Class QuadrupletonList<T>

All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess, SequencedCollection<T>, FixedSizeCollection<T>, MutableCollection<T>, InternalIterable<T>, FixedSizeList<T>, ListIterable<T>, MutableList<T>, OrderedIterable<T>, ReversibleIterable<T>, RichIterable<T>

final class QuadrupletonList<T> extends AbstractMemoryEfficientMutableList<T> implements Externalizable
This is a four element memory efficient List which is created by calling Lists.fixedSize.of(one, two, three, four).
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • element1

      private T element1
    • element2

      private T element2
    • element3

      private T element3
    • element4

      private T element4
  • Constructor Details

    • QuadrupletonList

      public QuadrupletonList()
    • QuadrupletonList

      QuadrupletonList(T obj1, T obj2, T obj3, T obj4)
  • Method Details

    • with

      public QuintupletonList<T> with(T value)
      Description copied from interface: MutableCollection
      This method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:
       MutableCollection<String> list = list.with("1");
       list = list.with("2");
       return list;
       
      In the case of FixedSizeCollection a new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.
      Specified by:
      with in interface FixedSizeCollection<T>
      Specified by:
      with in interface FixedSizeList<T>
      Specified by:
      with in interface MutableCollection<T>
      Specified by:
      with in interface MutableList<T>
      See Also:
    • clone

      public QuadrupletonList<T> clone()
      Specified by:
      clone in interface MutableList<T>
      Overrides:
      clone in class AbstractMemoryEfficientMutableList<T>
    • size

      public int size()
      Description copied from interface: RichIterable
      Returns the number of items in this iterable.
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in interface RichIterable<T>
    • get

      public T get(int index)
      Description copied from interface: ListIterable
      Returns the item at the specified position in this list iterable.
      Specified by:
      get in interface List<T>
      Specified by:
      get in interface ListIterable<T>
    • contains

      public boolean contains(Object obj)
      Description copied from interface: RichIterable
      Returns true if the iterable has an element which responds true to element.equals(object).
      Specified by:
      contains in interface Collection<T>
      Specified by:
      contains in interface List<T>
      Specified by:
      contains in interface RichIterable<T>
      Overrides:
      contains in class AbstractMutableList<T>
    • set

      public T set(int index, T element)
      set is implemented purely to allow the List to be sorted, not because this List should be considered mutable.
      Specified by:
      set in interface List<T>
    • replaceAll

      public void replaceAll(UnaryOperator<T> operator)
      Specified by:
      replaceAll in interface List<T>
      Since:
      10.0 - Overridden for efficiency
    • getFirst

      public T getFirst()
      Description copied from interface: RichIterable
      Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.

      The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.

      Specified by:
      getFirst in interface List<T>
      Specified by:
      getFirst in interface ListIterable<T>
      Specified by:
      getFirst in interface OrderedIterable<T>
      Specified by:
      getFirst in interface RichIterable<T>
      Specified by:
      getFirst in interface SequencedCollection<T>
      Overrides:
      getFirst in class AbstractMutableList<T>
    • getLast

      public T getLast()
      Description copied from interface: RichIterable
      Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.

      The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.

      Specified by:
      getLast in interface List<T>
      Specified by:
      getLast in interface ListIterable<T>
      Specified by:
      getLast in interface OrderedIterable<T>
      Specified by:
      getLast in interface RichIterable<T>
      Specified by:
      getLast in interface SequencedCollection<T>
      Overrides:
      getLast in class AbstractMutableList<T>
    • getOnly

      public T getOnly()
      Description copied from interface: RichIterable
      Returns the element if the iterable has exactly one element. Otherwise, throw IllegalStateException.
      Specified by:
      getOnly in interface RichIterable<T>
      Returns:
      an element of an iterable.
    • each

      public void each(Procedure<? super T> procedure)
      Description copied from interface: RichIterable
      The procedure is executed for each element in the iterable.

      Example using a Java 8 lambda expression:

       people.each(person -> LOGGER.info(person.getName()));
       

      Example using an anonymous inner class:

       people.each(new Procedure<Person>()
       {
           public void value(Person person)
           {
               LOGGER.info(person.getName());
           }
       });
       
      This method is a variant of InternalIterable.forEach(Procedure) that has a signature conflict with Iterable.forEach(java.util.function.Consumer).
      Specified by:
      each in interface RichIterable<T>
      Overrides:
      each in class AbstractMutableList<T>
      See Also:
    • forEachWithIndex

      public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
      Description copied from interface: InternalIterable
      Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

      Example using a Java 8 lambda:

       people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
       

      Example using an anonymous inner class:

       people.forEachWithIndex(new ObjectIntProcedure<Person>()
       {
           public void value(Person person, int index)
           {
               LOGGER.info("Index: " + index + " person: " + person.getName());
           }
       });
       
      Specified by:
      forEachWithIndex in interface InternalIterable<T>
      Specified by:
      forEachWithIndex in interface OrderedIterable<T>
      Overrides:
      forEachWithIndex in class AbstractMutableList<T>
    • forEachWith

      public <P> void forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
      Description copied from interface: InternalIterable
      The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

      Example using a Java 8 lambda:

       people.forEachWith((Person person, Person other) ->
           {
               if (person.isRelatedTo(other))
               {
                    LOGGER.info(person.getName());
               }
           }, fred);
       

      Example using an anonymous inner class:

       people.forEachWith(new Procedure2<Person, Person>()
       {
           public void value(Person person, Person other)
           {
               if (person.isRelatedTo(other))
               {
                    LOGGER.info(person.getName());
               }
           }
       }, fred);
       
      Specified by:
      forEachWith in interface InternalIterable<T>
      Overrides:
      forEachWith in class AbstractMutableList<T>
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException