HOME

com.ireasoning.protocol.snmp
Class SnmpOID

java.lang.Object
  extended bycom.ireasoning.protocol.snmp.SnmpOID
All Implemented Interfaces:
Comparable, Msg, Serializable, SnmpDataType

public class SnmpOID
extends Object
implements SnmpDataType, Comparable

This class represents Snmp OBJECT IDENTIFIER object. The OBJECT IDENTIFIER type represents administratively assigned names. Any instance of this type may have at most 128 sub-identifiers. Further, each sub-identifier must not exceed the value 2^32-1 (4294967295 decimal).

See Also:
Serialized Form

Field Summary
protected  int[] _value
          Member variables storing OID, ".1.3.2.456" will be stored as { 1, 3, 2, 456 }
static int MAX_LENGTH
          Max number of sub-identifier a OID can have (128)
 
Fields inherited from interface com.ireasoning.protocol.snmp.SnmpDataType
BITS, BITSTRING, COUNTER32, COUNTER64, END_OF_MIB_VIEW, END_OF_MIB_VIEW_OBJECT, GAUGE32, INTEGER, IPADDRESS, NO_SUCH_INSTANCE, NO_SUCH_INSTANCE_OBJECT, NO_SUCH_OBJECT, NO_SUCH_OBJECT_OBJECT, NULL, OCTETSTRING, OID, OPAQUE, PDU, SEQUENCE, SEQUENCEOF, serialVersionUID, TIMETICKS, UNSIGNED32, VARBIND
 
Fields inherited from interface com.ireasoning.protocol.Msg
ERROR_TYPE
 
Constructor Summary
SnmpOID()
          Constructs an empty SnmpOID objecct, whose toString() method should return "" just after construction.
SnmpOID(int[] data)
          Constructs a new SnmpOID by decoding the specified subarray of integers.
SnmpOID(int[] data, int length)
          Constructs a new SnmpOID by decoding the specified subarray of integers.
SnmpOID(int[] oid1, int[] oid2)
          Constructs a new SnmpOID which is oid1 with oid2 appended, that is, new oid = new SnmpOID(oid1).append(oid2)
SnmpOID(int[] data, int offset, int length)
          Constructs a new SnmpOID by decoding the specified subarray of integers.
SnmpOID(long[] data)
          Constructs a new SnmpOID by decoding the specified subarray of integers.
SnmpOID(long[] data, int length)
          Constructs a new SnmpOID by decoding the specified subarray of integers.
SnmpOID(long[] data, int offset, int length)
          Constructs a new SnmpOID by decoding the specified subarray of integers.
SnmpOID(SnmpOID oid)
          Makes a copy of passed in oid object
SnmpOID(SnmpOID oid1, SnmpOID oid2)
          Constructs a new SnmpOID which is oid1 with oid2 appended, that is, new oid = new SnmpOID(oid1).append(oid2)
SnmpOID(String strOID)
          Constructs an SnmpOID object from the passed in strOID
 
Method Summary
 SnmpOID append(int[] oid)
          Appends the passed oid to itself
 SnmpOID append(long[] oid)
          Appends the passed oid to itself
 SnmpOID append(SnmpOID oid)
          Appends the passed oid to itself
 SnmpOID append(String oid)
          Appends the passed oid to itself
 int compareTo(Object o)
          Compares this object to passed object, which should be an instance of SnmpOID or an integer array representing an OID.
 int compareTo(SnmpOID oid)
          Compares this object to passed object
 int compareTo(SnmpOID oid, int length)
          Compares this object to passed object, only compare first integers
 SnmpDataType copy()
          Makes a copy of itself
 int encode(com.ireasoning.protocol.snmp.SnmpEncoder encoder)
          For internal use
 boolean endsWith(int[] oid)
          Checks if this SnmpOID object's oid ends with passed oid.
 boolean endsWith(SnmpOID oid)
          Checks if this SnmpOID object's oid ends with passed oid.
 boolean endsWith(String oid)
          Checks if this SnmpOID object's oid ends with passed oid.
 boolean equals(Object obj)
          Check if this object equals to passed object
 int get(int index)
          Returns the integer at specified index of this OID
