Class CompositeFastList<E>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, MutableCollection<E>, InternalIterable<E>, ListIterable<E>, MutableList<E>, OrderedIterable<E>, ReversibleIterable<E>, RichIterable<E>, BatchIterable<E>

public final class CompositeFastList<E> extends AbstractMutableList<E> implements BatchIterable<E>, Serializable
CompositeFastList behaves like a list, but is composed of at least one list. It is useful where you don't want the additional expense of appending several lists or allocating memory for a super list to add multiple sublists to.

Note: mutation operations (e.g. add and remove, sorting) will change the underlying lists - so be sure to only use a composite list where it will be the only reference to the sublists (for example, a composite list which contains multiple query results is OK as long as it is the only thing that references the lists)

See Also:
  • Constructor Details

    • CompositeFastList

      public CompositeFastList()
  • Method Details

    • clone

      public MutableList<E> clone()
      Specified by:
      clone in interface MutableList<E>
      Overrides:
      clone in class AbstractMutableList<E>
    • size

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

      public void resetSize()
    • batchForEach

      public void batchForEach(Procedure<? super E> procedure, int sectionIndex, int sectionCount)
      Specified by:
      batchForEach in interface BatchIterable<E>
    • getBatchCount

      public int getBatchCount(int batchSize)
      Specified by:
      getBatchCount in interface BatchIterable<E>
    • reverseThis

      public CompositeFastList<E> reverseThis()
      Description copied from interface: MutableList
      Mutates this list by reversing its order and returns the current list as a result.
      Specified by:
      reverseThis in interface MutableList<E>
    • each

      public void each(Procedure<? super E> 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<E>
      Overrides:
      each in class AbstractMutableList<E>
      See Also:
    • injectInto

      public <IV> IV injectInto(IV injectedValue, Function2<? super IV,? super E,? extends IV> function)
      Description copied from interface: RichIterable
      Returns the final result of evaluating function using each element of the iterable and the previous evaluation result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current item in the iterable is used as the second parameter. This method is commonly called fold or sometimes reduce.
      Specified by:
      injectInto in interface RichIterable<E>
      Overrides:
      injectInto in class AbstractMutableList<E>
    • injectInto

      public int injectInto(int injectedValue, IntObjectToIntFunction<? super E> function)
      Description copied from interface: RichIterable
      Returns the final int result of evaluating function using each element of the iterable and the previous evaluation result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current item in the iterable is used as the second parameter.
      Specified by:
      injectInto in interface RichIterable<E>
      Overrides:
      injectInto in class AbstractMutableList<E>
    • injectInto

      public float injectInto(float injectedValue, FloatObjectToFloatFunction<? super E> function)
      Description copied from interface: RichIterable
      Returns the final float result of evaluating function using each element of the iterable and the previous evaluation result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current item in the iterable is used as the second parameter.
      Specified by:
      injectInto in interface RichIterable<E>
      Overrides:
      injectInto in class AbstractMutableList<E>
    • injectInto

      public long injectInto(long injectedValue, LongObjectToLongFunction<? super E> function)
      Description copied from interface: RichIterable
      Returns the final long result of evaluating function using each element of the iterable and the previous evaluation result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current item in the iterable is used as the second parameter.
      Specified by:
      injectInto in interface RichIterable<E>
      Overrides:
      injectInto in class AbstractMutableList<E>
    • injectInto

      public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? super E> function)
      Description copied from interface: RichIterable
      Returns the final double result of evaluating function using each element of the iterable and the previous evaluation result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current item in the iterable is used as the second parameter.
      Specified by:
      injectInto in interface RichIterable<E>
      Overrides:
      injectInto in class AbstractRichIterable<E>
    • forEachWithIndex

      public void forEachWithIndex(ObjectIntProcedure<? super E> 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<E>
      Specified by:
      forEachWithIndex in interface OrderedIterable<E>
      Overrides:
      forEachWithIndex in class AbstractMutableList<E>
    • reverseForEach

      public void reverseForEach(Procedure<? super E> procedure)
      Description copied from interface: ReversibleIterable
      Evaluates the procedure for each element of the list iterating in reverse order.
      e.g.
       people.reverseForEach(person -> LOGGER.info(person.getName()));
       
      Specified by:
      reverseForEach in interface ReversibleIterable<E>
    • reverseForEachWithIndex

      public void reverseForEachWithIndex(ObjectIntProcedure<? super E> procedure)
      Description copied from interface: ReversibleIterable
      Evaluates the procedure for each element and it's index in reverse order.
      e.g.
       people.reverseForEachWithIndex((person, index) ->
               LOGGER.info("Index: " + index + " person: " + person.getName()));
       
      Specified by:
      reverseForEachWithIndex in interface ReversibleIterable<E>
    • forEachWith

      public <P> void forEachWith(Procedure2<? super E,? super P> procedure2, 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<E>
      Overrides:
      forEachWith in class AbstractMutableList<E>
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: RichIterable
      Returns true if this iterable has zero items.
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
      Specified by:
      isEmpty in interface RichIterable<E>
      Overrides:
      isEmpty in class AbstractRichIterable<E>
    • contains

      public boolean contains(Object object)
      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<E>
      Specified by:
      contains in interface List<E>
      Specified by:
      contains in interface RichIterable<E>
      Overrides:
      contains in class AbstractMutableList<E>
    • iterator

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

      public Object[] toArray()
      Description copied from interface: RichIterable
      Converts this iterable to an array.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
      Specified by:
      toArray in interface RichIterable<E>
      Overrides:
      toArray in class AbstractRichIterable<E>
      See Also:
    • add

      public boolean add(E object)
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface List<E>
      Overrides:
      add in class AbstractMutableCollection<E>
    • remove

      public boolean remove(Object object)
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface List<E>
      Overrides:
      remove in class AbstractMutableCollection<E>
    • addAll

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

      public boolean containsAll(Collection<?> collection)
      Description copied from interface: RichIterable
      Returns true if all elements in source are contained in this collection.
      Specified by:
      containsAll in interface Collection<E>
      Specified by:
      containsAll in interface List<E>
      Specified by:
      containsAll in interface RichIterable<E>
      Overrides:
      containsAll in class AbstractMutableList<E>
      See Also:
    • toArray

      public Object[] toArray(Object[] array)
      Description copied from interface: RichIterable
      Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
      Specified by:
      toArray in interface RichIterable<E>
      Overrides:
      toArray in class AbstractRichIterable<E>
      See Also:
    • addComposited

      public void addComposited(Collection<? extends E> collection)
    • addAll

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

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
    • retainAll

      public boolean retainAll(Collection<?> collection)
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface List<E>
      Overrides:
      retainAll in class AbstractMutableList<E>
    • removeAll

      public boolean removeAll(Collection<?> collection)
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface List<E>
      Overrides:
      removeAll in class AbstractMutableList<E>
    • get

      public E 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<E>
      Specified by:
      get in interface ListIterable<E>
    • set

      public E set(int index, E element)
      Specified by:
      set in interface List<E>
    • add

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

      public E remove(int index)
      Specified by:
      remove in interface List<E>
    • indexOf

      public int indexOf(Object o)
      Description copied from interface: OrderedIterable
      Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.
      Specified by:
      indexOf in interface List<E>
      Specified by:
      indexOf in interface OrderedIterable<E>
      Overrides:
      indexOf in class AbstractMutableList<E>
      See Also:
    • lastIndexOf

      public int lastIndexOf(Object o)
      Description copied from interface: ListIterable
      Returns the index of the last occurrence of the specified item in this list, or -1 if this list does not contain the item.
      Specified by:
      lastIndexOf in interface List<E>
      Specified by:
      lastIndexOf in interface ListIterable<E>
      Overrides:
      lastIndexOf in class AbstractMutableList<E>
    • replaceAll

      public void replaceAll(UnaryOperator<E> operator)
      Specified by:
      replaceAll in interface List<E>
      Since:
      10.0
    • sort

      public void sort(Comparator<? super E> comparator)
      Specified by:
      sort in interface List<E>
    • listIterator

      public ListIterator<E> listIterator()
      a list iterator is a problem for a composite list as going back in the order of the list is an issue, as are the other methods like set() and add() (and especially, remove). Convert the internal lists to one list (if not already just one list) and return that list's list iterator.

      AFAIK list iterator is only commonly used in sorting.

      Specified by:
      listIterator in interface List<E>
      Specified by:
      listIterator in interface ListIterable<E>
      Overrides:
      listIterator in class AbstractMutableList<E>
      Returns:
      a ListIterator for this, with internal state converted to one list if needed.
      See Also:
    • listIterator

      public ListIterator<E> listIterator(int index)
      a list iterator is a problem for a composite list as going back in the order of the list is an issue, as are the other methods like set() and add() (and especially, remove). Convert the internal lists to one list (if not already just one list) and return that list's list iterator.

      AFAIK list iterator is only commonly used in sorting.

      Specified by:
      listIterator in interface List<E>
      Specified by:
      listIterator in interface ListIterable<E>
      Overrides:
      listIterator in class AbstractMutableList<E>
      Returns:
      a ListIterator for this, with internal state converted to one list if needed.
      See Also:
    • count

      public int count(Predicate<? super E> predicate)
      Description copied from interface: RichIterable
      Return the total number of elements that answer true to the specified predicate.

      Example using a Java 8 lambda expression:

       int count =
           people.count(person -> person.getAddress().getState().getName().equals("New York"));
       

      Example using an anonymous inner class:

       int count =
           people.count(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.getAddress().getState().getName().equals("New York");
               }
           });
       
      Specified by:
      count in interface RichIterable<E>
      Overrides:
      count in class AbstractMutableList<E>
    • countWith

      public <P> int countWith(Predicate2<? super E,? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns the total number of elements that evaluate to true for the specified predicate.
      e.g.
       return lastNames.countWith(Predicates2.equal(), "Smith");
       
      Specified by:
      countWith in interface RichIterable<E>
      Overrides:
      countWith in class AbstractMutableList<E>
    • anySatisfy

      public boolean anySatisfy(Predicate<? super E> predicate)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.
      Specified by:
      anySatisfy in interface RichIterable<E>
      Overrides:
      anySatisfy in class AbstractMutableList<E>
    • select

      public <R extends Collection<E>> R select(Predicate<? super E> predicate, R target)
      Description copied from interface: RichIterable
      Same as the select method with one parameter but uses the specified target collection for the results.

      Example using a Java 8 lambda expression:

       MutableList<Person> selected =
           people.select(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
       

      Example using an anonymous inner class:

       MutableList<Person> selected =
           people.select(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.person.getLastName().equals("Smith");
               }
           }, Lists.mutable.empty());
       

      Specified by:
      select in interface RichIterable<E>
      Overrides:
      select in class AbstractMutableList<E>
      Parameters:
      predicate - a Predicate to use as the select criteria
      target - the Collection to append to for all elements in this RichIterable that meet select criteria predicate
      Returns:
      target, which contains appended elements as a result of the select criteria
      See Also:
    • selectWith

      public <P, R extends Collection<E>> R selectWith(Predicate2<? super E,? super P> predicate, P parameter, R target)
      Description copied from interface: RichIterable
      Similar to RichIterable.select(Predicate, Collection), except with an evaluation parameter for the second generic argument in Predicate2.

      E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

      Example using a Java 8 lambda expression:

       MutableList<Person> selected =
           people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18), Lists.mutable.empty());
       

      Example using an anonymous inner class:

       MutableList<Person> selected =
           people.selectWith(new Predicate2<Person, Integer>()
           {
               public boolean accept(Person person, Integer age)
               {
                   return person.getAge()>= age;
               }
           }, Integer.valueOf(18), Lists.mutable.empty());
       
      Specified by:
      selectWith in interface RichIterable<E>
      Overrides:
      selectWith in class AbstractMutableList<E>
      Parameters:
      predicate - a Predicate2 to use as the select criteria
      parameter - a parameter to pass in for evaluation of the second argument P in predicate
      target - the Collection to append to for all elements in this RichIterable that meet select criteria predicate
      Returns:
      targetCollection, which contains appended elements as a result of the select criteria
      See Also:
    • reject

      public <R extends Collection<E>> R reject(Predicate<? super E> predicate, R target)
      Description copied from interface: RichIterable
      Same as the reject method with one parameter but uses the specified target collection for the results.

      Example using a Java 8 lambda expression:

       MutableList<Person> rejected =
           people.reject(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
       

      Example using an anonymous inner class:

       MutableList<Person> rejected =
           people.reject(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.person.getLastName().equals("Smith");
               }
           }, Lists.mutable.empty());
       
      Specified by:
      reject in interface RichIterable<E>
      Overrides:
      reject in class AbstractMutableList<E>
      Parameters:
      predicate - a Predicate to use as the reject criteria
      target - the Collection to append to for all elements in this RichIterable that cause Predicate#accept(Object) method to evaluate to false
      Returns:
      target, which contains appended elements as a result of the reject criteria
    • rejectWith

      public <P, R extends Collection<E>> R rejectWith(Predicate2<? super E,? super P> predicate, P parameter, R target)
      Description copied from interface: RichIterable
      Similar to RichIterable.reject(Predicate, Collection), except with an evaluation parameter for the second generic argument in Predicate2.

      E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

      Example using a Java 8 lambda expression:

       MutableList<Person> rejected =
           people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18), Lists.mutable.empty());
       

      Example using an anonymous inner class:

       MutableList<Person> rejected =
           people.rejectWith(new Predicate2<Person, Integer>()
           {
               public boolean accept(Person person, Integer age)
               {
                   return person.getAge() < age;
               }
           }, Integer.valueOf(18), Lists.mutable.empty());
       
      Specified by:
      rejectWith in interface RichIterable<E>
      Overrides:
      rejectWith in class AbstractMutableList<E>
      Parameters:
      predicate - a Predicate2 to use as the reject criteria
      parameter - a parameter to pass in for evaluation of the second argument P in predicate
      target - the Collection to append to for all elements in this RichIterable that cause Predicate#accept(Object) method to evaluate to false
      Returns:
      targetCollection, which contains appended elements as a result of the reject criteria
      See Also:
    • collect

      public <V, R extends Collection<V>> R collect(Function<? super E,? extends V> function, R target)
      Description copied from interface: RichIterable
      Same as RichIterable.collect(Function), except that the results are gathered into the specified target collection.

      Example using a Java 8 lambda expression:

       MutableList<String> names =
           people.collect(person -> person.getFirstName() + " " + person.getLastName(), Lists.mutable.empty());
       

      Example using an anonymous inner class:

       MutableList<String> names =
           people.collect(new Function<Person, String>()
           {
               public String valueOf(Person person)
               {
                   return person.getFirstName() + " " + person.getLastName();
               }
           }, Lists.mutable.empty());
       
      Specified by:
      collect in interface RichIterable<E>
      Overrides:
      collect in class AbstractMutableList<E>
      Parameters:
      function - a Function to use as the collect transformation function
      target - the Collection to append to for all elements in this RichIterable that meet select criteria function
      Returns:
      target, which contains appended elements as a result of the collect transformation
      See Also:
    • collectWith

      public <P, A, R extends Collection<A>> R collectWith(Function2<? super E,? super P,? extends A> function, P parameter, R target)
      Description copied from interface: RichIterable
      Same as collectWith but with a targetCollection parameter to gather the results.

      Example using a Java 8 lambda expression:

       MutableSet<Integer> integers =
           Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1), Sets.mutable.empty());
       

      Example using an anonymous inner class:

       Function2<Integer, Integer, Integer> addParameterFunction =
           new Function2<Integer, Integer, Integer>()
           {
               public Integer value(final Integer each, final Integer parameter)
               {
                   return each + parameter;
               }
           };
       MutableSet<Integer> integers =
           Lists.mutable.with(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1), Sets.mutable.empty());
       
      Specified by:
      collectWith in interface RichIterable<E>
      Overrides:
      collectWith in class AbstractMutableList<E>
      Parameters:
      function - a Function2 to use as the collect transformation function
      parameter - a parameter to pass in for evaluation of the second argument P in function
      target - the Collection to append to for all elements in this RichIterable that meet select criteria function
      Returns:
      targetCollection, which contains appended elements as a result of the collect transformation
    • anySatisfyWith

      public <P> boolean anySatisfyWith(Predicate2<? super E,? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.
      Specified by:
      anySatisfyWith in interface RichIterable<E>
      Overrides:
      anySatisfyWith in class AbstractMutableList<E>
    • allSatisfy

      public boolean allSatisfy(Predicate<? super E> predicate)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.
      Specified by:
      allSatisfy in interface RichIterable<E>
      Overrides:
      allSatisfy in class AbstractMutableList<E>
    • allSatisfyWith

      public <P> boolean allSatisfyWith(Predicate2<? super E,? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for every element of the collection, or returns false.
      Specified by:
      allSatisfyWith in interface RichIterable<E>
      Overrides:
      allSatisfyWith in class AbstractMutableList<E>
    • noneSatisfy

      public boolean noneSatisfy(Predicate<? super E> predicate)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.
      Specified by:
      noneSatisfy in interface RichIterable<E>
      Overrides:
      noneSatisfy in class AbstractMutableList<E>
    • noneSatisfyWith

      public <P> boolean noneSatisfyWith(Predicate2<? super E,? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.
      Specified by:
      noneSatisfyWith in interface RichIterable<E>
      Overrides:
      noneSatisfyWith in class AbstractMutableList<E>
    • asParallel

      public ParallelListIterable<E> asParallel(ExecutorService executorService, int batchSize)
      Description copied from interface: ListIterable
      Returns a parallel iterable of this ListIterable.
      Specified by:
      asParallel in interface ListIterable<E>
      Overrides:
      asParallel in class AbstractMutableList<E>