Class AbstractArrayAdapter<T>

All Implemented Interfaces:
Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess, MutableCollection<T>, InternalIterable<T>, ListIterable<T>, MutableList<T>, OrderedIterable<T>, ReversibleIterable<T>, RichIterable<T>
Direct Known Subclasses:
ArrayAdapter

public abstract class AbstractArrayAdapter<T> extends AbstractMutableList<T> implements RandomAccess
  • Method Details

    • notEmpty

      public boolean notEmpty()
      Description copied from interface: RichIterable
      The English equivalent of !this.isEmpty()
      Specified by:
      notEmpty in interface RichIterable<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 ListIterable<T>
      Specified by:
      getFirst in interface OrderedIterable<T>
      Specified by:
      getFirst in interface RichIterable<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 ListIterable<T>
      Specified by:
      getLast in interface OrderedIterable<T>
      Specified by:
      getLast in interface RichIterable<T>
      Overrides:
      getLast in class AbstractMutableList<T>
    • 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>
    • forEachWithIndex

      public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure)
      Description copied from interface: OrderedIterable
      Iterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.
      e.g.
       OrderedIterable<People> people = FastList.newListWith(ted, mary, bob, sally)
       people.forEachWithIndex(0, 1, new ObjectIntProcedure<Person>()
       {
           public void value(Person person, int index)
           {
                LOGGER.info(person.getName());
           }
       });
       

      This code would output ted and mary's names.

      Specified by:
      forEachWithIndex in interface OrderedIterable<T>
      Overrides:
      forEachWithIndex in class AbstractMutableList<T>
    • removeIf

      public boolean removeIf(Predicate<? super T> predicate)
      Description copied from interface: MutableCollection
      Removes all elements in the collection that evaluate to true for the specified predicate.
      e.g.
       return lastNames.removeIf(Predicates.isNull());
       
      Specified by:
      removeIf in interface MutableCollection<T>
      Overrides:
      removeIf in class AbstractMutableList<T>
    • removeIfWith

      public <P> boolean removeIfWith(Predicate2<? super T,? super P> predicate, P parameter)
      Description copied from interface: MutableCollection
      Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.
       return lastNames.removeIfWith(Predicates2.isNull(), null);
       
      Specified by:
      removeIfWith in interface MutableCollection<T>
      Overrides:
      removeIfWith in class AbstractMutableList<T>
    • detect

      public T detect(Predicate<? super T> predicate)
      Description copied from interface: RichIterable
      Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.

      Example using a Java 8 lambda expression:

       Person person =
           people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
       

      Example using an anonymous inner class:

       Person person =
           people.detect(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.getFirstName().equals("John") && person.getLastName().equals("Smith");
               }
           });
       
      Specified by:
      detect in interface RichIterable<T>
      Overrides:
      detect in class AbstractMutableList<T>
    • detectWith

      public <P> T detectWith(Predicate2<? super T,? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.

      Example using a Java 8 lambda expression:

       Person person =
           people.detectWith((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
       

      Example using an anonymous inner class:

       Person person =
           people.detectWith(new Predicate2<Person, String>()
           {
               public boolean accept(Person person, String fullName)
               {
                   return person.getFullName().equals(fullName);
               }
           }, "John Smith");
       
      Specified by:
      detectWith in interface RichIterable<T>
      Overrides:
      detectWith in class AbstractMutableList<T>
    • detectOptional

      public Optional<T> detectOptional(Predicate<? super T> predicate)
      Description copied from interface: RichIterable
      Returns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.

      Example using a Java 8 lambda expression:

       Person person =
           people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
       

      Specified by:
      detectOptional in interface RichIterable<T>
      Overrides:
      detectOptional in class AbstractMutableList<T>
    • detectWithOptional

      public <P> Optional<T> detectWithOptional(Predicate2<? super T,? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.

      Example using a Java 8 lambda expression:

       Optional<Person> person =
           people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
       

      Specified by:
      detectWithOptional in interface RichIterable<T>
      Overrides:
      detectWithOptional in class AbstractMutableList<T>
    • detectIndex

      public int detectIndex(Predicate<? super T> predicate)
      Description copied from interface: OrderedIterable
      Returns the index of the first element of the OrderedIterable for which the predicate evaluates to true. Returns -1 if no element evaluates true for the predicate.
      Specified by:
      detectIndex in interface OrderedIterable<T>
      Overrides:
      detectIndex in class AbstractMutableList<T>
    • detectLastIndex

      public int detectLastIndex(Predicate<? super T> predicate)
      Description copied from interface: ReversibleIterable
      Returns the index of the last element of the ReversibleIterable for which the predicate evaluates to true. Returns -1 if no element evaluates true for the predicate.
      Specified by:
      detectLastIndex in interface ReversibleIterable<T>
      Overrides:
      detectLastIndex in class AbstractMutableList<T>
    • count

      public int count(Predicate<? super T> 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<T>
      Overrides:
      count in class AbstractMutableList<T>
    • corresponds

      public <S> boolean corresponds(OrderedIterable<S> other, Predicate2<? super T,? super S> predicate)
      Description copied from interface: OrderedIterable
      Returns true if both OrderedIterables have the same length and predicate returns true for all corresponding elements e1 of this OrderedIterable and e2 of other. The predicate is evaluated for each element at the same position of each OrderedIterable in a forward iteration order. This is a short circuit pattern.
      Specified by:
      corresponds in interface OrderedIterable<T>
      Overrides:
      corresponds in class AbstractMutableList<T>
    • anySatisfy

      public boolean anySatisfy(Predicate<? super T> 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<T>
      Overrides:
      anySatisfy in class AbstractMutableList<T>
    • allSatisfy

      public boolean allSatisfy(Predicate<? super T> 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<T>
      Overrides:
      allSatisfy in class AbstractMutableList<T>
    • noneSatisfy

      public boolean noneSatisfy(Predicate<? super T> 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<T>
      Overrides:
      noneSatisfy in class AbstractMutableList<T>
    • injectInto

      public <IV> IV injectInto(IV injectedValue, Function2<? super IV,? super T,? 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<T>
      Overrides:
      injectInto in class AbstractMutableList<T>
    • select

      public <R extends Collection<T>> R select(Predicate<? super T> 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<T>
      Overrides:
      select in class AbstractMutableList<T>
      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:
    • reject

      public <R extends Collection<T>> R reject(Predicate<? super T> 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<T>
      Overrides:
      reject in class AbstractMutableList<T>
      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
    • collect

      public <V> MutableList<V> collect(Function<? super T,? extends V> function)
      Description copied from interface: MutableCollection
      Returns a new MutableCollection with the results of applying the specified function to each element of the source collection.
       MutableCollection<String> names =
           people.collect(person -> person.getFirstName() + " " + person.getLastName());
       
      Specified by:
      collect in interface ListIterable<T>
      Specified by:
      collect in interface MutableCollection<T>
      Specified by:
      collect in interface MutableList<T>
      Specified by:
      collect in interface OrderedIterable<T>
      Specified by:
      collect in interface ReversibleIterable<T>
      Specified by:
      collect in interface RichIterable<T>
    • collect

      public <V, R extends Collection<V>> R collect(Function<? super T,? 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<T>
      Overrides:
      collect in class AbstractMutableList<T>
      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:
    • collectIf

      public <V, R extends Collection<V>> R collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function, R target)
      Description copied from interface: RichIterable
      Same as the collectIf method with two parameters but uses the specified target collection for the results.
      Specified by:
      collectIf in interface RichIterable<T>
      Overrides:
      collectIf in class AbstractMutableList<T>
      Parameters:
      predicate - a Predicate to use as the select criteria
      function - a Function to use as the collect transformation function
      target - the Collection to append to for all elements in this RichIterable that meet the collect criteria predicate
      Returns:
      targetCollection, which contains appended elements as a result of the collect criteria and transformation
      See Also:
    • flatCollect

      public <V> MutableList<V> flatCollect(Function<? super T,? extends Iterable<V>> function)
      Description copied from interface: MutableCollection
      flatCollect is a special case of RichIterable.collect(Function). With collect, when the Function returns a collection, the result is a collection of collections. flatCollect outputs a single "flattened" collection instead. This method is commonly called flatMap.

      Consider the following example where we have a Person class, and each Person has a list of Address objects. Take the following Function:

       Function<Person, List<Address>> addressFunction = Person::getAddresses;
       RichIterable<Person> people = ...;
       
      Using collect returns a collection of collections of addresses.
       RichIterable<List<Address>> addresses = people.collect(addressFunction);
       
      Using flatCollect returns a single flattened list of addresses.
       RichIterable<Address> addresses = people.flatCollect(addressFunction);
       
      Co-variant example for MutableCollection:
       Function<Person, List<Address>> addressFunction = Person::getAddresses;
       MutableCollection<Person> people = ...;
       MutableCollection<List<Address>> addresses = people.collect(addressFunction);
       MutableCollection<Address> addresses = people.flatCollect(addressFunction);
       
      Specified by:
      flatCollect in interface ListIterable<T>
      Specified by:
      flatCollect in interface MutableCollection<T>
      Specified by:
      flatCollect in interface MutableList<T>
      Specified by:
      flatCollect in interface OrderedIterable<T>
      Specified by:
      flatCollect in interface ReversibleIterable<T>
      Specified by:
      flatCollect in interface RichIterable<T>
      Parameters:
      function - The Function to apply
      Returns:
      a new flattened collection produced by applying the given function
    • flatCollect

      public <V, R extends Collection<V>> R flatCollect(Function<? super T,? extends Iterable<V>> function, R target)
      Description copied from interface: RichIterable
      Same as flatCollect, only the results are collected into the target collection.
      Specified by:
      flatCollect in interface RichIterable<T>
      Overrides:
      flatCollect in class AbstractMutableList<T>
      Parameters:
      function - The Function to apply
      target - The collection into which results should be added.
      Returns:
      target, which will contain a flattened collection of results produced by applying the given function
      See Also:
    • selectAndRejectWith

      public <P> Twin<MutableList<T>> selectAndRejectWith(Predicate2<? super T,? super P> predicate, P parameter)
      Description copied from interface: MutableCollection
      Filters a collection into two separate collections based on a predicate returned via a Pair.
      e.g.
       return lastNames.selectAndRejectWith(Predicates2.lessThan(), "Mason");
       
      Specified by:
      selectAndRejectWith in interface MutableCollection<T>
      Overrides:
      selectAndRejectWith in class AbstractMutableList<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>
    • isEmpty

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

      public boolean contains(Object o)
      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>
    • 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>
    • toArray

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

      public <E> E[] toArray(E[] 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<T>
      Specified by:
      toArray in interface List<T>
      Specified by:
      toArray in interface RichIterable<T>
      Overrides:
      toArray in class AbstractRichIterable<T>
      See Also:
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class AbstractMutableCollection<T>
    • 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<T>
      Specified by:
      containsAll in interface List<T>
      Specified by:
      containsAll in interface RichIterable<T>
      Overrides:
      containsAll in class AbstractMutableList<T>
      See Also:
    • 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>
    • addAllIterable

      public boolean addAllIterable(Iterable<? extends T> iterable)
      Specified by:
      addAllIterable in interface MutableCollection<T>
      Overrides:
      addAllIterable in class AbstractMutableCollection<T>
      See Also:
    • removeAll

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

      public boolean removeAllIterable(Iterable<?> iterable)
      Specified by:
      removeAllIterable in interface MutableCollection<T>
      Overrides:
      removeAllIterable in class AbstractMutableCollection<T>
      See Also:
    • retainAll

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

      public boolean retainAllIterable(Iterable<?> iterable)
      Specified by:
      retainAllIterable in interface MutableCollection<T>
      Overrides:
      retainAllIterable in class AbstractMutableCollection<T>
      See Also:
    • replaceAll

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

      public void sort(Comparator<? super T> comparator)
      Specified by:
      sort in interface List<T>
      Since:
      10.0
    • clear

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

      public boolean addAll(int index, Collection<? extends T> collection)
      Specified by:
      addAll 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>
    • 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>
    • indexOf

      public int indexOf(Object item)
      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<T>
      Specified by:
      indexOf in interface OrderedIterable<T>
      Overrides:
      indexOf in class AbstractMutableList<T>
      See Also:
    • lastIndexOf

      public int lastIndexOf(Object item)
      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<T>
      Specified by:
      lastIndexOf in interface ListIterable<T>
      Overrides:
      lastIndexOf 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:
    • equals

      public boolean equals(Object that)
      Description copied from interface: ListIterable
      Follows the same general contract as List.equals(Object).
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface List<T>
      Specified by:
      equals in interface ListIterable<T>
      Overrides:
      equals in class AbstractMutableList<T>
    • abstractArrayAdapterEquals

      public boolean abstractArrayAdapterEquals(AbstractArrayAdapter<?> list)
    • hashCode

      public int hashCode()
      Description copied from interface: ListIterable
      Follows the same general contract as List.hashCode().
      Specified by:
      hashCode in interface Collection<T>
      Specified by:
      hashCode in interface List<T>
      Specified by:
      hashCode in interface ListIterable<T>
      Overrides:
      hashCode 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>
    • selectWith

      public <P, R extends Collection<T>> R selectWith(Predicate2<? super T,? 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<T>
      Overrides:
      selectWith in class AbstractMutableList<T>
      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:
    • rejectWith

      public <P, R extends Collection<T>> R rejectWith(Predicate2<? super T,? 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<T>
      Overrides:
      rejectWith in class AbstractMutableList<T>
      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:
    • collectWith

      public <P, A> MutableList<A> collectWith(Function2<? super T,? super P,? extends A> function, P parameter)
      Description copied from interface: MutableCollection
      Same as RichIterable.collect(Function) with a Function2 and specified parameter which is passed to the block.

      Example using a Java 8 lambda expression:

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

      Example using an anonymous inner class:

       Function2<Integer, Integer, Integer> addParameterFunction =
           new Function2<Integer, Integer, Integer>()
           {
               public Integer value(Integer each, Integer parameter)
               {
                   return each + parameter;
               }
           };
       RichIterable<Integer> integers =
           Lists.mutable.with(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1));
       
      Co-variant example for MutableCollection:
       MutableCollection<Integer> integers =
           Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));
       
      Specified by:
      collectWith in interface ListIterable<T>
      Specified by:
      collectWith in interface MutableCollection<T>
      Specified by:
      collectWith in interface MutableList<T>
      Specified by:
      collectWith in interface OrderedIterable<T>
      Specified by:
      collectWith in interface ReversibleIterable<T>
      Specified by:
      collectWith in interface RichIterable<T>
      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
      Returns:
      A new RichIterable that contains the transformed elements returned by Function2.value(Object, Object)
      See Also:
    • collectWith

      public <P, A, R extends Collection<A>> R collectWith(Function2<? super T,? 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<T>
      Overrides:
      collectWith in class AbstractMutableList<T>
      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
    • injectIntoWith

      public <IV, P> IV injectIntoWith(IV injectValue, Function3<? super IV,? super T,? super P,? extends IV> function, P parameter)
      Description copied from interface: MutableCollection
      Returns the final result of evaluating function using each element of the iterable, the previous evaluation result and 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. The parameter value is always used as the third parameter to the function call.
      Specified by:
      injectIntoWith in interface MutableCollection<T>
      Overrides:
      injectIntoWith in class AbstractMutableList<T>
      See Also:
    • forEach

      public void forEach(int fromIndex, int toIndex, Procedure<? super T> procedure)
      Description copied from interface: OrderedIterable
      Iterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.
      e.g.
       OrderedIterable<People> people = FastList.newListWith(ted, mary, bob, sally)
       people.forEach(0, 1, new Procedure<Person>()
       {
           public void value(Person person)
           {
                LOGGER.info(person.getName());
           }
       });
       

      This code would output ted and mary's names.

      Specified by:
      forEach in interface OrderedIterable<T>
      Overrides:
      forEach in class AbstractMutableList<T>
    • countWith

      public <P> int countWith(Predicate2<? super T,? 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<T>
      Overrides:
      countWith in class AbstractMutableList<T>
    • anySatisfyWith

      public <P> boolean anySatisfyWith(Predicate2<? super T,? 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<T>
      Overrides:
      anySatisfyWith in class AbstractMutableList<T>
    • allSatisfyWith

      public <P> boolean allSatisfyWith(Predicate2<? super T,? 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<T>
      Overrides:
      allSatisfyWith in class AbstractMutableList<T>
    • noneSatisfyWith

      public <P> boolean noneSatisfyWith(Predicate2<? super T,? 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<T>
      Overrides:
      noneSatisfyWith in class AbstractMutableList<T>
    • distinct

      public MutableList<T> distinct()
      Description copied from interface: MutableList
      Returns a new ListIterable containing the distinct elements in this list.
      Specified by:
      distinct in interface ListIterable<T>
      Specified by:
      distinct in interface MutableList<T>
      Specified by:
      distinct in interface OrderedIterable<T>
      Specified by:
      distinct in interface ReversibleIterable<T>
      Overrides:
      distinct in class AbstractMutableList<T>
      Returns:
      ListIterable of distinct elements
    • distinct

      public MutableList<T> distinct(HashingStrategy<? super T> hashingStrategy)
      Description copied from interface: MutableList
      Returns a new ListIterable containing the distinct elements in this list. Takes HashingStrategy.
      Specified by:
      distinct in interface ListIterable<T>
      Specified by:
      distinct in interface MutableList<T>
      Overrides:
      distinct in class AbstractMutableList<T>
      Returns:
      ListIterable of distinct elements
    • appendString

      public void appendString(Appendable appendable, String start, String separator, String end)
      Description copied from interface: RichIterable
      Prints a string representation of this collection onto the given Appendable. Prints the string returned by RichIterable.makeString(String, String, String).
      Specified by:
      appendString in interface RichIterable<T>
      Overrides:
      appendString in class AbstractMutableList<T>
    • take

      public MutableList<T> take(int count)
      Description copied from interface: ReversibleIterable
      Returns the first count elements of the iterable or all the elements in the iterable if count is greater than the length of the iterable.
      Specified by:
      take in interface ListIterable<T>
      Specified by:
      take in interface MutableList<T>
      Specified by:
      take in interface ReversibleIterable<T>
      Overrides:
      take in class AbstractMutableList<T>
      Parameters:
      count - the number of items to take.
    • drop

      public MutableList<T> drop(int count)
      Description copied from interface: ReversibleIterable
      Returns an iterable after skipping the first count elements or an empty iterable if the count is greater than the length of the iterable.
      Specified by:
      drop in interface ListIterable<T>
      Specified by:
      drop in interface MutableList<T>
      Specified by:
      drop in interface ReversibleIterable<T>
      Overrides:
      drop in class AbstractMutableList<T>
      Parameters:
      count - the number of items to drop.