static String getCommonSuffix(SnmpOID oid1, SnmpOID oid2)
          Returns the common suffix of passed two OID.
 int getLength()
          Gets the total number of fields.
 int getType()
          Returns SnmpDataType.OID
 String getTypeString()
          Returns "OID"
 int[] getValue()
          Returns an array of integers which is equivalent to this one
 int hashCode()
          Returns a hash code value for the object
 int indexOf(SnmpOID oid)
          Returns the index within this OID of the first occurrence of the specified OID
 void setValue(int[] value)
          Sets new OID value.
 void setValue(long[] value)
          Sets new OID value.
 void setValue(SnmpOID value)
          Sets new OID value.
 void setValue(String value)
          Sets new OID value.
 boolean startsWith(SnmpOID prefix)
          Tests if this oid starts with the specified prefix.
 boolean startsWith(String prefix)
          Tests if this oid starts with the specified prefix.
 SnmpOID suboid(int beginIndex)
          Returns a new SnmpOID instance that is a subset of this one.
 SnmpOID suboid(int beginIndex, int endIndex)
          Returns a new SnmpOID instance that is a subset of this one
Example:
OID ".1.3.6.1.2.1" suboid(1, 3) returns OID ".3.6"
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_value

protected int[] _value
Member variables storing OID, ".1.3.2.456" will be stored as { 1, 3, 2, 456 }


MAX_LENGTH

public static final int MAX_LENGTH
Max number of sub-identifier a OID can have (128)

See Also:
Constant Field Values
Constructor Detail

SnmpOID

public SnmpOID()
Constructs an empty SnmpOID objecct, whose toString() method should return "" just after construction.


SnmpOID

public SnmpOID(String strOID)
Constructs an SnmpOID object from the passed in strOID


SnmpOID

public SnmpOID(int[] data,
               int length)
Constructs a new SnmpOID by decoding the specified subarray of integers.

Parameters:
length - - the number of integers to decode
Throws:
IndexOutOfBoundsException - if length is larger than the length of passed data object

SnmpOID

public SnmpOID(int[] data,
               int offset,
               int length)
Constructs a new SnmpOID by decoding the specified subarray of integers.

Parameters:
offset - - the index of the first int to decode
length - - the number of integers to decode
Throws:
IndexOutOfBoundsException - if the offset is negative, or length plus offset is larger than the length of passed data object

SnmpOID

public SnmpOID(int[] data)
Constructs a new SnmpOID by decoding the specified subarray of integers.


SnmpOID

public SnmpOID(long[] data,
               int length)
Constructs a new SnmpOID by decoding the specified subarray of integers.

Parameters:
length - - the number of integers to decode
data - a list of unsigned 32 bit integers
Throws:
IndexOutOfBoundsException - if length is larger than the length of passed data object

SnmpOID

public SnmpOID(long[] data,
               int offset,
               int length)
Constructs a new SnmpOID by decoding the specified subarray of integers.

Parameters:
offset - - the index of the first integers to decode
length - - the number of integers to decode
data - a list of unsigned 32 bit integers
Throws:
IndexOutOfBoundsException - if the offset is negative, or length plus offset is larger than the length of passed data object

SnmpOID

public SnmpOID(SnmpOID oid1,
               SnmpOID oid2)
Constructs a new SnmpOID which is oid1 with oid2 appended, that is, new oid = new SnmpOID(oid1).append(oid2)


SnmpOID

public SnmpOID(int[] oid1,
               int[] oid2)
Constructs a new SnmpOID which is oid1 with oid2 appended, that is, new oid = new SnmpOID(oid1).append(oid2)


SnmpOID

public SnmpOID(long[] data)
Constructs a new SnmpOID by decoding the specified subarray of integers.

Parameters:
data - a list of unsigned 32 bit integers

SnmpOID

public SnmpOID(SnmpOID oid)
Makes a copy of passed in oid object

Method Detail

indexOf

public int indexOf(SnmpOID oid)
Returns the index within this OID of the first occurrence of the specified OID


suboid

public SnmpOID suboid(int beginIndex)
Returns a new SnmpOID instance that is a subset of this one.
Example:
OID ".1.3.6.1.2.1" suboid(1) returns OID ".3.6.1.2.1"

Parameters:
beginIndex - the beginning index, inclusive.
Throws:
IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this object.

suboid

public SnmpOID suboid(int beginIndex,
                      int endIndex)
Returns a new SnmpOID instance that is a subset of this one
Example:
OID ".1.3.6.1.2.1" suboid(1, 3) returns OID ".3.6"

Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Throws:
IndexOutOfBoundsException - if beginIndex/endIndex is negative or larger than the length of this object, or beginIndex is larger than endIndex.

getLength

