Class ArrayAdapter<T>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess, FixedSizeCollection<T>, MutableCollection<T>, InternalIterable<T>, FixedSizeList<T>, ListIterable<T>, MutableList<T>, OrderedIterable<T>, ReversibleIterable<T>, RichIterable<T>

public final class ArrayAdapter<T>
extends AbstractArrayAdapter<T>
implements Serializable, FixedSizeList<T>
This class provides a MutableList wrapper around an array. All of the internal iteration methods of the MutableList interface as well as the JDK Collections List interface are provided. However, the pre-determined fixed-sized semantics of an array are maintained and thus mutating List interface methods such as AbstractMutableCollection.add(Object), AbstractArrayAdapter.addAll(Collection), AbstractArrayAdapter.remove(Object), AbstractArrayAdapter.removeAll(Collection), etc. are not supported and will throw an UnsupportedOperationException. In addition, the mutating iteration methods AbstractArrayAdapter.removeIf(org.eclipse.collections.api.block.predicate.Predicate) and AbstractArrayAdapter.removeIfWith(org.eclipse.collections.api.block.predicate.Predicate2, Object) are not supported and will also throw an UnsupportedOperationException.

The with(Object) method is not an exception to the above restrictions, as it will create a new instance of this class with the existing contents plus the new item.

To create a wrapper around an existing array, use the adapt(Object[]) factory method. To wrap the contents of an existing Collection instance, use the newArray(Iterable) or newArrayWithItem(Iterable, Object) factory methods. To wrap existing objects in a new array, use one of the newArrayWith(Object) factory methods.

See Also:
Serialized Form
  • Method Details

    • adapt

      public static <E> ArrayAdapter<E> adapt​(E... array)
    • newArray

      public static <E> ArrayAdapter<E> newArray()
    • newArray

      public static <E> ArrayAdapter<E> newArray​(Iterable<? extends E> source)
    • spliterator

      public Spliterator<T> spliterator()
      Specified by:
      spliterator in interface Collection<T>
      Specified by:
      spliterator in interface Iterable<T>
      Specified by:
      spliterator in interface List<T>
      Since:
      8.1
    • newArrayWithItem

      public static <E> ArrayAdapter<E> newArrayWithItem​(Iterable<? extends E> iterable, E itemToAdd)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E one)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E one, E two)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E one, E two, E three)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E one, E two, E three, E four)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E one, E two, E three, E four, E five)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E one, E two, E three, E four, E five, E six)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E one, E two, E three, E four, E five, E six, E seven)
    • newArrayWith

      public static <E> ArrayAdapter<E> newArrayWith​(E... elements)
    • set

      public T set​(int index, T element)
      Specified by:
      set in interface List<T>
    • with

      public ArrayAdapter<T> with​(T value)
      Description copied from interface: MutableCollection
      This method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:
       MutableCollection<String> list = list.with("1");
       list = list.with("2");
       return list;
       
      In the case of FixedSizeCollection a new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.
      Specified by:
      with in interface FixedSizeCollection<T>
      Specified by:
      with in interface FixedSizeList<T>
      Specified by:
      with in interface MutableCollection<T>
      Specified by:
      with in interface MutableList<T>
      See Also:
      Collection.add(Object)
    • without

      public ArrayAdapter<T> without​(T element)
      Description copied from interface: MutableCollection
      This method allows mutable and fixed size collections the ability to remove elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling remove. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:
       MutableCollection<String> list = list.without("1");
       list = list.without("2");
       return list;
       
      In the case of FixedSizeCollection a new instance of MutableCollection will be returned by without, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling remove on itself.
      Specified by:
      without in interface FixedSizeCollection<T>
      Specified by:
      without in interface FixedSizeList<T>
      Specified by:
      without in interface MutableCollection<T>
      Specified by:
      without in interface MutableList<T>
      See Also:
      Collection.remove(Object)
    • withAll

      public ArrayAdapter<T> withAll​(Iterable<? extends T> elements)
      Description copied from interface: MutableCollection
      This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new elements to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:
       MutableCollection<String> list = list.withAll(FastList.newListWith("1", "2"));
       
      In the case of FixedSizeCollection a new instance of MutableCollection will be returned by withAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling addAll on itself.
      Specified by:
      withAll in interface FixedSizeCollection<T>
      Specified by:
      withAll in interface FixedSizeList<T>
      Specified by:
      withAll in interface MutableCollection<T>
      Specified by:
      withAll in interface MutableList<T>
      See Also:
      Collection.addAll(Collection)
    • withoutAll

      public ArrayAdapter<T> withoutAll​(Iterable<? extends T> elements)
      Description copied from interface: MutableCollection
      This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling removeAll. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:
       MutableCollection<String> list = list.withoutAll(FastList.newListWith("1", "2"));
       
      In the case of FixedSizeCollection a new instance of MutableCollection will be returned by withoutAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling removeAll on itself.
      Specified by:
      withoutAll in interface FixedSizeCollection<T>
      Specified by:
      withoutAll in interface FixedSizeList<T>
      Specified by:
      withoutAll in interface MutableCollection<T>
      Specified by:
      withoutAll in interface MutableList<T>
      See Also:
      Collection.removeAll(Collection)
    • clone

      public ArrayAdapter<T> clone()
      Specified by:
      clone in interface MutableList<T>
      Overrides:
      clone in class AbstractMutableList<T>
    • sortThis

      public ArrayAdapter<T> sortThis​(Comparator<? super T> comparator)
      Description copied from interface: MutableList
      Sorts the internal data structure of this list and returns the list itself as a convenience.
      Specified by:
      sortThis in interface MutableList<T>
    • tap

      public FixedSizeList<T> tap​(Procedure<? super T> procedure)
      Description copied from interface: RichIterable
      Executes the Procedure for each element in the iterable and returns this.

      Example using a Java 8 lambda expression:

       RichIterable<Person> tapped =
           people.tap(person -> LOGGER.info(person.getName()));
       

      Example using an anonymous inner class:

       RichIterable<Person> tapped =
           people.tap(new Procedure<Person>()
           {
               public void value(Person person)
               {
                   LOGGER.info(person.getName());
               }
           });
       
      Specified by:
      tap in interface FixedSizeCollection<T>
      Specified by:
      tap in interface FixedSizeList<T>
      Specified by:
      tap in interface ListIterable<T>
      Specified by:
      tap in interface MutableCollection<T>
      Specified by:
      tap in interface MutableList<T>
      Specified by:
      tap in interface OrderedIterable<T>
      Specified by:
      tap in interface ReversibleIterable<T>
      Specified by:
      tap in interface RichIterable<T>
      Overrides:
      tap in class AbstractMutableList<T>
      See Also:
      RichIterable.each(Procedure), RichIterable.forEach(Procedure)
    • toReversed

      public FixedSizeList<T> toReversed()
      Description copied from interface: MutableList
      Returns a new MutableList in reverse order.
      Specified by:
      toReversed in interface FixedSizeList<T>
      Specified by:
      toReversed in interface ListIterable<T>
      Specified by:
      toReversed in interface MutableList<T>
      Specified by:
      toReversed in interface ReversibleIterable<T>