Class CUID

java.lang.Object
icu.congee.id.generator.cuid.CUID
All Implemented Interfaces:
Serializable, Comparable<CUID>

public final class CUID extends Object implements Serializable, Comparable<CUID>
Collision-resistant ID optimized for horizontal scaling and performance.
Since:
1.0.0
See Also:
  • Method Details

    • randomCUID2

      public static CUID randomCUID2()
      Generates a new random CUID (Version 2).
      Returns:
      Newly generated CUID (Version 2)
      Since:
      2.0.0
    • randomCUID2

      public static CUID randomCUID2(int length)
      Generates a new random CUID (Version 2).
      Parameters:
      length - requested CUID length
      Returns:
      Newly generated CUID (Version 2)
      Since:
      2.0.1
    • randomCUID1

      public static CUID randomCUID1()
      Generates a new random CUID (Version 1).
      Returns:
      Newly generated CUID (Version 1)
      Since:
      2.0.0
    • fromString

      public static CUID fromString(String cuidAsString)
      Creates a CUID from the string standard representation.
      Parameters:
      cuidAsString - A string that specifies a CUID (Version 1 or 2)
      Returns:
      A CUID with the specified value
      Throws:
      IllegalArgumentException - If the string is not conform
      Since:
      1.0.0
    • isValid

      public static boolean isValid(String cuidAsString)
      Checks the CUID from the string standard representation.
      Parameters:
      cuidAsString - A string that specifies a CUID (Version 1 or 2)
      Returns:
      true If the string is conforms, otherwise, false
      Since:
      1.0.0
    • compareTo

      public int compareTo(CUID cuid)
      Specified by:
      compareTo in interface Comparable<CUID>
      Since:
      1.0.0
    • toString

      public String toString()
      Returns the string representation.
      Overrides:
      toString in class Object
      Returns:
      String containing the CUID
      Since:
      1.0.0
    • equals

      public boolean equals(Object o)
      Returns true if the argument is equal to current object, false otherwise.
      Overrides:
      equals in class Object
      Parameters:
      o - An object
      Since:
      1.0.0
    • hashCode

      public int hashCode()
      Generates a hash code.
      Overrides:
      hashCode in class Object
      Returns:
      Generated hashcode
      Since:
      1.0.0