Package org.opennms.protocols.snmp
Class SnmpObjectId
- java.lang.Object
-
- org.opennms.protocols.snmp.SnmpObjectId
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,SnmpSyntax
public class SnmpObjectId extends java.lang.Object implements SnmpSyntax, java.lang.Cloneable, java.io.Serializable
Defines the SNMP object identifier class for naming variables. An object identifier is a sequence of numbers that correspond to branches in the Management Information Base (MIB). Each vendor is free to define their own branch of the tree. The SnmpObjectId class provides an interface for naming those tree instances.- Author:
- Brian Weaver , Nazario Irizarry, Jr.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static byte
ASNTYPE
Defines the SNMP SMI type for this particular object.
-
Constructor Summary
Constructors Constructor Description SnmpObjectId()
Creates a default empty object identifier.SnmpObjectId(int[] data)
Creates an object identifier from the passed array of identifiers.SnmpObjectId(java.lang.String strOid)
Creates an object identifier from the pased dotted decimal object identifier string.SnmpObjectId(SnmpObjectId second)
Creates a duplicate object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(int[] ids)
Appends the specified identifiers to the current object.void
append(java.lang.String strOids)
Converts the passed string to an object identifier and appends them to the current object.void
append(SnmpObjectId second)
Appends the passed SnmpObjectId object to self.java.lang.Object
clone()
Implements the cloneable interface.int
compare(int[] ids)
Lexigraphically compares the object identifer to the array of identifiers.int
compare(int[] ids, int dist)
Lexigraphically compares the object identifer to the array of identifiers.int
compare(SnmpObjectId cmp)
Lexigraphically compares the object identifer to the passed object identifer.int
decodeASN(byte[] buf, int offset, AsnEncoder encoder)
Decodes the ASN.1 object identifer from the passed buffer.SnmpSyntax
duplicate()
Serves the same purpose as the method clone().int
encodeASN(byte[] buf, int offset, AsnEncoder encoder)
Encodes the ASN.1 object identifier using the passed encoder and stores the results in the passed buffer.boolean
equals(java.lang.Object o)
Test for equality.int[]
getIdentifiers()
Gets the array of object identifiers from the object.int
getLastIdentifier()
Returns the value of the last object identifier component valueint
getLength()
Gets the number of object identifiers in the object.int
hashCode()
Returns a computed hash code value for the object identifier.boolean
isRootOf(SnmpObjectId leaf)
Compares the passed object identifier against self to determine if self is the root of the passed object.void
prepend(int[] ids)
Prepends the passed set of identifiers to the front of the object.void
prepend(java.lang.String strOids)
Converts the passed string to an object identifier and prepends them to the current object.void
prepend(SnmpObjectId second)
Prepends the passed SnmpObjectId object to self.void
setIdentifiers(int[] data)
Sets the object to the passed object identifiervoid
setIdentifiers(java.lang.String strOid)
Sets the object to the passed dotted decimal object identifier string.java.lang.String
toString()
Converts the object identifier to a dotted decimal string representation.byte
typeId()
Used to get the ASN.1 type for this particular object.
-
-
-
Field Detail
-
ASNTYPE
public static final byte ASNTYPE
Defines the SNMP SMI type for this particular object.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SnmpObjectId
public SnmpObjectId()
Creates a default empty object identifier.
-
SnmpObjectId
public SnmpObjectId(int[] data)
Creates an object identifier from the passed array of identifiers. If the passed argument is null then a default object id (.0.0) is created for the instance.- Parameters:
data
- The array of object identifiers
-
SnmpObjectId
public SnmpObjectId(SnmpObjectId second)
Creates a duplicate object. The passed object identifier is copied into the newly created object.- Parameters:
second
- The object to copy
-
SnmpObjectId
public SnmpObjectId(java.lang.String strOid)
Creates an object identifier from the pased dotted decimal object identifier string. The string is converted to the internal representation. If the conversion fails then a default (.0.0) object identifier is assigned to the object.- Parameters:
strOid
- The dotted decimal object identifier string
-
-
Method Detail
-
getLength
public int getLength()
Gets the number of object identifiers in the object.- Returns:
- Returns the number of object identifiers
-
getLastIdentifier
public int getLastIdentifier()
Returns the value of the last object identifier component value
-
getIdentifiers
public int[] getIdentifiers()
Gets the array of object identifiers from the object. The instance is returned as a reference. The caller should not make any modifications to the returned list.- Returns:
- Returns the list of identifiers
-
setIdentifiers
public void setIdentifiers(int[] data)
Sets the object to the passed object identifier- Parameters:
data
- The new object identifier
-
setIdentifiers
public void setIdentifiers(java.lang.String strOid)
Sets the object to the passed dotted decimal object identifier string.- Parameters:
strOid
- The dotted decimal object identifier.
-
append
public void append(int[] ids)
Appends the specified identifiers to the current object.- Parameters:
ids
- The array of identifiers to append
-
append
public void append(java.lang.String strOids)
Converts the passed string to an object identifier and appends them to the current object.- Parameters:
strOids
- The dotted decimal identifiers to append
-
append
public void append(SnmpObjectId second)
Appends the passed SnmpObjectId object to self.- Parameters:
second
- The object to append to self
-
prepend
public void prepend(int[] ids)
Prepends the passed set of identifiers to the front of the object.- Parameters:
ids
- The list of identifiers
-
prepend
public void prepend(java.lang.String strOids)
Converts the passed string to an object identifier and prepends them to the current object.- Parameters:
strOids
- The dotted decimal identifiers to prepend
-
prepend
public void prepend(SnmpObjectId second)
Prepends the passed SnmpObjectId object to self.- Parameters:
second
- The object to prepend to self
-
compare
public int compare(int[] ids)
Lexigraphically compares the object identifer to the array of identifiers. If the object is lexigraphically less than ids a negative number is returned. A positive number is returned if self is greater than the passed identifers and a zero is returned if they are equal. The length of the identifiers do not have to be equal.- Parameters:
ids
- The array if identifier to compare- Returns:
- Returns zero if the ids are equal. Less than zero if the object is less than 'ids' and greater than zero if the object is greater than 'ids'.
-
compare
public int compare(int[] ids, int dist)
Lexigraphically compares the object identifer to the array of identifiers. If the object is lexigraphically less than ids a negative number is returned. A positive number is returned if self is greater than the passed identifers and a zero is returned if they are equal. The length of the identifiers do not have to be equal.- Parameters:
ids
- The array if identifier to compare.dist
- The maximum number of ids to compare.- Returns:
- Returns zero if the ids are equal. Less than zero if the object is less than 'ids' and greater than zero if the object is greater than 'ids'.
-
compare
public int compare(SnmpObjectId cmp)
Lexigraphically compares the object identifer to the passed object identifer. If the object is lexigraphically less than 'cmp' a negative number is returned. A positive number is returned if self is greater than the passed identifer and a zero is returned if they are equal. The length of the identifiers do not have to be equal.- Parameters:
cmp
- The object identifier to compare- Returns:
- Returns zero if the ids are equal. Less than zero if the object is less than 'cmp' and greater than zero if the object is greater than 'cmp'.
-
isRootOf
public boolean isRootOf(SnmpObjectId leaf)
Compares the passed object identifier against self to determine if self is the root of the passed object. If the passed object is in the same root tree as self then a true value is returned. Otherwise a false value is returned from the object.
- Parameters:
leaf
- The object to be tested- Returns:
- True if leaf is in the tree.
-
equals
public boolean equals(java.lang.Object o)
Test for equality. Returns true if 'o' is an instance of an SnmpObjectId and is equal to self.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- The object to be tested for equality.- Returns:
- True if the object is an SnmpObjectId and is equal to self. False otherwise.
-
toString
public java.lang.String toString()
Converts the object identifier to a dotted decimal string representation.- Overrides:
toString
in classjava.lang.Object
- Returns:
- Returns the dotted decimal object id string.
-
hashCode
public int hashCode()
Returns a computed hash code value for the object identifier. If the value of the object identifier is changed through any method the hash value for the identifer will change. Care must be exercised by developers to ensure that ObjectIds do not change when inserted into managers that track object by their hash value.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hash code for the object.
- Since:
- 1.8
-
typeId
public byte typeId()
Used to get the ASN.1 type for this particular object.- Specified by:
typeId
in interfaceSnmpSyntax
-
encodeASN
public int encodeASN(byte[] buf, int offset, AsnEncoder encoder) throws AsnEncodingException
Encodes the ASN.1 object identifier using the passed encoder and stores the results in the passed buffer. An exception is thrown if an error occurs with the encoding of the information.- Specified by:
encodeASN
in interfaceSnmpSyntax
- Parameters:
buf
- The buffer to write the encoded information.offset
- The offset to start writing informationencoder
- The encoder object.- Returns:
- The offset of the byte immediantly after the last encoded byte.
- Throws:
AsnEncodingException
- Thrown if the encoder finds an error in the buffer.
-
decodeASN
public int decodeASN(byte[] buf, int offset, AsnEncoder encoder) throws AsnDecodingException
Decodes the ASN.1 object identifer from the passed buffer. If an error occurs during the decoding sequence then an AsnDecodingException is thrown by the method. The value is decoded using the AsnEncoder passed to the object.- Specified by:
decodeASN
in interfaceSnmpSyntax
- Parameters:
buf
- The encode bufferoffset
- The offset byte to begin decodingencoder
- The decoder object.- Returns:
- The index of the byte immediantly after the last decoded byte of information.
- Throws:
AsnDecodingException
- Thrown by the encoder if an error occurs trying to decode the data buffer.
-
duplicate
public SnmpSyntax duplicate()
Serves the same purpose as the method clone().- Specified by:
duplicate
in interfaceSnmpSyntax
- Returns:
- A new copy of self.
-
clone
public java.lang.Object clone()
Implements the cloneable interface.- Overrides:
clone
in classjava.lang.Object
- Returns:
- Returns a new SnmpObjectId copy of self.
-
-