com.filenet.api.util
Class Id
- java.lang.Object
-
- com.filenet.api.util.Id
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable
- Direct Known Subclasses:
- SystemAddOnId, VersionStatusId
public class Id extends java.lang.Object implements java.io.Serializable, java.lang.Comparable
Immutable class that represents GUID values. This class can be constructed from either aString
or a byte array.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static Id
ZERO_ID
Convenience constant for the all-zero GUID.
-
Constructor Summary
Constructors Constructor and Description Id(byte[] bytes)
Constructs an ID with an array of bytes representing its GUID value.Id(java.lang.String id)
Constructs an ID from a string representing its GUID value.
-
Method Summary
Methods Modifier and Type Method and Description static Id
asIdOrNull(java.lang.String id)
Returns an Id if the passedString
is in GUID format.int
compareTo(java.lang.Object arg)
Compares two IDs.int
compareTo(java.lang.Object arg, DatabaseType dbType)
Compares two IDs as is done in a database search.static Id
createId()
Generates an ID with an IETF Version 4 UUID value.boolean
equals(java.lang.Object otherId)
Compares two IDs for logical equality.byte[]
getBytes()
Returns a copy of this ID as an array of bytes.int
hashCode()
Returns the hashcode for this ID.static boolean
isId(java.lang.String value)
Determines if aString
is an ID or not.java.lang.String
toString()
Returns the string representation of this ID.
-
-
-
Field Detail
-
ZERO_ID
public static final Id ZERO_ID
Convenience constant for the all-zero GUID.
-
-
Constructor Detail
-
Id
public Id(java.lang.String id)
Constructs an ID from a string representing its GUID value. A valid string consists of optional whitespace, an optional left brace({), followed by required 8 hexadecimal characters, a dash, 4 hexadecimal characters, a dash, 4 hexadecimal characters, a dash, 4 hexadecimal characters, a dash, and 12 hexadecimal characters, then finally an optional right brace(}) followed by whitespace. The braces must either both be present or both be omitted.
Example:{1234abcd-56ef-7a89-9fe8-7d65cd43ba21}
An exception is thrown if the input string does not conform to this format.- Parameters:
id
- GUID value in string format from which to construct an ID.
-
Id
public Id(byte[] bytes)
Constructs an ID with an array of bytes representing its GUID value.- Parameters:
bytes
- GUID value in byte array format from which to construct an ID.
-
-
Method Detail
-
createId
public static Id createId()
Generates an ID with an IETF Version 4 UUID value. This value is based on the Internet Engineering Task Force (IETF) UUID specification usingjava.security.SecureRandom
.- Returns:
- An
Id
object.
-
asIdOrNull
public static Id asIdOrNull(java.lang.String id)
Returns an Id if the passedString
is in GUID format. A valid string consists of optional whitespace, an optional left brace({), followed by required 8 hexadecimal characters, a dash, 4 hexadecimal characters, a dash, 4 hexadecimal characters, a dash, 4 hexadecimal characters, a dash, and 12 hexadecimal characters, then finally an optional right brace(}) followed by whitespace. The braces must either both be present or both be omitted.
Example:{1234abcd-56ef-7a89-9fe8-7d65cd43ba21}
If the inputString
does not conform to this format, the method returnsnull
. This method provides a more efficient alternative to callingisId(String)
followed conditionally bynew Id(String)
.- Parameters:
id
- GUID value in string format from which to construct an ID.- Returns:
- An
Id
object or null.
-
compareTo
public int compareTo(java.lang.Object arg)
Compares two IDs. This method returns -1 ifthis
is less thanarg
, 1 ifthis
is greater thanarg
, and 0 if the IDs are equal.This comparison is consistent with how IDs are compared in the DB2 and Oracle databases, but does not match how MSSQL Server compares IDs. For MSSQL Server databases, use
compareTo(arg, dbType)
.- Specified by:
compareTo
in interfacejava.lang.Comparable
- Parameters:
arg
- A JavaObject
representing the ID against which to compare this ID.- Returns:
- An integer (-1, 1, or 0).
-
compareTo
public int compareTo(java.lang.Object arg, DatabaseType dbType)
Compares two IDs as is done in a database search. This method returns -1 ifthis
is less thanarg
, 1 ifthis
is greater thanarg
, and 0 if the IDs are equal.This comparison matches the way that the databases compare IDs if done in a database search.
dbType
may benull
if the comparison algorithm does not need to match that of any particular database. Specifyingnull
fordbType
is the same as calling the single-parameter form of this method (compareTo(arg)
).- Parameters:
arg
- The GUID against which to compare this GUID.dbType
- An instance ofDatabaseType
; can benull
.- Returns:
- An integer (-1, 1, or 0).
-
equals
public boolean equals(java.lang.Object otherId)
Compares two IDs for logical equality.- Overrides:
equals
in classjava.lang.Object
- Parameters:
otherId
- The ID against which to compare this ID.- Returns:
true
ifotherId
is anId
object and their GUIDs are logically equal; otherwise, returnsfalse
.
-
getBytes
public byte[] getBytes()
Returns a copy of this ID as an array of bytes.- Returns:
- A copy of this ID as an array of bytes.
-
hashCode
public int hashCode()
Returns the hashcode for this ID.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- An integer representing the hashcode for the ID.
-
isId
public static boolean isId(java.lang.String value)
Determines if aString
is an ID or not.- Parameters:
value
- TheString
to verify.- Returns:
true
if the providedString
is in GUID format; otherwise, returnsfalse
.
-
toString
public java.lang.String toString()
Returns the string representation of this ID.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The ID as a
String
.
-
-