Package org.snmp4j.smi
Class OID
java.lang.Object
org.snmp4j.smi.AbstractVariable
org.snmp4j.smi.OID
- All Implemented Interfaces:
 Serializable,Cloneable,Comparable<Variable>,BERSerializable,AssignableFromIntArray,AssignableFromString,Variable
The Object Identifier Class.
 The Object Identifier (OID) class is the encapsulation of an
 SMI object identifier. The SMI object is a data identifier for a
 data element found in a Management Information Base (MIB), as
 defined by a MIB definition. The 
OID class allows definition and
 manipulation of object identifiers.- Version:
 - 2.3.1
 - Author:
 - Frank Fock
 - See Also:
 
- 
Field Summary
FieldsFields inherited from class org.snmp4j.smi.AbstractVariable
SMISYNTAXES_PROPERTIES - 
Constructor Summary
ConstructorsConstructorDescriptionOID()Constructs a zero length OID.OID(int[] rawOID) Constructs anOIDfrom an array of integer values.OID(int[] prefixOID, int suffixID) Constructs anOIDfrom two arrays of integer values where the first represents the OID prefix (i.e., the object class ID) and the second one represents the OID suffix (i.e., the instance identifier).OID(int[] prefixOID, int[] suffixOID) Constructs anOIDfrom two arrays of integer values where the first represents the OID prefix (i.e., the object class ID) and the second one represents the OID suffix (i.e., the instance identifier).OID(int[] rawOID, int offset, int length) Constructs anOIDfrom an array of integer values.Constructs anOIDfrom a dotted string.Copy constructor. - 
Method Summary
Modifier and TypeMethodDescriptionfinal OIDappend(int subID) Appends a sub-identifier to this OID.final OIDAppends a dotted String OID to thisOID.final OIDAppends anOIDto this OID.final OIDappendUnsigned(long subID) Appends an unsigned long sub-identifier value to this OID.clone()Clones this variable.final intvoiddecodeBER(BERInputStream inputStream) Decodes aVariablefrom anBERInputStream.voidencodeBER(OutputStream outputStream) Encodes aVariableto anOutputStream.final booleanformat()Format the OID as text.final voidfromSubIndex(OID subIndex, boolean impliedLength) Sets the value of thisVariablefrom the supplied (sub-)index.final intget(int index) Gets the sub-identifier value at the specified position.intReturns the length of thisVariablein bytes when encoded according to the Basic Encoding Rules (BER).final intGets the ASN.1 syntax identifier value of this SNMP variable.final longgetUnsigned(int index) Gets the unsigned sub-identifier value at the specified position.final int[]getValue()Gets all sub-identifiers as an int array.inthashCode()booleanisValid()Checks whether thisOIDcan be BER encoded.final intlast()Returns the last sub-identifier as an integer value.final longReturns the last sub-identifier as an unsigned long value.intleftMostCompare(int n, OID other) Compares the n leftmost sub-identifiers with the givenOIDin left-to-right direction.mask(OctetString mask) Returns a copy of this OID where sub-identifiers have been set to zero for all n-th sub-identifier where the n-th bit of mask is zero.static OIDReturns the greater of the two OID values.static OIDReturns the lesser of the two OID values.final OIDnextPeer()Returns the next following OID with the same or lesser size (length).final OIDReturns the predecessor OID for this OID.intRemoves the last sub-identifier (if available) from thisOIDand returns it.intrightMostCompare(int n, OID other) Compares the n rightmost sub-identifiers in direction right-to-left with those of the givenOID.final voidset(int index, int value) Sets the sub-identifier at the specified position.final voidsetValue(int[] value) Sets the value from an array of integer values.voidfinal intsize()Returns the number of sub-identifiers in thisOID.booleanstartsWith(OID other) Check if the OID starts with the given OID.final OIDReturns the successor OID for this OID.byte[]Returns the content of the as a byte array.Returns the OID as dotted string (e.g., "1.3.6.1.4.1") regardless of whatOIDTextFormatinstance is set inSNMP4JSettings.inttoInt()Returns an integer representation of this variable if such a representation exists.int[]Returns the value of this object as an int array.longtoLong()Returns a long representation of this variable if such a representation exists.toString()Return a string representation that can be parsed again to thisOIDbyOID(String).final OIDtoSubIndex(boolean impliedLength) Converts the value of thisVariableto a (sub-)index value.trim()Returns a new copy of this OID with the last sub-indentifier removed.voidtrim(int n) Remove the n rightmost subidentifiers from this OID.Methods inherited from class org.snmp4j.smi.AbstractVariable
createFromBER, createFromSyntax, equal, getBERPayloadLength, getSyntaxFromString, getSyntaxString, getSyntaxString, isDynamic, isException 
- 
Field Details
- 
MAX_OID_LEN
public static final int MAX_OID_LEN- See Also:
 
 - 
