1 20 21 package org.snmp4j.agent.mo.snmp.smi; 22 23 import org.snmp4j.smi.*; 24 import java.util.Arrays ; 25 import org.snmp4j.PDU; 26 27 34 public class EnumerationConstraint implements ValueConstraint { 35 36 private int[] allowedValues; 37 38 44 public EnumerationConstraint(int[] allowedValues) { 45 this.allowedValues = new int[allowedValues.length]; 46 System.arraycopy(allowedValues, 0, 47 this.allowedValues, 0, allowedValues.length); 48 Arrays.sort(this.allowedValues); 49 } 50 51 public int validate(Variable variable) { 52 if (variable instanceof Integer32) { 53 if (Arrays.binarySearch(allowedValues, 54 ((Integer32)variable).getValue()) < 0) { 55 return PDU.wrongValue; 56 } 57 return PDU.noError; 58 } 59 return PDU.wrongType; 60 } 61 } 62 | Popular Tags |