Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops committed Jul 7, 2023
1 parent 84b41a7 commit 36900bd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/typeid/TypeID.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*
* <p>Values are expected to be constructed with <code>new TypeID("typename")</code> or parsed from
* their string representation with <code>TypeID.fromString("prefix_01h455vb4pex5vsknk084sn02q")
* </code>
* </code> or an existing standard library UUID <code>TypeID.fromUUID("prefix", uuid)</code> Values
* are serialized to their string format by calling <code>typeId.toString()</code>
*/
public record TypeID(String prefix, String suffix) {
private static final Predicate<String> PREFIX =
Expand All @@ -39,16 +40,17 @@ public TypeID(String prefix) {
this(prefix, Base32.encode(UUIDv7.generate().bytes()).get());
}

/** return suffix in standard UUID format */
/** Returns the TypeID's suffix in standard library UUID format */
public UUID uuid() {
return new UUIDv7(Base32.decode(suffix.getBytes()).get()).uuid();
}

/** Returns a string representation of this TypeID */
@Override
public String toString() {
return switch (prefix) {
case "" -> suffix;
default -> prefix + DELIMETER + suffix;
default -> String.join(DELIMETER, prefix, suffix);
};
}

Expand Down

0 comments on commit 36900bd

Please sign in to comment.