Record Class CodeType<T extends Code>

java.lang.Object
java.lang.Record
net.tangly.core.codes.CodeType<T>
Type Parameters:
T - reference code type
Record Components:
clazz - class of the reference code table
codes - list of all reference code table values

public record CodeType<T extends Code>(@NotNull Class<T extends Code> clazz, @NotNull List<T extends Code> codes) extends Record
The code type describes a reference code table entity and all the existing code values.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CodeType(@NotNull Class<T> clazz, @NotNull List<T> codes)
    Creates an instance of a CodeType record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Return all active codes defined for the code table.
    @NotNull Class<T>
    Returns the value of the clazz record component.
    @NotNull List<T>
    Returns the value of the codes record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    findCode(int id)
    Find the code with the given identifier.
    Find the first code with the given identifier.
    final int
    Returns a hash code value for this object.
    Return all inactive codes defined for the code table.
    static <E extends Enum<E> & Code>
    CodeType<E>
    of(Class<E> clazz)
    Builder for a reference code implemented as an enumeration.
    static <E extends Code>
    CodeType<E>
    of(Class<E> clazz, List<E> codes)
    Builder for a reference code implemented as a Java class.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CodeType

      public CodeType(@NotNull @NotNull Class<T> clazz, @NotNull @NotNull List<T> codes)
      Creates an instance of a CodeType record class.
      Parameters:
      clazz - the value for the clazz record component
      codes - the value for the codes record component
  • Method Details

    • of

      public static <E extends Enum<E> & Code> CodeType<E> of(Class<E> clazz)
      Builder for a reference code implemented as an enumeration. Provides a simple approach to map any enumeration type into a reference code.
      Type Parameters:
      E - reference code type
      Parameters:
      clazz - class of the reference code table enumeration
      Returns:
      code type of the reference code
    • of

      public static <E extends Code> CodeType<E> of(Class<E> clazz, List<E> codes)
      Builder for a reference code implemented as a Java class. Provides a pragmatic approach to map a class and a set of instances into a reference code.
      Type Parameters:
      E - reference code type
      Parameters:
      clazz - class of the reference code table
      codes - the set of code instances associated with the code class
      Returns:
      code type of the reference code
    • activeCodes

      public List<T> activeCodes()
      Return all active codes defined for the code table.
      Returns:
      list of active codes
    • inactiveCodes

      public List<T> inactiveCodes()
      Return all inactive codes defined for the code table.
      Returns:
      list of inactive codes
    • findCode

      public Optional<T> findCode(int id)
      Find the code with the given identifier.
      Parameters:
      id - identifier of the requested code
      Returns:
      the requested code or empty optional
    • findCode

      public Optional<T> findCode(String code)
      Find the first code with the given identifier.
      Parameters:
      code - code of the requested code
      Returns:
      the requested code or empty optional
    • 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.
    • clazz

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

      @NotNull public @NotNull List<T> codes()
      Returns the value of the codes record component.
      Returns:
      the value of the codes record component