Package io.crums.util

Class ListExtension<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<T>
io.crums.util.ListExtension<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess

public class ListExtension<T>
extends java.util.AbstractList<T>
implements java.util.RandomAccess
A first list extended by a second. The present use case is when the first list is read-only, but this class imposes no restrictions. This is just a serial view of 2 otherwise independent lists.
  • Field Summary

    Fields inherited from class java.util.AbstractList

    modCount
  • Constructor Summary

    Constructors
    Constructor Description
    ListExtension​(java.util.List<T> first)
    Creqte a new instance by extending the first list with an ArrayList.
    ListExtension​(java.util.List<T> first, java.util.List<T> second)
    Creates an instance composed of the given 2 lists.
  • Method Summary

    Modifier and Type Method Description
    boolean add​(T e)
    Adds to the second.
    boolean addAll​(java.util.Collection<? extends T> c)
    Adds to the second.
    java.util.List<T> first()
    Returns the first list.
    T get​(int index)  
    java.util.List<T> second()
    Returns the second list.
    int size()  

    Methods inherited from class java.util.AbstractList

    add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList

    Methods inherited from class java.util.AbstractCollection

    contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.List

    contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
  • Constructor Details

    • ListExtension

      public ListExtension​(java.util.List<T> first)
      Creqte a new instance by extending the first list with an ArrayList.
    • ListExtension

      public ListExtension​(java.util.List<T> first, java.util.List<T> second)
      Creates an instance composed of the given 2 lists.
  • Method Details

    • add

      public boolean add​(T e)

      Adds to the second.

      Specified by:
      add in interface java.util.Collection<T>
      Specified by:
      add in interface java.util.List<T>
      Overrides:
      add in class java.util.AbstractList<T>
    • addAll

      public boolean addAll​(java.util.Collection<? extends T> c)

      Adds to the second.

      Specified by:
      addAll in interface java.util.Collection<T>
      Specified by:
      addAll in interface java.util.List<T>
      Overrides:
      addAll in class java.util.AbstractCollection<T>
    • first

      public java.util.List<T> first()
      Returns the first list.
    • second

      public java.util.List<T> second()
      Returns the second list.
    • get

      public T get​(int index)
      Specified by:
      get in interface java.util.List<T>
      Specified by:
      get in class java.util.AbstractList<T>
    • size

      public int size()
      Specified by:
      size in interface java.util.Collection<T>
      Specified by:
      size in interface java.util.List<T>
      Specified by:
      size in class java.util.AbstractCollection<T>
      Returns:
      the sum of the sizes of the first() and second() internal lists.