⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unsignedinteger32.java

📁 snmp4j
💻 JAVA
字号:
/*_############################################################################  _##  _##  SNMP4J - UnsignedInteger32.java  _##  _##  Copyright 2003-2005  Frank Fock and Jochen Katz (SNMP4J.org)  _##  _##  Licensed under the Apache License, Version 2.0 (the "License");  _##  you may not use this file except in compliance with the License.  _##  You may obtain a copy of the License at  _##  _##      http://www.apache.org/licenses/LICENSE-2.0  _##  _##  Unless required by applicable law or agreed to in writing, software  _##  distributed under the License is distributed on an "AS IS" BASIS,  _##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  _##  See the License for the specific language governing permissions and  _##  limitations under the License.  _##  _##########################################################################*/package org.snmp4j.smi;import java.io.*;import org.snmp4j.asn1.BER;import org.snmp4j.asn1.BERInputStream;/** * UnsignedInteger32 type is an SNMP type that represents unsigned 32bit * integer values (0 to 4294967295). * @author Frank Fock * @version 1.0 */public class UnsignedInteger32 extends Variable {  static final long serialVersionUID = -2155365655395258383L;  protected long value = 0;  public UnsignedInteger32() {  }  /**   * Creates an <code>UnsignedInteger32</code> from a <code>long</code> value.   * @param value   *    a <code>long</code> value which must not be greater 2^32-1 and not less   *    zero.   * @throws IllegalArgumentException   *    if <code>value</code> &lt; 0 or &gt; 2^32-1.   */  public UnsignedInteger32(long value) {    setValue(value);  }  public void encodeBER(OutputStream outputStream) throws java.io.IOException {    BER.encodeUnsignedInteger(outputStream, BER.GAUGE, value);  }  public void decodeBER(BERInputStream inputStream) throws java.io.IOException {    BER.MutableByte type = new BER.MutableByte();    long newValue = BER.decodeUnsignedInteger(inputStream, type);    if (type.getValue() != BER.GAUGE) {      throw new IOException("Wrong type encountered when decoding Gauge: "+type.getValue());    }    setValue(newValue);  }  public int getSyntax() {    return SMIConstants.SYNTAX_UNSIGNED_INTEGER32;  }  public int hashCode() {    return (int)value;  }  public int getBERLength() {    if (value < 0x80L) {      return 3;    }    else if (value < 0x8000L) {      return 4;    }    else if (value < 0x800000L) {      return 5;    }    else if (value < 0x80000000L) {      return 6;    }    return 7;  }  public boolean equals(Object o) {    if (o instanceof UnsignedInteger32) {      return (((UnsignedInteger32)o).value == value);    }    return false;  }  public int compareTo(Object o) {    long diff = (value - ((UnsignedInteger32)o).getValue());    if (diff < 0) {      return -1;    }    else if (diff > 0) {      return 1;    }    return 0;  }  public String toString() {    return Long.toString(value);  }  public void setValue(long value) {    if ((value < 0) || (value > 4294967295l)) {      throw new IllegalArgumentException(          "Argument must be an unsigned 32bit value");    }    this.value = value;  }  public long getValue() {    return value;  }  public Object clone() {    return new UnsignedInteger32(value);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -