Record Class TypeId

java.lang.Object
java.lang.Record
de.fxlae.typeid.TypeId
Record Components:
prefix - the prefix of the TypeId to create. Might be an empty string, but not null.
uuid - the UUID of the TypeId to create.

public record TypeId(String prefix, UUID uuid) extends Record
A record for representing TypeIDs.
  • Constructor Details

    • TypeId

      public TypeId(String prefix, UUID uuid)
      Creates an instance of a TypeId record class.
      Parameters:
      prefix - the value for the prefix record component
      uuid - the value for the uuid record component
  • Method Details

    • generate

      public static TypeId generate(String prefix)
      Creates a new prefixed TypeId based on UUIDv7.
      Parameters:
      prefix - the prefix to use
      Returns:
      the new TypeId
      Throws:
      NullPointerException - if the prefix is null
      IllegalArgumentException - if the prefix is invalid
    • generate

      public static TypeId generate()
      Creates a new TypeId without prefix, based on UUIDv7.

      Note: "no prefix" means empty string, not null.

      Returns:
      the new TypeId.
    • of

      public static TypeId of(UUID uuid)
      Creates a new TypeId without prefix, based on the given UUID.

      The UUID can be of any version.

      Note: "no prefix" means empty string, not null.

      Parameters:
      uuid - the UUID to use
      Returns:
      the new TypeId
      Throws:
      NullPointerException - if the UUID is null
    • of

      public static TypeId of(String prefix, UUID uuid)
      Creates a new TypeId, based on the given prefix and UUID.
      Parameters:
      prefix - the prefix to use
      uuid - the UUID to use
      Returns:
      the new TypeId
      Throws:
      NullPointerException - if the prefix and/or UUID is null
      IllegalArgumentException - if the prefix is invalid
    • parse

      public static TypeId parse(String text)
      Parses the textual representation of a TypeID and returns a TypeId instance.
      Parameters:
      text - the textual representation.
      Returns:
      the new TypeId.
      Throws:
      NullPointerException - if the text is null
      IllegalArgumentException - if the text is invalid
    • parse

      public static <T> T parse(String text, Function<TypeId,T> successHandler, Function<String,T> errorHandler)
      Parses the textual representation of a TypeID and executes a handler Function, depending on the outcome. Both provided functions must have the same return type.
      Type Parameters:
      T - the result type of the handler Function that was executed
      Parameters:
      text - the textual representation of the TypeID
      successHandler - the Function that is executed if the TypeID is valid, providing the TypeId
      errorHandler - the Function that is executed if the TypeID could not be parsed, providing the error message
      Returns:
      the result of the handler Function that was executed
      Throws:
      NullPointerException - if the successHandler and/or errorHandler is null
    • parseToOptional

      public static Optional<TypeId> parseToOptional(String text)
      Parses the textual representation of a TypeID and returns an Optional.
      Parameters:
      text - the textual representation of the TypeID
      Returns:
      an Optional containing a TypeId or an empty TypeId in case of validation errors
      Throws:
      NullPointerException - if the text is null
    • parseToValidated

      public static Validated<TypeId> parseToValidated(String text)
      Parses the textual representation of a TypeID and returns a Validated.
      Parameters:
      text - the textual representation of the TypeID
      Returns:
      a valid Validated containing a TypeId or an invalid Validated with an error message
      Throws:
      NullPointerException - if the text is null
    • toString

      public String toString()
      Returns the textual representation of this TypeId.
      Specified by:
      toString in class Record
      Returns:
      the textual representation.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • prefix

      public String prefix()
      Returns the value of the prefix record component.
      Returns:
      the value of the prefix record component
    • uuid

      public UUID uuid()
      Returns the value of the uuid record component.
      Returns:
      the value of the uuid record component