Class AbstractArrayAdapter<T>

    • Field Detail

      • OBJECTS

        private static final java.lang.Object[] OBJECTS
      • items

        protected T[] items
    • Constructor Detail

      • AbstractArrayAdapter

        protected AbstractArrayAdapter()
        This method must be here so subclasses can be serializable.
      • AbstractArrayAdapter

        protected AbstractArrayAdapter​(T[] newElements)
    • Method Detail

      • 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:
        InternalIterable.forEach(Procedure), Iterable.forEach(java.util.function.Consumer)
      • 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>
      • 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 java.util.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> java.util.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>
      • 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>
      • 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 java.util.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:
        RichIterable.select(Predicate)
      • reject

        public <R extends java.util.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,​R extends java.util.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:
        RichIterable.collect(Function)
      • collectIf

        public <V,​R extends java.util.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:
        RichIterable.collectIf(Predicate, Function)
      • flatCollect

        public <V> MutableList<V> flatCollect​(Function<? super T,​? extends java.lang.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 java.util.Collection<V>> R flatCollect​(Function<? super T,​? extends java.lang.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:
        RichIterable.flatCollect(Function)
      • size

        public int size()
        Description copied from interface: RichIterable
        Returns the number of items in this iterable.
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.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 java.util.Collection<T>
        Specified by:
        isEmpty in interface java.util.List<T>
        Specified by:
        isEmpty in interface RichIterable<T>
        Overrides:
        isEmpty in class AbstractRichIterable<T>
      • contains

        public boolean contains​(java.lang.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 java.util.Collection<T>
        Specified by:
        contains in interface java.util.List<T>
        Specified by:
        contains in interface RichIterable<T>
        Overrides:
        contains in class AbstractMutableList<T>
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in interface java.util.List<T>
        Overrides:
        iterator in class AbstractMutableList<T>
      • toArray

        public java.lang.Object[] toArray()
        Description copied from interface: RichIterable
        Converts this iterable to an array.
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.List<T>
        Specified by:
        toArray in interface RichIterable<T>
        Overrides:
        toArray in class AbstractRichIterable<T>
        See Also:
        Collection.toArray()
      • 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 java.util.Collection<T>
        Specified by:
        toArray in interface java.util.List<T>
        Specified by:
        toArray in interface RichIterable<T>
        Overrides:
        toArray in class AbstractRichIterable<T>
        See Also:
        Collection.toArray(Object[])
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<T>
        Specified by:
        remove in interface java.util.List<T>
        Overrides:
        remove in class AbstractMutableCollection<T>
      • containsAll

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

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

        public boolean removeAll​(java.util.Collection<?> collection)
        Specified by:
        removeAll in interface java.util.Collection<T>
        Specified by:
        removeAll in interface java.util.List<T>
        Overrides:
        removeAll in class AbstractMutableList<T>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> collection)
        Specified by:
        retainAll in interface java.util.Collection<T>
        Specified by:
        retainAll in interface java.util.List<T>
        Overrides:
        retainAll in class AbstractMutableList<T>
      • replaceAll

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

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

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

        public boolean addAll​(int index,
                              java.util.Collection<? extends T> collection)
        Specified by:
        addAll in interface java.util.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 java.util.List<T>
        Specified by:
        get in interface ListIterable<T>
      • add

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

        public T remove​(int index)
        Specified by:
        remove in interface java.util.List<T>
      • indexOf

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

        public int lastIndexOf​(java.lang.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 java.util.List<T>
        Specified by:
        lastIndexOf in interface ListIterable<T>
        Overrides:
        lastIndexOf in class AbstractMutableList<T>
      • equals

        public boolean equals​(java.lang.Object that)
        Description copied from interface: ListIterable
        Follows the same general contract as List.equals(Object).
        Specified by:
        equals in interface java.util.Collection<T>
        Specified by:
        equals in interface java.util.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 java.util.Collection<T>
        Specified by:
        hashCode in interface java.util.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 java.util.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:
        RichIterable.select(Predicate), RichIterable.select(Predicate, Collection)
      • rejectWith

        public <P,​R extends java.util.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:
        RichIterable.reject(Predicate), RichIterable.reject(Predicate, Collection)
      • 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:
        RichIterable.collect(Function)
      • collectWith

        public <P,​A,​R extends java.util.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:
        RichIterable.injectInto(Object, Function2)
      • 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>
      • 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>