Class ShortUuid

java.lang.Object
ai.bizone.shortuuid.ShortUuid

public class ShortUuid extends Object
ShortUuid is a class that can be used to encode and decode UUIDs to a shorter string representation.
  • Field Details

  • Constructor Details

    • ShortUuid

      public ShortUuid()
  • Method Details

    • random

      public static String random(boolean caseSensitive)
      Create a ShortUuid
      Parameters:
      caseSensitive - whether the id can be case-sensitive (in this case use a larger base to encode the id)
      Returns:
      ShortUuid encoded UUID
    • toShortUuid

      public static String toShortUuid(UUID uuid, boolean caseSensitive)
      Encode UUID to ShortUuid
      Parameters:
      uuid - UUID to be encoded
      caseSensitive - whether the id can be case-sensitive (in this case use a larger base to encode the id)
      Returns:
      ShortUuid encoded UUID
    • toUuid

      public static UUID toUuid(String shortId, boolean caseSensitive)
      Decode ShortUuid to UUID
      Parameters:
      shortId - encoded UUID
      caseSensitive - whether the id can be case-sensitive (in this case use a larger base to encode the id)
      Returns:
      decoded UUID
    • tryShorteningId

      public static String tryShorteningId(String id, boolean caseSensitive)
      Try to shorten an identifier, if it is a UUID it will be converted to Base36. Otherwise, all non-alphanumeric characters will be removed
      Parameters:
      id - An identifier to short
      caseSensitive - whether the id can be case-sensitive (in this case use a larger base to encode the id)
      Returns:
      The shortened string