1 20 21 22 23 24 25 package org.snmp4j.smi; 26 27 import java.io.*; 28 import org.snmp4j.asn1.BER; 29 import org.snmp4j.asn1.BERInputStream; 30 31 40 public class Counter32 extends UnsignedInteger32 { 41 42 private static final long serialVersionUID = 6140742767439142144L; 43 44 public Counter32() { 45 } 46 47 public Counter32(long value) { 48 super(value); 49 } 50 51 public boolean equals(Object o) { 52 if (o instanceof Counter32) { 53 return (((Counter32)o).getValue() == getValue()); 54 } 55 return false; 56 } 57 58 public int getSyntax() { 59 return SMIConstants.SYNTAX_COUNTER32; 60 } 61 62 public void encodeBER(OutputStream outputStream) throws IOException { 63 BER.encodeUnsignedInteger(outputStream, BER.COUNTER32, getValue()); 64 } 65 66 public void decodeBER(BERInputStream inputStream) throws IOException { 67 BER.MutableByte type = new BER.MutableByte(); 68 long newValue = BER.decodeUnsignedInteger(inputStream, type); 69 if (type.getValue() != BER.COUNTER32) { 70 throw new IOException("Wrong type encountered when decoding Counter: "+ 71 type.getValue()); 72 } 73 setValue(newValue); 74 } 75 76 public Object clone() { 77 return new Counter32(value); 78 } 79 80 84 public void increment() { 85 if (value < 4294967295l) { 86 value++; 87 } 88 else { 89 value = 0; 90 } 91 } 92 93 public OID toSubIndex(boolean impliedLength) { 94 throw new UnsupportedOperationException (); 95 } 96 97 public void fromSubIndex(OID subIndex, boolean impliedLength) { 98 throw new UnsupportedOperationException (); 99 } 100 101 } 102 103 | Popular Tags |