Class AbstractMutableList.SubList<T>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess, SequencedCollection<T>, MutableCollection<T>, InternalIterable<T>, ListIterable<T>, MutableList<T>, OrderedIterable<T>, ReversibleIterable<T>, RichIterable<T>
Direct Known Subclasses:
AbstractMemoryEfficientMutableList.SubList
Enclosing class:
AbstractMutableList<T>

protected static class AbstractMutableList.SubList<T> extends AbstractMutableList<T> implements Serializable, RandomAccess
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • original

      private final MutableList<T> original
    • offset

      private final int offset
    • size

      private int size
  • Constructor Details

  • Method Details

    • toReversed

      public MutableList<T> toReversed()
      Description copied from interface: MutableList
      Returns a new MutableList in reverse order.
      Specified by:
      toReversed in interface ListIterable<T>
      Specified by:
      toReversed in interface MutableList<T>
      Specified by:
      toReversed in interface ReversibleIterable<T>
    • writeReplace

      protected Object writeReplace()
    • add

      public boolean add(T o)
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface List<T>
      Overrides:
      add in class AbstractMutableCollection<T>
    • set

      public T set(int index, T element)
      Specified by:
      set in interface List<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>
    • 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>
    • add

      public void add(int index, T element)
      Specified by:
      add in interface List<T>
    • remove

      public T remove(int index)
      Specified by:
      remove in interface List<T>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface List<T>
    • addAll

      public boolean addAll(Collection<? extends T> collection)
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface List<T>
      Overrides:
      addAll in class AbstractMutableCollection<T>
    • addAll

      public boolean addAll(int index, Collection<? extends T> collection)
      Specified by:
      addAll in interface List<T>
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface List<T>
      Overrides:
      iterator in class AbstractMutableList<T>
    • listIterator

      public ListIterator<T> listIterator(int index)
      Specified by:
      listIterator in interface List<T>
      Specified by:
      listIterator in interface ListIterable<T>
      Overrides:
      listIterator in class AbstractMutableList<T>
      See Also:
    • subList

      public MutableList<T> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<T>
      Specified by:
      subList in interface ListIterable<T>
      Specified by:
      subList in interface MutableList<T>
      Overrides:
      subList in class AbstractMutableList<T>
      See Also:
    • checkIfOutOfBounds

      private void checkIfOutOfBounds(int index)
    • clone

      public MutableList<T> clone()
      Specified by:
      clone in interface MutableList<T>
      Overrides:
      clone in class AbstractMutableList<T>
    • 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>
    • toStack

      public MutableStack<T> toStack()
      Description copied from interface: OrderedIterable
      Converts the OrderedIterable to a mutable MutableStack implementation.
      Specified by:
      toStack in interface OrderedIterable<T>
    • 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>