Package de.fxlae.typeid
Record Class TypeId
java.lang.Object
java.lang.Record
de.fxlae.typeid.TypeId
- Record Components:
prefix- the prefix of theTypeIdto create. Might be an empty string, but not null.uuid- theUUIDof theTypeIdto create.
A
record for representing TypeIDs.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.static TypeIdgenerate()Creates a newTypeIdwithout prefix, based on UUIDv7.static TypeIdCreates a new prefixedTypeIdbased on UUIDv7.final inthashCode()Returns a hash code value for this object.static TypeIdstatic TypeIdstatic TypeIdParses the textual representation of a TypeID and returns aTypeIdinstance.static <T> TParses the textual representation of a TypeID and executes a handlerFunction, depending on the outcome.parseToOptional(String text) Parses the textual representation of a TypeID and returns anOptional.parseToValidated(String text) Parses the textual representation of a TypeID and returns aValidated.prefix()Returns the value of theprefixrecord component.toString()Returns the textual representation of thisTypeId.uuid()Returns the value of theuuidrecord component.
-
Constructor Details
-
Method Details
-
generate
Creates a new prefixedTypeIdbased on UUIDv7.- Parameters:
prefix- the prefix to use- Returns:
- the new
TypeId - Throws:
NullPointerException- if the prefix is nullIllegalArgumentException- if the prefix is invalid
-
generate
Creates a newTypeIdwithout prefix, based on UUIDv7.Note: "no prefix" means empty string, not null.
- Returns:
- the new
TypeId.
-
of
Creates a newTypeIdwithout prefix, based on the givenUUID.The
UUIDcan be of any version.Note: "no prefix" means empty string, not null.
- Parameters:
uuid- theUUIDto use- Returns:
- the new
TypeId - Throws:
NullPointerException- if the UUID is null
-
of
- Parameters:
prefix- the prefix to useuuid- theUUIDto use- Returns:
- the new
TypeId - Throws:
NullPointerException- if the prefix and/or UUID is nullIllegalArgumentException- if the prefix is invalid
-
parse
Parses the textual representation of a TypeID and returns aTypeIdinstance.- Parameters:
text- the textual representation.- Returns:
- the new
TypeId. - Throws:
NullPointerException- if the text is nullIllegalArgumentException- 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 handlerFunction, depending on the outcome. Both provided functions must have the same return type.- Type Parameters:
T- the result type of the handlerFunctionthat was executed- Parameters:
text- the textual representation of the TypeIDsuccessHandler- theFunctionthat is executed if the TypeID is valid, providing theTypeIderrorHandler- theFunctionthat is executed if the TypeID could not be parsed, providing the error message- Returns:
- the result of the handler
Functionthat was executed - Throws:
NullPointerException- if the successHandler and/or errorHandler is null
-
parseToOptional
Parses the textual representation of a TypeID and returns anOptional.- Parameters:
text- the textual representation of the TypeID- Returns:
- an
Optionalcontaining aTypeIdor an emptyTypeIdin case of validation errors - Throws:
NullPointerException- if the text is null
-
parseToValidated
Parses the textual representation of a TypeID and returns aValidated.- Parameters:
text- the textual representation of the TypeID- Returns:
- a valid
Validatedcontaining aTypeIdor an invalidValidatedwith an error message - Throws:
NullPointerException- if the text is null
-
toString
Returns the textual representation of thisTypeId. -
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. -
equals
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 withObjects::equals(Object,Object). -
prefix
Returns the value of theprefixrecord component.- Returns:
- the value of the
prefixrecord component
-
uuid
Returns the value of theuuidrecord component.- Returns:
- the value of the
uuidrecord component
-