Class Guid

java.lang.Object
de.uplanet.util.Guid

@Scriptable public final class Guid extends Object
This class represents global universal IDs.

Instances of this class are immutable.

This class uses the SHAPRNG for secure random numbers and the SHA-1 algorithm for hashing to 20 bytes.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    A GUID string representation that contains only zeroes.
    static final Guid
    The GUID that consists solely of zero bytes.
    static final String
    The algorithm used for generating GUIDs.
    static final int
    The length of a GUID represented as a string.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Check if the given string is not null and represents a GUID, and throw an IllegalArgumentException if this is not the case.
    static String
    Check if the given string is null or represents a GUID, and throw an IllegalArgumentException if this is not the case.
    static Guid
    Creates an instance of GUID using the SHAPRNG algorithm and the current system time.
    static Guid
    createInstance(byte[]... p_randomBytes)
    Creates an instance of GUID using given random bytes.
    boolean
    equals(Object p_obj)
     
    byte[]
    Get the GUIDs 20 bytes.
    int
     
    static boolean
    Tests if the given string is a GUID representation.
    static void
    Initialize the random number generator.
    Convert the GUID to a string.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • NULL

      public static final String NULL
      A GUID string representation that contains only zeroes.
      See Also:
    • NULL_GUID

      public static final Guid NULL_GUID
      The GUID that consists solely of zero bytes.
    • SHA1PRNG

      public static final String SHA1PRNG
      The algorithm used for generating GUIDs.
      See Also:
    • STRING_LENGTH

      public static final int STRING_LENGTH
      The length of a GUID represented as a string.
      See Also:
  • Method Details

    • seed

      public static void seed()
      Initialize the random number generator.

      This method should be called at most once per Java VM instance.

    • createInstance

      public static Guid createInstance()
      Creates an instance of GUID using the SHAPRNG algorithm and the current system time.
      Returns:
      An initialized instance of Guid.
    • createInstance

      public static Guid createInstance(byte[]... p_randomBytes)
      Creates an instance of GUID using given random bytes.
      Parameters:
      p_randomBytes - Random bytes that are used to create the GUID.
      Returns:
      An initialized instance of Guid.
    • getBytes

      public byte[] getBytes()
      Get the GUIDs 20 bytes.
      Returns:
      A copy of this GUIDs bytes.
    • isStringRepresentation

      public static boolean isStringRepresentation(String p_str)
      Tests if the given string is a GUID representation.
      Parameters:
      p_str - The string to test (may be null).
      Returns:
      true if the string represents a GUID, or false if the given value is null or does not represent a GUID.
    • checkValidOrNull

      public static String checkValidOrNull(String p_str)
      Check if the given string is null or represents a GUID, and throw an IllegalArgumentException if this is not the case.

      For security reasons possible error messages will contain at most an eight character prefix of the input string.

      Parameters:
      p_str - The string to check.
      Returns:
      The given string.
      Throws:
      IllegalArgumentException - If the given string is not null and does not represent a valid GUID.
    • checkValid

      public static String checkValid(String p_str)
      Check if the given string is not null and represents a GUID, and throw an IllegalArgumentException if this is not the case.

      For security reasons possible error messages will contain at most an eight character prefix of the input string.

      Parameters:
      p_str - The string to check.
      Returns:
      The given string.
      Throws:
      IllegalArgumentException - If the given string is null or does not represent a valid GUID.
    • equals

      public boolean equals(Object p_obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Convert the GUID to a string.
      Overrides:
      toString in class Object
      Returns:
      The string representation of the GUID.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object