1 29 30 31 package snmp; 32 33 34 35 import java.math.*; 36 37 38 45 46 47 public class SNMPCounter32 extends SNMPInteger 48 { 49 private static BigInteger maxValue = new BigInteger("4294967295"); 51 52 53 54 56 57 public SNMPCounter32() 58 { 59 this(0); } 61 62 63 public SNMPCounter32(long newValue) 64 { 65 tag = SNMPBERCodec.SNMPCOUNTER32; 66 67 value = new BigInteger(new Long (newValue).toString()); 68 69 value = value.mod(maxValue); 71 } 72 73 74 75 80 81 protected SNMPCounter32(byte[] enc) 82 throws SNMPBadValueException 83 { 84 tag = SNMPBERCodec.SNMPCOUNTER32; 85 86 extractValueFromBEREncoding(enc); 87 88 value = value.mod(maxValue); 90 } 91 92 93 94 95 96 101 102 public void setValue(Object newValue) 103 throws SNMPBadValueException 104 { 105 if (newValue instanceof BigInteger) 106 { 107 value = (BigInteger)newValue; 108 value = value.mod(maxValue); } 110 else if (newValue instanceof Integer ) 111 { 112 value = new BigInteger(newValue.toString()); 113 value = value.mod(maxValue); } 115 else if (newValue instanceof String ) 116 { 117 value = value = new BigInteger((String )newValue); 118 value = value.mod(maxValue); } 120 else 121 throw new SNMPBadValueException(" Counter32: bad object supplied to set value "); 122 } 123 124 125 126 127 } | Popular Tags |