public int getLength()
Gets the total number of fields. For instance, ".1.345.2" is represented as {1, 345, 2}, which has 3 elements, the getLength() will return 3.


getValue

public int[] getValue()
Returns an array of integers which is equivalent to this one

Returns:
the OID value as an integer array.

get

public int get(int index)
Returns the integer at specified index of this OID

Parameters:
index - the specified index of the digit to be retrieved
Returns:
the integer at specified index of this OID
Throws:
IndexOutOfBoundsException - if index is out of range

setValue

public void setValue(int[] value)
Sets new OID value.


setValue

public void setValue(long[] value)
Sets new OID value.


setValue

public void setValue(String value)
Sets new OID value.


setValue

public void setValue(SnmpOID value)
Sets new OID value.


endsWith

public boolean endsWith(String oid)
Checks if this SnmpOID object's oid ends with passed oid. e.g. For OID ".1.3.2.456", it returns true is passed "456", ".456" or "2.456", but false if passed "6" or "1.456"


endsWith

public boolean endsWith(SnmpOID oid)
Checks if this SnmpOID object's oid ends with passed oid. e.g. For OID ".1.3.2.456", it returns true is passed "456", ".456" or "2.456", but false if passed "6" or "1.456"


endsWith

public boolean endsWith(int[] oid)
Checks if this SnmpOID object's oid ends with passed oid. e.g. For OID ".1.3.2.456", it returns true is passed "456", ".456" or "2.456", but false if passed "6" or "1.456"

Parameters:
oid - an integer array

append

public SnmpOID append(int[] oid)
Appends the passed oid to itself

Parameters:
oid - the oid to be appeneded, it doesn't matter if it starts with "." or not. If oids is null or empty, nothing get changed for this object.
Returns:
itself

append

public SnmpOID append(long[] oid)
Appends the passed oid to itself

Parameters:
oid - the oid to be appeneded, it doesn't matter if it starts with "." or not. If oids is null or empty, nothing get changed for this object.
Returns:
new OID with appeneded value

append

public SnmpOID append(String oid)
Appends the passed oid to itself

Parameters:
oid - the oid string to be appeneded, it doesn't matter if it starts with "." or not. If oid is null or empty, nothing get changed for this object.
Returns:
new OID with appeneded value

append

public SnmpOID append(SnmpOID oid)
Appends the passed oid to itself

Parameters:
oid - the oid to be appeneded
Returns:
new OID with appeneded value

compareTo

public int compareTo(Object o)
Compares this object to passed object, which should be an instance of SnmpOID or an integer array representing an OID.

Specified by:
compareTo in interface Comparable
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

compareTo

public int compareTo(SnmpOID oid)
Compares this object to passed object

Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

compareTo

public int compareTo(SnmpOID oid,
                     int length)
Compares this object to passed object, only compare first integers

Parameters:
length - number of integers to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

startsWith

public boolean startsWith(String prefix)
Tests if this oid starts with the specified prefix.

Parameters:
prefix - - the prefix.

startsWith

public boolean startsWith(SnmpOID prefix)
Tests if this oid starts with the specified prefix.

Parameters:
prefix - - the prefix.

equals

public boolean equals(Object obj)
Check if this object equals to passed object

Specified by:
equals in interface SnmpDataType
Parameters:
obj - the obejct to be compared.

toString

public String toString()
Returns:
a string format of this object

hashCode

public int hashCode()
Description copied from interface: SnmpDataType
Returns a hash code value for the object

Specified by:
hashCode in interface SnmpDataType

getType

public int getType()
Returns SnmpDataType.OID

Specified by:
getType in interface SnmpDataType
Returns:
the object data type

getTypeString

public String getTypeString()
Returns "OID"

Specified by:
getTypeString in interface SnmpDataType

copy

public SnmpDataType copy()
Description copied from interface: SnmpDataType
Makes a copy of itself

Specified by:
copy in interface SnmpDataType
Returns:
a deep copy of this object

encode

public int encode(com.ireasoning.protocol.snmp.SnmpEncoder encoder)
           throws SnmpEncodingException
Description copied from interface: SnmpDataType
For internal use

Specified by:
encode in interface SnmpDataType
Throws:
SnmpEncodingException

getCommonSuffix

public static String getCommonSuffix(SnmpOID oid1,
                                     SnmpOID oid2)
Returns the common suffix of passed two OID. For example, if oid1 is ".1.3.6.1.1.2", oid2 is ".1.3.6.3.1.2", it returns ".1.2". If there's no common suffix, it return an empty String


HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.