Class ImmutableEmptyList<T>

    • Constructor Detail

      • ImmutableEmptyList

        ImmutableEmptyList()
    • Method Detail

      • readResolve

        private java.lang.Object readResolve()
      • 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>
      • contains

        public boolean contains​(java.lang.Object obj)
        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 AbstractRichIterable<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>
      • 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>
        See Also:
        InternalIterable.forEach(Procedure), Iterable.forEach(java.util.function.Consumer)
      • reverseForEach

        public void reverseForEach​(Procedure<? super T> 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<T>
      • reverseForEachWithIndex

        public void reverseForEachWithIndex​(ObjectIntProcedure<? super T> 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<T>
      • forEachWithIndex

        public void forEachWithIndex​(ObjectIntProcedure<? super T> objectIntProcedure)
        Description copied from interface: InternalIterable
        Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

        Example using a Java 8 lambda:

         people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
         

        Example using an anonymous inner class:

         people.forEachWithIndex(new ObjectIntProcedure<Person>()
         {
             public void value(Person person, int index)
             {
                 LOGGER.info("Index: " + index + " person: " + person.getName());
             }
         });
         
        Specified by:
        forEachWithIndex in interface InternalIterable<T>
        Specified by:
        forEachWithIndex in interface OrderedIterable<T>
        Overrides:
        forEachWithIndex in class AbstractImmutableList<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 AbstractImmutableList<T>
      • min

        public T min​(java.util.Comparator<? super T> comparator)
        Description copied from interface: RichIterable
        Returns the minimum element out of this container based on the comparator.
        Specified by:
        min in interface RichIterable<T>
        Overrides:
        min in class AbstractImmutableList<T>
      • max

        public T max​(java.util.Comparator<? super T> comparator)
        Description copied from interface: RichIterable
        Returns the maximum element out of this container based on the comparator.
        Specified by:
        max in interface RichIterable<T>
        Overrides:
        max in class AbstractImmutableList<T>
      • minBy

        public <V extends java.lang.Comparable<? super V>> T minBy​(Function<? super T,​? extends V> function)
        Description copied from interface: RichIterable
        Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.
        Specified by:
        minBy in interface RichIterable<T>
        Overrides:
        minBy in class AbstractImmutableList<T>
      • maxBy

        public <V extends java.lang.Comparable<? super V>> T maxBy​(Function<? super T,​? extends V> function)
        Description copied from interface: RichIterable
        Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.
        Specified by:
        maxBy in interface RichIterable<T>
        Overrides:
        maxBy in class AbstractImmutableList<T>
      • zip

        public <S> ImmutableList<Pair<T,​S>> zip​(java.lang.Iterable<S> that)
        Description copied from interface: RichIterable
        Returns a RichIterable formed from this RichIterable and another RichIterable by combining corresponding elements in pairs. If one of the two RichIterables is longer than the other, its remaining elements are ignored.
        Specified by:
        zip in interface ImmutableCollection<T>
        Specified by:
        zip in interface ImmutableList<T>
        Specified by:
        zip in interface ListIterable<T>
        Specified by:
        zip in interface OrderedIterable<T>
        Specified by:
        zip in interface ReversibleIterable<T>
        Specified by:
        zip in interface RichIterable<T>
        Overrides:
        zip in class AbstractImmutableList<T>
        Type Parameters:
        S - the type of the second half of the returned pairs
        Parameters:
        that - The RichIterable providing the second half of each result pair
        Returns:
        A new RichIterable containing pairs consisting of corresponding elements of this RichIterable and that. The length of the returned RichIterable is the minimum of the lengths of this RichIterable and that.
      • select

        public ImmutableList<T> select​(Predicate<? super T> predicate)
        Description copied from interface: RichIterable
        Returns all elements of the source collection that return true when evaluating the predicate. This method is also commonly called filter.

        Example using a Java 8 lambda expression:

         RichIterable<Person> selected =
             people.select(person -> person.getAddress().getCity().equals("London"));
         

        Example using an anonymous inner class:

         RichIterable<Person> selected =
             people.select(new Predicate<Person>()
             {
                 public boolean accept(Person person)
                 {
                     return person.getAddress().getCity().equals("London");
                 }
             });
         
        Specified by:
        select in interface ImmutableCollection<T>
        Specified by:
        select in interface ImmutableList<T>
        Specified by:
        select in interface ListIterable<T>
        Specified by:
        select in interface OrderedIterable<T>
        Specified by:
        select in interface ReversibleIterable<T>
        Specified by:
        select in interface RichIterable<T>
        Overrides:
        select in class AbstractImmutableList<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 AbstractImmutableList<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)
      • reject

        public ImmutableList<T> reject​(Predicate<? super T> predicate)
        Description copied from interface: RichIterable
        Returns all elements of the source collection that return false when evaluating of the predicate. This method is also sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).

        Example using a Java 8 lambda expression:

         RichIterable<Person> rejected =
             people.reject(person -> person.person.getLastName().equals("Smith"));
         

        Example using an anonymous inner class:

         RichIterable<Person> rejected =
             people.reject(new Predicate<Person>()
             {
                 public boolean accept(Person person)
                 {
                     return person.person.getLastName().equals("Smith");
                 }
             });
         
        Specified by:
        reject in interface ImmutableCollection<T>
        Specified by:
        reject in interface ImmutableList<T>
        Specified by:
        reject in interface ListIterable<T>
        Specified by:
        reject in interface OrderedIterable<T>
        Specified by:
        reject in interface ReversibleIterable<T>
        Specified by:
        reject in interface RichIterable<T>
        Overrides:
        reject in class AbstractImmutableList<T>
        Parameters:
        predicate - a Predicate to use as the reject criteria
        Returns:
        a RichIterable that contains elements that cause Predicate.accept(Object) method to evaluate to false
      • 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 AbstractImmutableList<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)
      • collect

        public <V> ImmutableList<V> collect​(Function<? super T,​? extends V> function)
        Description copied from interface: RichIterable
        Returns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

        Example using a Java 8 lambda expression:

         RichIterable<String> names =
             people.collect(person -> person.getFirstName() + " " + person.getLastName());
         

        Example using an anonymous inner class:

         RichIterable<String> names =
             people.collect(new Function<Person, String>()
             {
                 public String valueOf(Person person)
                 {
                     return person.getFirstName() + " " + person.getLastName();
                 }
             });
         
        Specified by:
        collect in interface ImmutableCollection<T>
        Specified by:
        collect in interface ImmutableList<T>
        Specified by:
        collect in interface ListIterable<T>
        Specified by:
        collect in interface OrderedIterable<T>
        Specified by:
        collect in interface ReversibleIterable<T>
        Specified by:
        collect in interface RichIterable<T>
        Overrides:
        collect in class AbstractImmutableList<T>
      • collectIf

        public <V> ImmutableList<V> collectIf​(Predicate<? super T> predicate,
                                              Function<? super T,​? extends V> function)
        Description copied from interface: RichIterable
        Returns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate. This is the optimized equivalent of calling iterable.select(predicate).collect(function).

        Example using a Java 8 lambda and method reference:

         RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(e -> e != null, Object::toString);
         

        Example using Predicates factory:

         RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString());
         
        Specified by:
        collectIf in interface ImmutableCollection<T>
        Specified by:
        collectIf in interface ImmutableList<T>
        Specified by:
        collectIf in interface ListIterable<T>
        Specified by:
        collectIf in interface OrderedIterable<T>
        Specified by:
        collectIf in interface ReversibleIterable<T>
        Specified by:
        collectIf in interface RichIterable<T>
        Overrides:
        collectIf in class AbstractImmutableList<T>
      • collectWith

        public <P,​V,​R extends java.util.Collection<V>> R collectWith​(Function2<? super T,​? super P,​? extends V> 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 AbstractImmutableList<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
      • flatCollect

        public <V> ImmutableList<V> flatCollect​(Function<? super T,​? extends java.lang.Iterable<V>> function)
        Description copied from interface: RichIterable
        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);
         
        Specified by:
        flatCollect in interface ImmutableCollection<T>
        Specified by:
        flatCollect in interface ImmutableList<T>
        Specified by:
        flatCollect in interface ListIterable<T>
        Specified by:
        flatCollect in interface OrderedIterable<T>
        Specified by:
        flatCollect in interface ReversibleIterable<T>
        Specified by:
        flatCollect in interface RichIterable<T>
        Overrides:
        flatCollect in class AbstractImmutableList<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 targetCollection)
        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 AbstractImmutableList<T>
        Parameters:
        function - The Function to apply
        targetCollection - 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)
      • countBy

        public <V,​R extends MutableBagIterable<V>> R countBy​(Function<? super T,​? extends V> function,
                                                                   R target)
        Description copied from interface: RichIterable
        This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.
        Specified by:
        countBy in interface RichIterable<T>
        Since:
        9.0
      • countByWith

        public <V,​P,​R extends MutableBagIterable<V>> R countByWith​(Function2<? super T,​? super P,​? extends V> function,
                                                                               P parameter,
                                                                               R target)
        Description copied from interface: RichIterable
        This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.
        Specified by:
        countByWith in interface RichIterable<T>
        Since:
        9.0
      • countByEach

        public <V,​R extends MutableBagIterable<V>> R countByEach​(Function<? super T,​? extends java.lang.Iterable<V>> function,
                                                                       R target)
        Description copied from interface: RichIterable
        This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.
        Specified by:
        countByEach in interface RichIterable<T>
        Since:
        10.0.0
      • 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 AbstractRichIterable<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 AbstractRichIterable<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 AbstractImmutableList<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 AbstractRichIterable<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 AbstractRichIterable<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 AbstractRichIterable<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 AbstractRichIterable<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 AbstractImmutableList<T>
      • injectInto

        public int injectInto​(int injectedValue,
                              IntObjectToIntFunction<? super T> intObjectToIntFunction)
        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<T>
        Overrides:
        injectInto in class AbstractImmutableList<T>
      • injectInto

        public long injectInto​(long injectedValue,
                               LongObjectToLongFunction<? super T> longObjectToLongFunction)
        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<T>
        Overrides:
        injectInto in class AbstractImmutableList<T>
      • injectInto

        public double injectInto​(double injectedValue,
                                 DoubleObjectToDoubleFunction<? super T> doubleObjectToDoubleFunction)
        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<T>
        Overrides:
        injectInto in class AbstractImmutableList<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 AbstractImmutableList<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 AbstractImmutableList<T>
      • getOnly

        public T getOnly()
        Description copied from interface: RichIterable
        Returns the element if the iterable has exactly one element. Otherwise, throw IllegalStateException.
        Specified by:
        getOnly in interface RichIterable<T>
        Returns:
        an element of an iterable.
      • indexOf

        public int indexOf​(java.lang.Object object)
        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 AbstractImmutableList<T>
        See Also:
        List.indexOf(Object)
      • equals

        public boolean equals​(java.lang.Object otherList)
        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 AbstractImmutableList<T>
      • 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 AbstractImmutableList<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>
      • notEmpty

        public boolean notEmpty()
        Description copied from interface: RichIterable
        The English equivalent of !this.isEmpty()
        Specified by:
        notEmpty in interface RichIterable<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 AbstractRichIterable<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 AbstractRichIterable<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 AbstractRichIterable<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 AbstractRichIterable<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)
      • detectIfNone

        public T detectIfNone​(Predicate<? super T> predicate,
                              Function0<? extends T> function)
        Description copied from interface: RichIterable
        Returns the first element of the iterable for which the predicate evaluates to true. If no element matches the predicate, then returns the value of applying the specified function.
        Specified by:
        detectIfNone in interface RichIterable<T>
      • toString

        public java.lang.String toString()
        Description copied from class: AbstractRichIterable
        Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.
         Assert.assertEquals("[]", Lists.mutable.empty().toString());
         Assert.assertEquals("[1]", Lists.mutable.with(1).toString());
         Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());
         
        Specified by:
        toString in interface RichIterable<T>
        Overrides:
        toString in class AbstractRichIterable<T>
        Returns:
        a string representation of this collection.
        See Also:
        AbstractCollection.toString()
      • makeString

        public java.lang.String makeString()
        Description copied from interface: RichIterable
        Returns a string representation of this collection by delegating to RichIterable.makeString(String) and defaulting the separator parameter to the characters ", " (comma and space).
        Specified by:
        makeString in interface RichIterable<T>
        Returns:
        a string representation of this collection.
      • makeString

        public java.lang.String makeString​(java.lang.String separator)
        Description copied from interface: RichIterable
        Returns a string representation of this collection by delegating to RichIterable.makeString(String, String, String) and defaulting the start and end parameters to "" (the empty String).
        Specified by:
        makeString in interface RichIterable<T>
        Returns:
        a string representation of this collection.
      • makeString

        public java.lang.String makeString​(java.lang.String start,
                                           java.lang.String separator,
                                           java.lang.String end)
        Description copied from interface: RichIterable
        Returns a string representation of this collection with the elements separated by the specified separator and enclosed between the start and end strings.
        Specified by:
        makeString in interface RichIterable<T>
        Returns:
        a string representation of this collection.
      • appendString

        public void appendString​(java.lang.Appendable appendable)
        Description copied from interface: RichIterable
        Prints a string representation of this collection onto the given Appendable. Prints the string returned by RichIterable.makeString().
        Specified by:
        appendString in interface RichIterable<T>