Class ArrayAdapter<T>
java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<T>
org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection<T>
org.eclipse.collections.impl.list.mutable.AbstractMutableList<T>
org.eclipse.collections.impl.list.fixed.AbstractArrayAdapter<T>
org.eclipse.collections.impl.list.fixed.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 Summary
Modifier and Type Method Description static <E> ArrayAdapter<E>
adapt(E... array)
ArrayAdapter<T>
clone()
static <E> ArrayAdapter<E>
newArray()
static <E> ArrayAdapter<E>
newArray(Iterable<? extends E> source)
static <E> ArrayAdapter<E>
newArrayWith(E one)
static <E> ArrayAdapter<E>
newArrayWith(E... elements)
static <E> ArrayAdapter<E>
newArrayWith(E one, E two)
static <E> ArrayAdapter<E>
newArrayWith(E one, E two, E three)
static <E> ArrayAdapter<E>
newArrayWith(E one, E two, E three, E four)
static <E> ArrayAdapter<E>
newArrayWith(E one, E two, E three, E four, E five)
static <E> ArrayAdapter<E>
newArrayWith(E one, E two, E three, E four, E five, E six)
static <E> ArrayAdapter<E>
newArrayWith(E one, E two, E three, E four, E five, E six, E seven)
static <E> ArrayAdapter<E>
newArrayWithItem(Iterable<? extends E> iterable, E itemToAdd)
T
set(int index, T element)
ArrayAdapter<T>
sortThis(Comparator<? super T> comparator)
Sorts the internal data structure of this list and returns the list itself as a convenience.Spliterator<T>
spliterator()
FixedSizeList<T>
tap(Procedure<? super T> procedure)
Executes the Procedure for each element in the iterable and returnsthis
.FixedSizeList<T>
toReversed()
Returns a new MutableList in reverse order.ArrayAdapter<T>
with(T value)
This method allows mutable and fixed size collections the ability to add elements to their existing elements.ArrayAdapter<T>
withAll(Iterable<? extends T> elements)
This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements.ArrayAdapter<T>
without(T element)
This method allows mutable and fixed size collections the ability to remove elements from their existing elements.ArrayAdapter<T>
withoutAll(Iterable<? extends T> elements)
This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements.Methods inherited from class org.eclipse.collections.impl.list.fixed.AbstractArrayAdapter
abstractArrayAdapterEquals, add, addAll, addAll, addAllIterable, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, clear, collect, collect, collectIf, collectWith, collectWith, contains, containsAll, corresponds, count, countWith, detect, detectIndex, detectLastIndex, detectOptional, detectWith, detectWithOptional, distinct, distinct, drop, each, equals, flatCollect, flatCollect, forEach, forEachWith, forEachWithIndex, forEachWithIndex, get, getFirst, getLast, hashCode, indexOf, injectInto, injectIntoWith, isEmpty, iterator, lastIndexOf, listIterator, noneSatisfy, noneSatisfyWith, notEmpty, reject, rejectWith, remove, remove, removeAll, removeAllIterable, removeIf, removeIfWith, replaceAll, retainAll, retainAllIterable, select, selectAndRejectWith, selectWith, size, sort, subList, take, toArray, toArray
Methods inherited from class org.eclipse.collections.impl.list.mutable.AbstractMutableList
appendString, asParallel, asReversed, asSynchronized, asUnmodifiable, binarySearch, chunk, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, distinctBy, dropWhile, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, listIterator, max, max, maxBy, min, min, minBy, newEmpty, partition, partitionWhile, partitionWith, selectInstancesOf, sortThisBy, sortThisByBoolean, sortThisByByte, sortThisByChar, sortThisByDouble, sortThisByFloat, sortThisByInt, sortThisByLong, sortThisByShort, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, takeWhile, toSet, toSortedList, toStack, zip, zip, zipWithIndex, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection
add, aggregateInPlaceBy, countBy, countByEach, countByWith, reduce, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
asLazy, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAllArguments, containsAllIterable, detectWithIfNone, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, into, toBag, toBiMap, toList, toMap, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
Methods inherited from interface org.eclipse.collections.api.collection.FixedSizeCollection
add, addAll, addAllIterable, clear, remove, removeAll, removeAllIterable, removeIf, removeIfWith, retainAll, retainAllIterable
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, size, sort, toArray, toArray
Methods inherited from interface org.eclipse.collections.api.list.ListIterable
asParallel, binarySearch, binarySearch, equals, forEachInBoth, get, getFirst, getLast, hashCode, lastIndexOf, listIterator, listIterator
Methods inherited from interface org.eclipse.collections.api.collection.MutableCollection
aggregateBy, aggregateInPlaceBy, countBy, countByEach, countByWith, groupByUniqueKey, injectIntoWith, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from interface org.eclipse.collections.api.list.MutableList
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, collectWithIndex, distinct, distinct, distinctBy, drop, dropWhile, flatCollect, flatCollectWith, groupBy, groupByEach, newEmpty, partition, partitionWhile, partitionWith, reject, rejectWith, reverseThis, select, selectInstancesOf, selectWith, shuffleThis, shuffleThis, sortThis, sortThisBy, sortThisByBoolean, sortThisByByte, sortThisByChar, sortThisByDouble, sortThisByFloat, sortThisByInt, sortThisByLong, sortThisByShort, subList, take, takeWhile, toImmutable, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
collectWithIndex, corresponds, detectIndex, forEach, forEachWithIndex, forEachWithIndex, getFirstOptional, getLastOptional, indexOf, max, min, toStack, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.ordered.ReversibleIterable
asReversed, detectLastIndex, reverseForEach, reverseForEachWithIndex
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsBy, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, makeString, makeString, makeString, max, maxBy, maxByOptional, maxOptional, maxOptional, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, size, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
-
Method Details
-
adapt
-
newArray
-
newArray
-
spliterator
- Specified by:
spliterator
in interfaceCollection<T>
- Specified by:
spliterator
in interfaceIterable<T>
- Specified by:
spliterator
in interfaceList<T>
- Since:
- 8.1
-
newArrayWithItem
-
newArrayWith
-
newArrayWith
-
newArrayWith
-
newArrayWith
-
newArrayWith
-
newArrayWith
-
newArrayWith
public static <E> ArrayAdapter<E> newArrayWith(E one, E two, E three, E four, E five, E six, E seven) -
newArrayWith
-
set
-
with
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 ofFixedSizeCollection
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 interfaceFixedSizeCollection<T>
- Specified by:
with
in interfaceFixedSizeList<T>
- Specified by:
with
in interfaceMutableCollection<T>
- Specified by:
with
in interfaceMutableList<T>
- See Also:
Collection.add(Object)
-
without
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 ofFixedSizeCollection
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 interfaceFixedSizeCollection<T>
- Specified by:
without
in interfaceFixedSizeList<T>
- Specified by:
without
in interfaceMutableCollection<T>
- Specified by:
without
in interfaceMutableList<T>
- See Also:
Collection.remove(Object)
-
withAll
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 ofFixedSizeCollection
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 interfaceFixedSizeCollection<T>
- Specified by:
withAll
in interfaceFixedSizeList<T>
- Specified by:
withAll
in interfaceMutableCollection<T>
- Specified by:
withAll
in interfaceMutableList<T>
- See Also:
Collection.addAll(Collection)
-
withoutAll
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 ofFixedSizeCollection
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 interfaceFixedSizeCollection<T>
- Specified by:
withoutAll
in interfaceFixedSizeList<T>
- Specified by:
withoutAll
in interfaceMutableCollection<T>
- Specified by:
withoutAll
in interfaceMutableList<T>
- See Also:
Collection.removeAll(Collection)
-
clone
- Specified by:
clone
in interfaceMutableList<T>
- Overrides:
clone
in classAbstractMutableList<T>
-
sortThis
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 interfaceMutableList<T>
-
tap
Description copied from interface:RichIterable
Executes the Procedure for each element in the iterable and returnsthis
.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 interfaceFixedSizeCollection<T>
- Specified by:
tap
in interfaceFixedSizeList<T>
- Specified by:
tap
in interfaceListIterable<T>
- Specified by:
tap
in interfaceMutableCollection<T>
- Specified by:
tap
in interfaceMutableList<T>
- Specified by:
tap
in interfaceOrderedIterable<T>
- Specified by:
tap
in interfaceReversibleIterable<T>
- Specified by:
tap
in interfaceRichIterable<T>
- Overrides:
tap
in classAbstractMutableList<T>
- See Also:
RichIterable.each(Procedure)
,RichIterable.forEach(Procedure)
-
toReversed
Description copied from interface:MutableList
Returns a new MutableList in reverse order.- Specified by:
toReversed
in interfaceFixedSizeList<T>
- Specified by:
toReversed
in interfaceListIterable<T>
- Specified by:
toReversed
in interfaceMutableList<T>
- Specified by:
toReversed
in interfaceReversibleIterable<T>
-