Record Class IdNonEmptyList<T>

java.lang.Object
java.lang.Record
com.io7m.idstore.model.IdNonEmptyList<T>
Type Parameters:
T - The type of elements
Record Components:
first - The first element
rest - The rest of the elements
All Implemented Interfaces:
Iterable<T>

public record IdNonEmptyList<T>(T first, List<T> rest) extends Record implements Iterable<T>
A non-empty list.
  • Constructor Details

    • IdNonEmptyList

      public IdNonEmptyList(T first, List<T> rest)
      A non-empty list.
      Parameters:
      first - The first element
      rest - The rest of the elements
  • Method Details

    • single

      public static <T> IdNonEmptyList<T> single(T x)
      Create a one-element list.
      Type Parameters:
      T - The type of elements
      Parameters:
      x - The element
      Returns:
      The result list
    • toList

      public List<T> toList()
      Returns:
      This list as a plain immutable list
    • ofList

      public static <T> IdNonEmptyList<T> ofList(List<T> items) throws IdValidityException
      The list as a non-empty list.
      Type Parameters:
      T - The type of elements
      Parameters:
      items - The list elements
      Returns:
      The list
      Throws:
      IdValidityException - On empty lists
    • contains

      public boolean contains(T email)
      Parameters:
      email - The email address
      Returns:
      true if the list contains the given email
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • size

      public int size()
      Returns:
      The list size
    • 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.
    • first

      public T first()
      Returns the value of the first record component.
      Returns:
      the value of the first record component
    • rest

      public List<T> rest()
      Returns the value of the rest record component.
      Returns:
      the value of the rest record component