MAX_SUBID_VALUE
public static final int MAX_SUBID_VALUE- See Also:
 
 
 - 
 - 
Constructor Details
- 
OID
public OID()Constructs a zero length OID. - 
OID
Constructs anOIDfrom a dotted string. The string can contain embedded strings enclosed by a single quote (') that are converted to the corresponding OIO value. For example the following OID pairs are equal:OID a = new OID("1.3.6.2.1.5.'hallo'.1"); OID b = new OID("1.3.6.2.1.5.104.97.108.108.111.1"); assertEquals(a, b); a = new OID("1.3.6.2.1.5.'hal.lo'.1"); b = new OID("1.3.6.2.1.5.104.97.108.46.108.111.1"); assertEquals(a, b); a = new OID("1.3.6.2.1.5.'hal.'.'''.'lo'.1"); b = new OID("1.3.6.2.1.5.104.97.108.46.39.108.111.1");- Parameters:
 oid- a dotted OID String, for example "1.3.6.1.2.2.1.0"
 - 
OID
public OID(int[] rawOID) Constructs anOIDfrom an array of integer values.- Parameters:
 rawOID- an array ofintvalues. The array is copied. Later changes torawOIDwill therefore not affect the OID's value.
 - 
OID
public OID(int[] prefixOID, int[] suffixOID) Constructs anOIDfrom two arrays of integer values where the first represents the OID prefix (i.e., the object class ID) and the second one represents the OID suffix (i.e., the instance identifier).- Parameters:
 prefixOID- an array ofintvalues. The array is copied. Later changes toprefixOIDwill therefore not affect the OID's value.suffixOID- an array ofintvalues which will be appended to theprefixOIDOID. The array is copied. Later changes tosuffixOIDwill therefore not affect the OID's value.- Since:
 - 1.8
 
 - 
OID
public OID(int[] prefixOID, int suffixID) Constructs anOIDfrom two arrays of integer values where the first represents the OID prefix (i.e., the object class ID) and the second one represents the OID suffix (i.e., the instance identifier).- Parameters:
 prefixOID- an array ofintvalues. The array is copied. Later changes toprefixOIDwill therefore not affect the OID's value.suffixID- anintvalue that will be appended to theprefixOIDOID. The array is copied. Later changes toprefixOIDwill therefore not affect the OID's value.- Since:
 - 2.2.6
 
 - 
OID
public OID(int[] rawOID, int offset, int length) Constructs anOIDfrom an array of integer values.- Parameters:
 rawOID- an array ofintvalues. The array is copied. Later changes torawOIDwill therefore not affect the OID's value.offset- the zero based offset into therawOIDthat points to the first sub-identifier of the new OID.length- the length of the new OID, whereoffset + lengthmust be less or equal the length ofrawOID. Otherwise anIndexOutOfBoundsExceptionis thrown.
 - 
OID
Copy constructor.- Parameters:
 other- OID
 
 - 
 - 
Method Details
- 
getSyntax
public final int getSyntax()Description copied from class:AbstractVariableGets the ASN.1 syntax identifier value of this SNMP variable.- Specified by:
 getSyntaxin interfaceVariable- Specified by:
 getSyntaxin classAbstractVariable- Returns:
 - an integer value less than 128 for regular SMI objects and a value greater or equal than 128 for exception values like noSuchObject, noSuchInstance, and endOfMibView.
 
 - 
hashCode
public int hashCode()- Specified by:
 hashCodein interfaceVariable- Specified by:
 hashCodein classAbstractVariable
 - 
equals
- Specified by:
 equalsin interfaceVariable- Specified by:
 equalsin classAbstractVariable
 - 
mask
Returns a copy of this OID where sub-identifiers have been set to zero for all n-th sub-identifier where the n-th bit of mask is zero.- Parameters:
 mask- a mask where the n-th bit corresponds to the n-th sub-identifier.- Returns:
 - the masked OID.
 - Since:
 - 1.5
 
 - 
compareTo
- Specified by:
 compareToin interfaceComparable<Variable>- Specified by:
 compareToin interfaceVariable- Specified by:
 compareToin classAbstractVariable
 - 
toString
Return a string representation that can be parsed again to thisOIDbyOID(String).- Specified by:
 toStringin interfaceVariable- Specified by:
 toStringin classAbstractVariable- Returns:
 - a formatted string representation of this OID (e.g. "ifDescr.1") that
    can be parsed again as defined by 
OIDTextFormat.formatForRoundTrip(int[])inSNMP4JSettings. 
 - 
format
Format the OID as text. This could return to same result astoString()but also fully converted index-to-text values likesnmp4jLogLoggerIndex.org.snmp4j.MessageDispatcherImpl.- Returns:
 - a string representation of this OID as defined by the
    
OIDTextFormat.format(int[])inSNMP4JSettings. - Since:
 - 2.2
 
 - 
toDottedString
Returns the OID as dotted string (e.g., "1.3.6.1.4.1") regardless of whatOIDTextFormatinstance is set inSNMP4JSettings.- Returns:
 - a dotted string representation of this OID value.
 - Since:
 - 2.2
 
 - 
toByteArray
public byte[] toByteArray()Returns the content of the as a byte array. This method can be used to convert an index value to anOctetStringorIpAddressinstance.- Returns:
 - the sub-identifies of this 
OIDas a byte array. Each sub-identifier value is masked with 0xFF to form a byte value. - Since:
 - 1.2
 
 - 
encodeBER
Description copied from class:AbstractVariableEncodes aVariableto anOutputStream.- Specified by:
 encodeBERin interfaceBERSerializable- Specified by:
 encodeBERin classAbstractVariable- Parameters:
 outputStream- anOutputStream.- Throws:
 IOException- if an error occurs while writing to the stream.
 - 
getBERLength
public int getBERLength()Description copied from class:AbstractVariableReturns the length of thisVariablein bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
 getBERLengthin interfaceBERSerializable- Specified by:
 getBERLengthin classAbstractVariable- Returns:
 - the BER encoded length of this variable.
 
 - 
decodeBER
Description copied from class:AbstractVariableDecodes aVariablefrom anBERInputStream.- Specified by:
 decodeBERin interfaceBERSerializable- Specified by:
 decodeBERin classAbstractVariable- Parameters:
 inputStream- anBERInputStreamcontaining a BER encoded byte stream.- Throws:
 IOException- if the stream could not be decoded by using BER rules.
 - 
setValue
- Specified by:
 setValuein interfaceAssignableFromString
 - 
setValue
public final void setValue(int[] value) Sets the value from an array of integer values.- Specified by:
 setValuein interfaceAssignableFromIntArray- Parameters:
 value- The new value- Throws:
 IllegalArgumentException- if value == null.
 - 
getValue
public final int[] getValue()Gets all sub-identifiers as an int array.- Returns:
 - int arry of all sub-identifiers
 
 - 
get
public final int get(int index) Gets the sub-identifier value at the specified position.- Parameters:
 index- a zero-based index into theOID.- Returns:
 - the sub-indentifier value at 
index. NOTE: The returned value may be negative if the sub-identifier value is greater than2^31. - Throws:
 ArrayIndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
 - 
getUnsigned
public final long getUnsigned(int index) Gets the unsigned sub-identifier value at the specified position.- Parameters:
 index- int- Returns:
 - the sub-identifier value at 
indexas an unsigned long value. 
 - 
set
public final void set(int index, int value) Sets the sub-identifier at the specified position.- Parameters:
 index- a zero-based index into theOID.value- a 32bit unsigned integer value.- Throws:
 ArrayIndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
 - 
append
Appends a dotted String OID to thisOID.- Parameters:
 oid- a dotted String with numerical sub-identifiers.- Returns:
 - a pointer to this OID instance (useful for chaining).
 
 - 
append
Appends anOIDto this OID.- Parameters:
 oid- anOIDinstance.- Returns:
 - a pointer to this OID instance (useful for chaining).
 
 - 
append
Appends a sub-identifier to this OID.- Parameters:
 subID- an integer value.- Returns:
 - a pointer to this OID instance (useful for chaining).
 
 - 
appendUnsigned
Appends an unsigned long sub-identifier value to this OID.- Parameters:
 subID- an unsigned long value less or equal to 2^32-1.- Returns:
 - a pointer to this OID instance (useful for chaining).
 - Since:
 - 1.2
 
 - 
isValid
public boolean isValid()Checks whether thisOIDcan be BER encoded.- Returns:
 trueif size() >= 2 and size() <= 128 and if the first two sub-identifiers are less than 3 and 40 respectively.
 - 
size
public final int size()Returns the number of sub-identifiers in thisOID.- Returns:
 - an integer value between 0 and 128.
 
 - 
leftMostCompare
Compares the n leftmost sub-identifiers with the givenOIDin left-to-right direction.- Parameters:
 n- the number of sub-identifiers to compare.other- anOIDto compare with thisOID.- Returns:
 - 0 if the first 
nsub-identifiers are the same. - <0 if the first 
nsub-identifiers of thisOIDare lexicographic less than those of the comparand. - >0 if the first 
nsub-identifiers of thisOIDare lexicographic greater than those of the comparand. 
- 0 if the first 
 
 - 
rightMostCompare
Compares the n rightmost sub-identifiers in direction right-to-left with those of the givenOID.- Parameters:
 n- the number of sub-identifiers to compare.other- anOIDto compare with thisOID.- Returns:
 - 0 if the first 
nsub-identifiers are the same. - <0 if the first 
nsub-identifiers of thisOIDare lexicographic less than those of the comparand. - >0 if the first 
nsub-identifiers of thisOIDare lexicographic greater than those of the comparand. 
- 0 if the first 
 
 - 
startsWith
Check if the OID starts with the given OID.- Parameters:
 other- the OID to compare to- Returns:
 - false if the sub-identifiers do not match.
 
 - 
clone
Description copied from interface:VariableClones this variable. Cloning can be used by the SNMP4J API to better support concurrency by creating a clone for internal processing. The content of this object is independent to the content of the clone. Thus, changes to the clone will have no effect to this object.- Specified by:
 clonein interfaceVariable- Specified by:
 clonein classAbstractVariable- Returns:
 - a new instance of this 
Variablewith the same value. 
 - 
last
public final int last()Returns the last sub-identifier as an integer value. If this OID is empty (i.e. has no sub-identifiers) then aNoSuchElementExceptionis thrown- Returns:
 - the value of the last sub-identifier of this OID as an integer value. Sub-identifier values greater than 2^31-1 will be returned as negative values!
 - Since:
 - 1.2
 
 - 
lastUnsigned
public final long lastUnsigned()Returns the last sub-identifier as an unsigned long value. If this OID is empty (i.e. has no sub-identifiers) then aNoSuchElementExceptionis thrown- Returns:
 - the value of the last sub-identifier of this OID as an unsigned long.
 - Since:
 - 1.2
 
 - 
removeLast
public int removeLast()Removes the last sub-identifier (if available) from thisOIDand returns it.- Returns:
 - the last sub-identifier or -1 if there is no sub-identifier left in
    this 
OID. 
 - 
trim
public void trim(int n) Remove the n rightmost subidentifiers from this OID.- Parameters:
 n- the number of subidentifiers to remove. Ifnis zero or negative then this OID will not be changed. Ifnis greater thansize()all subidentifiers will be removed from this OID.
 - 
trim
Returns a new copy of this OID with the last sub-indentifier removed.- Returns:
 - a copy of this OID with 
n-1sub-identifiers wherenis the size of this OID and greater than zero, otherwise a zero length OID is returned. - Since:
 - 1.11
 
 - 
toInt
public int toInt()Description copied from class:AbstractVariableReturns an integer representation of this variable if such a representation exists.- Specified by:
 toIntin interfaceVariable- Specified by:
 toIntin classAbstractVariable- Returns:
 - an integer value (if the native representation of this variable would be a long, then the long value will be casted to int).
 
 - 
toLong
public long toLong()Description copied from class:AbstractVariableReturns a long representation of this variable if such a representation exists.- Specified by:
 toLongin interfaceVariable- Specified by:
 toLongin classAbstractVariable- Returns:
 - a long value.
 
 - 
toSubIndex
Description copied from class:AbstractVariableConverts the value of thisVariableto a (sub-)index value.- Specified by:
 toSubIndexin interfaceVariable- Specified by:
 toSubIndexin classAbstractVariable- Parameters:
 impliedLength- specifies if the sub-index has an implied length. This parameter applies to variable length variables only (e.g.OctetStringandOID). For other variables it has no effect.- Returns:
 - an OID that represents this value as an (sub-)index.
 
 - 
fromSubIndex
Description copied from class:AbstractVariableSets the value of thisVariablefrom the supplied (sub-)index.- Specified by:
 fromSubIndexin interfaceVariable- Specified by:
 fromSubIndexin classAbstractVariable- Parameters:
 subIndex- the sub-index OID.impliedLength- specifies if the sub-index has an implied length. This parameter applies to variable length variables only (e.g.OctetStringandOID). For other variables it has no effect.
 - 
successor
Returns the successor OID for this OID.- Returns:
 - an OID clone of this OID with a zero sub-identifier appended.
 - Since:
 - 1.7
 
 - 
predecessor
Returns the predecessor OID for this OID.- Returns:
 - if this OID ends on 0, then a 
MAX_OID_LENsub-identifier OID is returned where each sub-ID for index greater or equal tosize()is set toMAX_SUBID_VALUE. - Since:
 - 1.7
 
 - 
nextPeer
Returns the next following OID with the same or lesser size (length).- Returns:
 - OID the next OID on the same or upper level or a clone of this OID, if it has a zero length or is 2^32-1.
 - Since:
 - 1.7
 
 - 
max
Returns the greater of the two OID values.- Parameters:
 a- an OID.b- an OID.- Returns:
 aif a >= b,botherwise.- Since:
 - 1.7
 
 - 
min
Returns the lesser of the two OID values.- Parameters:
 a- an OID.b- an OID.- Returns:
 aif a <= b,botherwise.- Since:
 - 1.7
 
 - 
toIntArray
public int[] toIntArray()Description copied from interface:AssignableFromIntArrayReturns the value of this object as an int array.- Specified by:
 toIntArrayin interfaceAssignableFromIntArray- Returns:
 - an int array.
 
 
 -