public class OID extends AbstractVariable implements AssignableFromString, AssignableFromIntArray
OID
class allows definition and
manipulation of object identifiers.Modifier and Type | Field and Description |
---|---|
static int |
MAX_OID_LEN |
static int |
MAX_SUBID_VALUE |
SMISYNTAXES_PROPERTIES
Constructor and Description |
---|
OID()
Constructs a zero length OID.
|
OID(int[] rawOID)
Constructs an
OID from an array of integer values. |
OID(int[] prefixOID,
int suffixID)
Constructs an
OID from 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 an
OID from 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 an
OID from an array of integer values. |
OID(OID other)
Copy constructor.
|
OID(String oid)
Constructs an
OID from a dotted string. |
Modifier and Type | Method and Description |
---|---|
OID |
append(int subID)
Appends a sub-identifier to this OID.
|
OID |
append(OID oid)
Appends an
OID to this OID. |
OID |
append(String oid)
Appends a dotted String OID to this
OID . |
OID |
appendUnsigned(long subID)
Appends an unsigned long sub-identifier value to this OID.
|
Object |
clone()
Clones this variable.
|
int |
compareTo(Variable o) |
void |
decodeBER(BERInputStream inputStream)
Decodes a
Variable from an BERInputStream . |
void |
encodeBER(OutputStream outputStream)
Encodes a
Variable to an OutputStream . |
boolean |
equals(Object o) |
String |
format()
Format the OID as text.
|
void |
fromSubIndex(OID subIndex,
boolean impliedLength)
Sets the value of this
Variable from the supplied (sub-)index. |
int |
get(int index)
Gets the sub-identifier value at the specified position.
|
int |
getBERLength()
Returns the length of this
Variable in bytes when encoded
according to the Basic Encoding Rules (BER). |
int |
getSyntax()
Gets the ASN.1 syntax identifier value of this SNMP variable.
|
long |
getUnsigned(int index)
Gets the unsigned sub-identifier value at the specified position.
|
int[] |
getValue()
Gets all sub-identifiers as an int array.
|
int |
hashCode() |
boolean |
isValid()
Checks whether this
OID can be BER encoded. |
int |
last()
Returns the last sub-identifier as an integer value.
|
long |
lastUnsigned()
Returns the last sub-identifier as an unsigned long value.
|
int |
leftMostCompare(int n,
OID other)
Compares the n leftmost sub-identifiers with the given
OID
in left-to-right direction. |
OID |
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 OID |
max(OID a,
OID b)
Returns the greater of the two OID values.
|
static OID |
min(OID a,
OID b)
Returns the lesser of the two OID values.
|
OID |
nextPeer()
Returns the next following OID with the same or lesser size (length).
|
OID |
predecessor()
Returns the predecessor OID for this OID.
|
int |
removeLast()
Removes the last sub-identifier (if available) from this
OID
and returns it. |
int |
rightMostCompare(int n,
OID other)
Compares the n rightmost sub-identifiers in direction right-to-left
with those of the given
OID . |
void |
set(int index,
int value)
Sets the sub-identifier at the specified position.
|
void |
setValue(int[] value)
Sets the value from an array of integer values.
|
void |
setValue(String value) |
int |
size()
Returns the number of sub-identifiers in this
OID . |
boolean |
startsWith(OID other)
Check if the OID starts with the given OID.
|
OID |
successor()
Returns the successor OID for this OID.
|
byte[] |
toByteArray()
Returns the content of the as a byte array.
|
String |
toDottedString()
Returns the OID as dotted string (e.g., "1.3.6.1.4.1") regardless of what
OIDTextFormat instance is set in SNMP4JSettings . |
int |
toInt()
Returns an integer representation of this variable if
such a representation exists.
|
int[] |
toIntArray()
Returns the value of this object as an int array.
|
long |
toLong()
Returns a long representation of this variable if
such a representation exists.
|
String |
toString()
Return a string representation that can be parsed again to this
OID
by OID(String) . |
OID |
toSubIndex(boolean impliedLength)
Converts the value of this
Variable to a (sub-)index
value. |
OID |
trim()
Returns a new copy of this OID with the last sub-indentifier removed.
|
void |
trim(int n)
Remove the n rightmost subidentifiers from this OID.
|
createFromBER, createFromSyntax, equal, getBERPayloadLength, getSyntaxFromString, getSyntaxString, getSyntaxString, isDynamic, isException
public static final int MAX_OID_LEN
public static final int MAX_SUBID_VALUE
public OID()
public OID(String oid)
OID
from 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");
oid
- a dotted OID String, for example "1.3.6.1.2.2.1.0"public OID(int[] rawOID)
OID
from an array of integer values.rawOID
- an array of int
values. The array
is copied. Later changes to rawOID
will therefore not
affect the OID's value.public OID(int[] prefixOID, int[] suffixOID)
OID
from 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).prefixOID
- an array of int
values. The array
is copied. Later changes to prefixOID
will therefore not
affect the OID's value.suffixOID
- an array of int
values which will be appended to the
prefixOID
OID. The array is copied. Later changes to
suffixOID
will therefore not affect the OID's value.public OID(int[] prefixOID, int suffixID)
OID
from 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).prefixOID
- an array of int
values. The array
is copied. Later changes to prefixOID
will therefore not
affect the OID's value.suffixID
- an int
value that will be appended to the
prefixOID
OID. The array is copied. Later changes to
prefixOID
will therefore not affect the OID's value.public OID(int[] rawOID, int offset, int length)
OID
from an array of integer values.rawOID
- an array of int
values. The array
is copied. Later changes to rawOID
will therefore not
affect the OID's value.offset
- the zero based offset into the rawOID
that points to the
first sub-identifier of the new OID.length
- the length of the new OID, where offset + length
must be
less or equal the length of rawOID
. Otherwise an
IndexOutOfBoundsException
is thrown.public OID(OID other)
other
- OIDpublic final int getSyntax()
AbstractVariable
getSyntax
in interface Variable
getSyntax
in class AbstractVariable
public int hashCode()
hashCode
in interface Variable
hashCode
in class AbstractVariable
public final boolean equals(Object o)
equals
in interface Variable
equals
in class AbstractVariable
public OID mask(OctetString mask)
mask
- a mask where the n-th bit corresponds to the n-th sub-identifier.public final int compareTo(Variable o)
compareTo
in interface Comparable<Variable>
compareTo
in interface Variable
compareTo
in class AbstractVariable
public String toString()
OID
by OID(String)
.toString
in interface Variable
toString
in class AbstractVariable
OIDTextFormat.formatForRoundTrip(int[])
in SNMP4JSettings
.public String format()
toString()
but also fully converted index-to-text values like
snmp4jLogLoggerIndex.org.snmp4j.MessageDispatcherImpl
.OIDTextFormat.format(int[])
in SNMP4JSettings
.public String toDottedString()
OIDTextFormat
instance is set in SNMP4JSettings
.public byte[] toByteArray()
OctetString
or
IpAddress
instance.OID
as a byte array. Each
sub-identifier value is masked with 0xFF to form a byte value.public void encodeBER(OutputStream outputStream) throws IOException
AbstractVariable
Variable
to an OutputStream
.encodeBER
in interface BERSerializable
encodeBER
in class AbstractVariable
outputStream
- an OutputStream
.IOException
- if an error occurs while writing to the stream.public int getBERLength()
AbstractVariable
Variable
in bytes when encoded
according to the Basic Encoding Rules (BER).getBERLength
in interface BERSerializable
getBERLength
in class AbstractVariable
public void decodeBER(BERInputStream inputStream) throws IOException
AbstractVariable
Variable
from an BERInputStream
.decodeBER
in interface BERSerializable
decodeBER
in class AbstractVariable
inputStream
- an BERInputStream
containing a BER encoded byte stream.IOException
- if the stream could not be decoded by using BER rules.public void setValue(String value)
setValue
in interface AssignableFromString
public final void setValue(int[] value)
setValue
in interface AssignableFromIntArray
value
- The new valueIllegalArgumentException
- if value == null.public final int[] getValue()
public final int get(int index)
index
- a zero-based index into the OID
.index
. NOTE: The returned
value may be negative if the sub-identifier value is greater than
2^31
.ArrayIndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()).public final long getUnsigned(int index)
index
- intindex
as an unsigned long
value.public final void set(int index, int value)
index
- a zero-based index into the OID
.value
- a 32bit unsigned integer value.ArrayIndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()).public final OID append(String oid)
OID
.oid
- a dotted String with numerical sub-identifiers.public final OID append(OID oid)
OID
to this OID.oid
- an OID
instance.public final OID append(int subID)
subID
- an integer value.public final OID appendUnsigned(long subID)
subID
- an unsigned long value less or equal to 2^32-1.public boolean isValid()
OID
can be BER encoded.true
if size() >= 2 and size() <= 128 and if the first
two sub-identifiers are less than 3 and 40 respectively.public final int size()
OID
.public int leftMostCompare(int n, OID other)
OID
in left-to-right direction.n
- the number of sub-identifiers to compare.other
- an OID
to compare with this OID
.n
sub-identifiers are the same.
n
sub-identifiers of this
OID
are lexicographic less than those of the comparand.
n
sub-identifiers of this
OID
are lexicographic greater than those of the comparand.
public int rightMostCompare(int n, OID other)
OID
.n
- the number of sub-identifiers to compare.other
- an OID
to compare with this OID
.n
sub-identifiers are the same.
n
sub-identifiers of this
OID
are lexicographic less than those of the comparand.
n
sub-identifiers of this
OID
are lexicographic greater than those of the comparand.
public boolean startsWith(OID other)
other
- the OID to compare topublic Object clone()
Variable
clone
in interface Variable
clone
in class AbstractVariable
Variable
with the same value.public final int last()
NoSuchElementException
is thrownpublic final long lastUnsigned()
NoSuchElementException
is thrownpublic int removeLast()
OID
and returns it.OID
.public void trim(int n)
n
- the number of subidentifiers to remove. If n
is zero or
negative then this OID will not be changed. If n
is greater
than size()
all subidentifiers will be removed from this OID.public OID trim()
n-1
sub-identifiers where
n
is the size of this OID and greater than zero, otherwise
a zero length OID is returned.public int toInt()
AbstractVariable
toInt
in interface Variable
toInt
in class AbstractVariable
public long toLong()
AbstractVariable
toLong
in interface Variable
toLong
in class AbstractVariable
public final OID toSubIndex(boolean impliedLength)
AbstractVariable
Variable
to a (sub-)index
value.toSubIndex
in interface Variable
toSubIndex
in class AbstractVariable
impliedLength
- specifies if the sub-index has an implied length. This parameter applies
to variable length variables only (e.g. OctetString
and
OID
). For other variables it has no effect.public final void fromSubIndex(OID subIndex, boolean impliedLength)
AbstractVariable
Variable
from the supplied (sub-)index.fromSubIndex
in interface Variable
fromSubIndex
in class AbstractVariable
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. OctetString
and
OID
). For other variables it has no effect.public final OID successor()
public final OID predecessor()
MAX_OID_LEN
sub-identifier OID is returned where each sub-ID for index greater
or equal to size()
is set to MAX_SUBID_VALUE
.public final OID nextPeer()
public static OID max(OID a, OID b)
a
- an OID.b
- an OID.a
if a >= b, b
otherwise.public static OID min(OID a, OID b)
a
- an OID.b
- an OID.a
if a <= b, b
otherwise.public int[] toIntArray()
AssignableFromIntArray
toIntArray
in interface AssignableFromIntArray
Copyright © 2020 SNMP4J.org. All rights reserved.