public final class ObjectID extends ImmutableDataObject implements Comparable<ObjectID>
It is limited to representing values where all packed subidentifiers can be represented as positive Java longs (i.e. 63 bits or less).
This class is threadsafe, and is immutable assuming that callers do not modify arrays passed to the constructor or returned from getEncodedForm() / getValue().
Modifier and Type | Field and Description |
---|---|
static ObjectID |
EMPTY_OID
An ObjectID that's different from all real network ObjectIDs.
|
Constructor and Description |
---|
ObjectID(byte[] encoded)
Construct a new ObjectID from a BER-encoded representation.
|
ObjectID(int[] intIds)
Construct a new ObjectID from an array of subidentifiers.
|
ObjectID(long[] ids)
Construct a new ObjectID from an array of subidentifiers.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ObjectID rhs) |
boolean |
equals(Object obj)
Compare two ObjectIDs.
|
byte[] |
getEncodedForm()
Get the BER encoded form of this object identifier.
|
long[] |
getValue()
Get the decoded form of this object identifier, one long per
subidentifier.
|
int |
hashCode() |
static ObjectID |
parse(String str)
Converts a String to an ObjectID.
|
String |
toString()
Returns a string representation of this ObjectID.
|
clone, isReadOnly, setReadOnly
public static final ObjectID EMPTY_OID
public ObjectID(byte[] encoded)
encoded
- the BER encoded formNullPointerException
- if encoded
is nullpublic ObjectID(int[] intIds)
intIds
- an array of subidentifiersNullPointerException
- if intIds
is nullIllegalArgumentException
- if any subidentifier is negativepublic ObjectID(long[] ids)
ids
- an array of subidentifiersNullPointerException
- if intIds
is nullIllegalArgumentException
- if any subidentifier is negative, or if the first pair of subidentifiers is too largepublic static ObjectID parse(String str)
"0.1.2.3.4.5" (the dot form) "{ 0 1 2 3 4 5 }" (the ASN.1 form) "{ 0 foo(1) 2 bar(3) 4 5 }" (the ASN.1 form, including identifiers)
str
- the string to parseNullPointerException
- if str is nullIllegalArgumentException
- if str cannot be parsedpublic long[] getValue()
Decoding is performed lazily for ObjectID instances created from an encoded form. Decoding may fail if the underlying encoded form is malformed, or if a valid encoded form contains packed subidentifiers that cannot be represented as a positive Java long.
The caller should not modify the returned array.
IllegalArgumentException
- if the underlying encoded form cannot be decodedpublic byte[] getEncodedForm()
The caller should not modify the returned array.
public int compareTo(ObjectID rhs)
compareTo
in interface Comparable<ObjectID>
public boolean equals(Object obj)
Equality is defined based on the encoded form of the object identifier. This means that illegal non-minimal encodings of an object identifier will not compare equal to an equivalent, correctly-encoded, value.
public String toString()
The returned string follows the ASN.1 syntax for
OBJECT IDENTIFIERS: a list of space-separated
subidentifiers surrounded by { }
If the underlying encoded form cannot be decoded, then an ASN.1-style inline comment reporting the decode exception is included in place of the subidentifiers.