Class ObjectID
-
- All Implemented Interfaces:
DataObject
,Immutable
,Serializable
,Comparable<ObjectID>
public final class ObjectID extends ImmutableDataObject implements Comparable<ObjectID>
ObjectID is a representation of an ASN.1 OBJECT IDENTIFIER value.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().
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class com.opencloud.util.ImmutableDataObject
clone, isReadOnly, setReadOnly
-
-
-
-
Field Detail
-
EMPTY_OID
public static final ObjectID EMPTY_OID
An ObjectID that's different from all real network ObjectIDs.
-
-
Constructor Detail
-
ObjectID
public ObjectID(byte[] encoded)
Construct a new ObjectID from a BER-encoded representation. Decoding is deferred until needed. The caller should not subsequently modify the passed array.- Parameters:
encoded
- the BER encoded form- Throws:
NullPointerException
- ifencoded
is null
-
ObjectID
public ObjectID(int[] intIds)
Construct a new ObjectID from an array of subidentifiers. Encoding is performed immediately.- Parameters:
intIds
- an array of subidentifiers- Throws:
NullPointerException
- ifintIds
is nullIllegalArgumentException
- if any subidentifier is negative
-
ObjectID
public ObjectID(long[] ids)
Construct a new ObjectID from an array of subidentifiers. Encoding is performed immediately. The caller should not subsequently modify the passed array.- Parameters:
ids
- an array of subidentifiers- Throws:
NullPointerException
- ifintIds
is nullIllegalArgumentException
- if any subidentifier is negative, or if the first pair of subidentifiers is too large
-
-
Method Detail
-
parse
public static ObjectID parse(String str)
Converts a String to an ObjectID. Possible string forms are:"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)
- Parameters:
str
- the string to parse- Returns:
- the parsed ObjectID
- Throws:
NullPointerException
- if str is nullIllegalArgumentException
- if str cannot be parsed
-
getValue
public long[] getValue()
Get the decoded form of this object identifier, one long per subidentifier.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.
- Returns:
- an array of decoded subidentifiers
- Throws:
IllegalArgumentException
- if the underlying encoded form cannot be decoded
-
getEncodedForm
public byte[] getEncodedForm()
Get the BER encoded form of this object identifier. Encodings are computed once on construction, so this method is cheap.The caller should not modify the returned array.
- Returns:
- the BER-encoded form
-
compareTo
public int compareTo(ObjectID rhs)
- Specified by:
compareTo
in interfaceComparable<ObjectID>
-
equals
public boolean equals(Object obj)
Compare two ObjectIDs.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.
-
toString
public String toString()
Returns a string representation of this ObjectID.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.
-
-