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.ComparableImmutable class that represents GUID values. This class can be constructed from either aStringor a byte array.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static IdZERO_IDConvenience 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static IdasIdOrNull(java.lang.String id)Returns an Id if the passedStringis in GUID format.intcompareTo(java.lang.Object arg)Compares two IDs.intcompareTo(java.lang.Object arg, DatabaseType dbType)Compares two IDs as is done in a database search.static IdcreateId()Generates an ID with an IETF Version 4 UUID value.static IdcreateSequentialId(DatabaseType dbType)Generates an ID that has a time- and counter-based portion that is combined with a random portion in such a way that consecutively created IDs are sequential (monotonic) per the natural ordering applied by the underlying database.booleanequals(java.lang.Object otherId)Compares two IDs for logical equality.bytegetByte(int index)Returns a single byte from this ID.byte[]getBytes()Returns a copy of this ID as an array of bytes.inthashCode()Returns the hashcode for this ID.static booleanisId(java.lang.String value)Determines if aStringis an ID or not.java.lang.StringtoString()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
Idobject.
-
createSequentialId
public static Id createSequentialId(DatabaseType dbType)
Generates an ID that has a time- and counter-based portion that is combined with a random portion in such a way that consecutively created IDs are sequential (monotonic) per the natural ordering applied by the underlying database.- Parameters:
dbType- ADatabaseTypeobject that specifies the type of database.- Returns:
- An
Idobject.
-
asIdOrNull
public static Id asIdOrNull(java.lang.String id)
Returns an Id if the passedStringis 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 inputStringdoes 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
Idobject or null.
-
compareTo
public int compareTo(java.lang.Object arg)
Compares two IDs. This method returns -1 ifthisis less thanarg, 1 ifthisis 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:
compareToin interfacejava.lang.Comparable- Parameters:
arg- A JavaObjectrepresenting 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 ifthisis less thanarg, 1 ifthisis 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.
dbTypemay benullif the comparison algorithm does not need to match that of any particular database. SpecifyingnullfordbTypeis 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:
equalsin classjava.lang.Object- Parameters:
otherId- The ID against which to compare this ID.- Returns:
trueifotherIdis anIdobject 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.
-
getByte
public byte getByte(int index)
Returns a single byte from this ID.- Parameters:
index- The index of the byte retrieve.- Returns:
- The byte at that index.
-
hashCode
public int hashCode()
Returns the hashcode for this ID.- Overrides:
hashCodein classjava.lang.Object- Returns:
- An integer representing the hashcode for the ID.
-
isId
public static boolean isId(java.lang.String value)
Determines if aStringis an ID or not.- Parameters:
value- TheStringto verify.- Returns:
trueif the providedStringis in GUID format; otherwise, returnsfalse.
-
toString
public java.lang.String toString()
Returns the string representation of this ID.- Overrides:
toStringin classjava.lang.Object- Returns:
- The ID as a
String.
-
-