Package uk.co.westhawk.snmp.stack
Class AsnObjectId
java.lang.Object
uk.co.westhawk.snmp.stack.AsnObject
uk.co.westhawk.snmp.stack.AsnObjectId
- All Implemented Interfaces:
Comparable
,SnmpConstants
This class represents the ASN.1 ObjectID class. An Object ID (OID)
identifies a variable in a MIB.
- Version:
- $Revision: 3.25 $ $Date: 2008/08/19 13:34:13 $
- Author:
- Tim Panton
-
Field Summary
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpConstants
ASN_APPLICATION, ASN_BIT_STR, ASN_BIT8, ASN_BOOLEAN, ASN_CONSTRUCTOR, ASN_CONTEXT, ASN_EXTENSION_ID, ASN_INTEGER, ASN_LONG_LEN, ASN_NULL, ASN_OBJECT_ID, ASN_OCTET_STR, ASN_PRIMITIVE, ASN_PRIVATE, ASN_SEQUENCE, ASN_SET, ASN_UNIVERSAL, CONS_SEQ, COUNTER, COUNTER64, GAUGE, GET_REQ_MSG, GET_RPRT_MSG, GET_RSP_MSG, GETBULK_REQ_MSG, GETNEXT_REQ_MSG, INFORM_REQ_MSG, INTEGER, IPADDRESS, NSAP_ADDRESS, NULLOBJ, OBJID, OBSOLETED_RFC1442_UINTEGER32, OPAQUE, SET_REQ_MSG, SMI_V2_UINTEGER32, SNMP_ERR_AUTHORIZATIONERR, SNMP_ERR_BADVALUE, SNMP_ERR_COMMITFAILED, SNMP_ERR_DECODING_EXC, SNMP_ERR_DECODINGASN_EXC, SNMP_ERR_DECODINGPKTLNGTH_EXC, SNMP_ERR_GENERR, SNMP_ERR_INCONSISTENTNAME, SNMP_ERR_INCONSISTENTVALUE, SNMP_ERR_NOACCESS, SNMP_ERR_NOCREATION, SNMP_ERR_NOERROR, SNMP_ERR_NOSUCHNAME, SNMP_ERR_NOTWRITABLE, SNMP_ERR_READONLY, SNMP_ERR_RESOURCEUNAVAILABLE, SNMP_ERR_TOOBIG, SNMP_ERR_UNDOFAILED, SNMP_ERR_WRONGENCODING, SNMP_ERR_WRONGLENGTH, SNMP_ERR_WRONGTYPE, SNMP_ERR_WRONGVALUE, SNMP_TRAP_AUTHFAIL, SNMP_TRAP_COLDSTART, SNMP_TRAP_EGPNEIGHBORLOSS, SNMP_TRAP_ENTERPRISESPECIFIC, SNMP_TRAP_LINKDOWN, SNMP_TRAP_LINKUP, SNMP_TRAP_WARMSTART, SNMP_VAR_ENDOFMIBVIEW, SNMP_VAR_NOSUCHINSTANCE, SNMP_VAR_NOSUCHOBJECT, SNMP_VERSION_1, SNMP_VERSION_2c, SNMP_VERSION_3, STRING, TIMETICKS, TRP_REQ_MSG, TRPV2_REQ_MSG
-
Constructor Summary
ConstructorsConstructorDescriptionAsnObjectId
(long[] oida) Constructs an AsnObjectId out of an array of long.Constructs an AsnObjectId out of an OID string. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(long sub_oid) Adds a single sub-identifier to the end of the OID.void
add
(long[] sub_oid) Adds a number of sub-identifiers to the end of the OID.void
Adds sub-identifiers to the end of the OID.int
int
boolean
Compares this OID to the specified object.long
getElementAt
(int index) Returns the element in the AsnObjectId at the specified index.long[]
getOid()
Returns the value of the AsnObjectId as an array of long.int
getSize()
Returns the number of elements in the AsnObjectId.long[]
getSubOid
(int beginIndex, int endIndex) Returns a subset of the value of the AsnObjectId as an array of long.getValue()
Returns the value of the AsnObjectId.int
hashCode()
Returns a hash code for this OID.long
Returns the last element in the AsnObjectId.int
leftMostCompare
(int n, AsnObjectId b) Compares the n leftmost sub-identifiers with the given AsnObject in left-to-right direction.long
Removes the last sub-identifier (if available) from this OID and returns it.boolean
startsWith
(AsnObjectId prefix) Checks if this OID starts with the specified prefix.toString()
Returns the string representation of the AsnObjectId.toString
(long[] v) Returns the string representation of the AsnObjectId.Methods inherited from class uk.co.westhawk.snmp.stack.AsnObject
getRespType, getRespTypeString, setDebug
-
Constructor Details
-
AsnObjectId
Constructs an AsnObjectId out of an OID string.- Parameters:
s
- The OID, format a[.b]*- Throws:
IllegalArgumentException
-
AsnObjectId
public AsnObjectId(long[] oida) Constructs an AsnObjectId out of an array of long.- Parameters:
oida
- The OID, as an array of long- Since:
- 4_14
-
-
Method Details
-
startsWith
Checks if this OID starts with the specified prefix.- Returns:
- true if starts with the prefix, false otherwise
-
add
public void add(long sub_oid) Adds a single sub-identifier to the end of the OID.- Parameters:
sub_oid
- The sub-identifier
-
add
public void add(long[] sub_oid) Adds a number of sub-identifiers to the end of the OID.- Parameters:
sub_oid
- The sub-identifiers- See Also:
-
add
Adds sub-identifiers to the end of the OID.- Parameters:
s
- The sub-identifiers, format a[.b]*- Throws:
IllegalArgumentException
-
removeLast
public long removeLast()Removes the last sub-identifier (if available) from this OID and returns it.- Returns:
- The sub-identifier or -1 if there is no sub-identifier
- Since:
- 6.1
-
getValue
Returns the value of the AsnObjectId.- Returns:
- The value (the OID)
-
toString
Returns the string representation of the AsnObjectId. -
toString
Returns the string representation of the AsnObjectId.- Returns:
- The string of the AsnObjectId
-
getSize
public int getSize()Returns the number of elements in the AsnObjectId. We cannot use size(), since that is already in use.- Returns:
- the number of elements
-
getElementAt
Returns the element in the AsnObjectId at the specified index.- Parameters:
index
- The index- Returns:
- the element at the specified index
- Throws:
ArrayIndexOutOfBoundsException
- if an invalid index was given
-
lastElement
Returns the last element in the AsnObjectId.- Returns:
- the last element
- Throws:
ArrayIndexOutOfBoundsException
- if the AsnObjectId is empty.- Since:
- 6.1
-
getOid
public long[] getOid()Returns the value of the AsnObjectId as an array of long. The value returned is a copy.- Returns:
- The OID value
- Since:
- 4_14
-
getSubOid
Returns a subset of the value of the AsnObjectId as an array of long. The value returned is a copy.- Returns:
- The sub OID value
- Throws:
ArrayIndexOutOfBoundsException
- Since:
- 4_14
-
equals
Compares this OID to the specified object. The result istrue
if and only if the argument is notnull
and is aAsnObjectId
object that represents the same sequence of numbers as this object.Thanks to Eli Bishop (eli@graphesthesia.com) for the suggestion of adding it.
-
hashCode
public int hashCode()Returns a hash code for this OID. The hash value of the empty OID is zero. -
compareTo
- Specified by:
compareTo
in interfaceComparable
- Since:
- 6.1
- See Also:
-
compareTo
- Since:
- 6.1
- See Also:
-
leftMostCompare
Compares the n leftmost sub-identifiers with the given AsnObject in left-to-right direction.- Parameters:
n
- The number of sub-identifiers to compare.b
- An AsnObject to compare with this object- Returns:
- 0, when the first 'n' sub-identifiers are the same.
- -1 when the first 'n' sub-identifiers of this object are lexicographic less than those of b. This includes the case where this object is shorter than 'n' AND shorter than b.
- 1 when the first 'n' sub-identifiers of this object are lexicographic greater than those of b.
- Since:
- 6.1
-