public final class CollectionAdapter<T> extends AbstractCollectionAdapter<T> implements Serializable
To create a new instance that wraps a collection with the MutableSet interface, use the wrapSet(Iterable)
factory method. To create a new instance that wraps a collection with the MutableList interface, use the
wrapList(Iterable)
factory method. To wrap a collection with the MutableCollection interface alone, use
the adapt(Collection)
factory method.
Constructor and Description |
---|
CollectionAdapter(Collection<T> newDelegate) |
Modifier and Type | Method and Description |
---|---|
static <E> MutableCollection<E> |
adapt(Collection<E> collection) |
MutableCollection<T> |
asSynchronized()
Returns a synchronized (thread-safe) collection backed by this collection.
|
MutableCollection<T> |
asUnmodifiable()
Returns an unmodifiable view of this collection.
|
boolean |
equals(Object o) |
int |
hashCode() |
MutableCollection<T> |
newEmpty()
Deprecated.
use
FastList.newList() or UnifiedSet.newSet() instead |
ImmutableCollection<T> |
toImmutable()
Converts this MutableCollection to an ImmutableCollection.
|
CollectionAdapter<T> |
with(T... elements) |
CollectionAdapter<T> |
with(T element)
This method allows mutable and fixed size collections the ability to add elements to their existing elements.
|
CollectionAdapter<T> |
withAll(Iterable<? extends T> elements)
This method allows mutable and fixed size collections the ability to add multiple elements to their existing
elements.
|
CollectionAdapter<T> |
without(T element)
This method allows mutable and fixed size collections the ability to remove elements from their existing elements.
|
CollectionAdapter<T> |
withoutAll(Iterable<? extends T> elements)
This method allows mutable and fixed size collections the ability to remove multiple elements from their existing
elements.
|
static <E> MutableList<E> |
wrapList(Iterable<E> iterable) |
static <E> MutableSet<E> |
wrapSet(Iterable<E> iterable) |
add, addAll, addAllIterable, aggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, clear, collect, collect, collectBoolean, collectBoolean, collectByte, collectByte, collectChar, collectChar, collectDouble, collectDouble, collectFloat, collectFloat, collectIf, collectIf, collectInt, collectInt, collectLong, collectLong, collectShort, collectShort, collectWith, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, each, flatCollect, flatCollect, forEach, forEachWith, forEachWithIndex, getFirst, getLast, groupBy, groupBy, groupByEach, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoWith, isEmpty, iterator, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, partition, partitionWith, reject, reject, rejectWith, rejectWith, remove, removeAll, removeAllIterable, removeIf, removeIfWith, retainAll, retainAllIterable, select, select, selectAndRejectWith, selectInstancesOf, selectWith, selectWith, size, sumByDouble, sumByFloat, sumByInt, sumByLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, tap, toArray, toArray, toBag, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zip, zipWithIndex, zipWithIndex
parallelStream, removeIf, spliterator, stream
public CollectionAdapter(Collection<T> newDelegate)
public MutableCollection<T> asUnmodifiable()
MutableCollection
The returned collection does not pass the hashCode and equals operations through to the backing collection, but relies on Object's equals and hashCode methods. This is necessary to preserve the contracts of these operations in the case that the backing collection is a set or a list.
The returned collection will be serializable if this collection is serializable.
asUnmodifiable
in interface MutableCollection<T>
public MutableCollection<T> asSynchronized()
MutableCollection
It is imperative that the user manually synchronize on the returned collection when iterating over it using the standard JDK iterator or JDK 5 for loop.
MutableCollection collection = myCollection.asSynchronized(); ... synchronized(collection) { Iterator i = c.iterator(); // Must be in the synchronized block while (i.hasNext()) foo(i.next()); }Failure to follow this advice may result in non-deterministic behavior.
The preferred way of iterating over a synchronized collection is to use the collection.forEach() method which is properly synchronized internally.
MutableCollection collection = myCollection.asSynchronized(); ... collection.forEach(new Procedure() { public void value(Object each) { ... } });
The returned collection does not pass the hashCode and equals operations through to the backing collection, but relies on Object's equals and hashCode methods. This is necessary to preserve the contracts of these operations in the case that the backing collection is a set or a list.
The returned collection will be serializable if this collection is serializable.
asSynchronized
in interface MutableCollection<T>
public ImmutableCollection<T> toImmutable()
MutableCollection
toImmutable
in interface MutableCollection<T>
public static <E> MutableSet<E> wrapSet(Iterable<E> iterable)
public static <E> MutableList<E> wrapList(Iterable<E> iterable)
public static <E> MutableCollection<E> adapt(Collection<E> collection)
public boolean equals(Object o)
equals
in interface Collection<T>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<T>
hashCode
in class Object
public CollectionAdapter<T> with(T... elements)
public CollectionAdapter<T> with(T element)
MutableCollection
MutableCollectionIn the case oflist; list = list.with("1"); list = list.with("2"); return list;
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.with
in interface MutableCollection<T>
Collection.add(Object)
public CollectionAdapter<T> without(T element)
MutableCollection
MutableCollectionIn the case oflist; list = list.without("1"); list = list.without("2"); return list;
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.without
in interface MutableCollection<T>
Collection.remove(Object)
public CollectionAdapter<T> withAll(Iterable<? extends T> elements)
MutableCollection
MutableCollectionIn the case oflist; list = list.withAll(FastList.newListWith("1", "2")); return list;
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.withAll
in interface MutableCollection<T>
Collection.addAll(Collection)
public CollectionAdapter<T> withoutAll(Iterable<? extends T> elements)
MutableCollection
MutableCollectionIn the case oflist; list = list.withoutAll(FastList.newListWith("1", "2")); return list;
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.withoutAll
in interface MutableCollection<T>
Collection.removeAll(Collection)
@Deprecated public MutableCollection<T> newEmpty()
FastList.newList()
or UnifiedSet.newSet()
insteadMutableCollection
newEmpty
in interface MutableCollection<T>
Copyright © 2004–2016. All rights reserved.