Record Class TagType<T>

java.lang.Object
java.lang.Record
net.tangly.core.TagType<T>
Type Parameters:
T - type of the tags
Record Components:
namespace - namespace of the tags defined through the tag type
name - name of the tags defined through the tag type
kind - kind of the tag specifying if a value exists and if it is mandatory
clazz - class for the type of values stored in the tag
convert - mapping function between a string to a Java object representation of the string value. if multiple values are supported, the mapping function shall return a list of Java objects.
validate - validation function for the Java representation of the string tag value

public record TagType<T>(String namespace, @NotNull String name, @NotNull TagType.ValueKinds kind, @NotNull Class<T> clazz, Function<String,T> convert, BiPredicate<TagType<T>,T> validate) extends Record
Implements the conceptual type for a set of related tags, all the same class. The tag type also provides support to convert the text format of a tag into a Java object and to validate acceptable tag values.

A tag should be associated at most once with an entity. If multiple values are needed, the tag value should be a comma separated list of all values. The conversion method shall transform the comma separated string into a list of objects if needed.

  • Constructor Details

    • TagType

      public TagType(String namespace, @NotNull @NotNull String name, @NotNull @NotNull TagType.ValueKinds kind, @NotNull @NotNull Class<T> clazz, Function<String,T> convert, BiPredicate<TagType<T>,T> validate)
      Creates an instance of a TagType record class.
      Parameters:
      namespace - the value for the namespace record component
      name - the value for the name record component
      kind - the value for the kind record component
      clazz - the value for the clazz record component
      convert - the value for the convert record component
      validate - the value for the validate record component
  • Method Details

    • ofWithNoValue

      public static TagType<String> ofWithNoValue(String namespace, @NotNull @NotNull String name)
    • ofMandatoryString

      public static TagType<String> ofMandatoryString(String namespace, @NotNull @NotNull String name)
    • ofOptionalString

      public static TagType<String> ofOptionalString(String namespace, @NotNull @NotNull String name)
    • ofString

      public static TagType<String> ofString(String namespace, @NotNull @NotNull String name, @NotNull @NotNull TagType.ValueKinds kind)
    • ofString

      public static TagType<String> ofString(String namespace, @NotNull @NotNull String name, @NotNull @NotNull TagType.ValueKinds kind, @NotNull @NotNull BiPredicate<TagType<String>,String> validate)
    • ofMandatory

      public static <T> TagType<T> ofMandatory(String namespace, @NotNull @NotNull String name, Class<T> clazz, Function<String,T> convert, @NotNull @NotNull BiPredicate<TagType<T>,T> validate)
    • ofMandatory

      public static <T> TagType<T> ofMandatory(String namespace, @NotNull @NotNull String name, Class<T> clazz, @NotNull @NotNull Function<String,T> convert)
    • of

      public static <T> TagType<T> of(String namespace, @NotNull @NotNull String name, @NotNull @NotNull TagType.ValueKinds kind, @NotNull @NotNull Class<T> clazz, @NotNull @NotNull Function<String,T> convert)
    • of

      public static <T> TagType<T> of(String namespace, @NotNull @NotNull String name, @NotNull @NotNull TagType.ValueKinds kind, Class<T> clazz, Function<String,T> convert, BiPredicate<TagType<T>,T> validate)
    • canHaveValue

      public boolean canHaveValue()
    • mustHaveValue

      public boolean mustHaveValue()
    • value

      public T value(@NotNull @NotNull Tag tag)
      Transforms a tag string value into a Java object.
      Parameters:
      tag - tag which value should be converted
      Returns:
      the Java object representation of the tag value
    • of

      public Tag of(T value)
      Creates a tag with the given value using the tag type configuration.
      Parameters:
      value - value of the tag
      Returns:
      new tag instance
    • of

      public Tag of(String value)
    • validate

      public boolean validate(@NotNull @NotNull String value)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
    • namespace

      public String namespace()
      Returns the value of the namespace record component.
      Returns:
      the value of the namespace record component
    • name

      @NotNull public @NotNull String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • kind

      @NotNull public @NotNull TagType.ValueKinds kind()
      Returns the value of the kind record component.
      Returns:
      the value of the kind record component
    • clazz

      @NotNull public @NotNull Class<T> clazz()
      Returns the value of the clazz record component.
      Returns:
      the value of the clazz record component
    • convert

      public Function<String,T> convert()
      Returns the value of the convert record component.
      Returns:
      the value of the convert record component
    • validate

      public BiPredicate<TagType<T>,T> validate()
      Returns the value of the validate record component.
      Returns:
      the value of the validate record component