public final class CollectionAdapter<T> extends AbstractCollectionAdapter<T> implements java.io.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(java.util.Collection<T> newDelegate) |
| Modifier and Type | Method and Description |
|---|---|
static <E> com.gs.collections.api.collection.MutableCollection<E> |
adapt(java.util.Collection<E> collection) |
com.gs.collections.api.collection.MutableCollection<T> |
asSynchronized()
Returns a synchronized (thread-safe) collection backed by this collection.
|
com.gs.collections.api.collection.MutableCollection<T> |
asUnmodifiable()
Returns an unmodifiable view of this collection.
|
boolean |
equals(java.lang.Object o) |
protected java.util.Collection<T> |
getDelegate() |
int |
hashCode() |
com.gs.collections.api.collection.MutableCollection<T> |
newEmpty()
Deprecated.
use
FastList.newList() or UnifiedSet.newSet() instead |
com.gs.collections.api.collection.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(java.lang.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(java.lang.Iterable<? extends T> elements)
This method allows mutable and fixed size collections the ability to remove multiple elements from their existing
elements.
|
static <E> com.gs.collections.api.list.MutableList<E> |
wrapList(java.lang.Iterable<E> iterable) |
static <E> com.gs.collections.api.set.MutableSet<E> |
wrapSet(java.lang.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, wrap, zip, zip, zipWithIndex, zipWithIndexpublic CollectionAdapter(java.util.Collection<T> newDelegate)
protected java.util.Collection<T> getDelegate()
getDelegate in class AbstractCollectionAdapter<T>public com.gs.collections.api.collection.MutableCollection<T> asUnmodifiable()
com.gs.collections.api.collection.MutableCollectionThe 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 com.gs.collections.api.collection.MutableCollection<T>public com.gs.collections.api.collection.MutableCollection<T> asSynchronized()
com.gs.collections.api.collection.MutableCollectionIt 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 com.gs.collections.api.collection.MutableCollection<T>public com.gs.collections.api.collection.ImmutableCollection<T> toImmutable()
com.gs.collections.api.collection.MutableCollectiontoImmutable in interface com.gs.collections.api.collection.MutableCollection<T>public static <E> com.gs.collections.api.set.MutableSet<E> wrapSet(java.lang.Iterable<E> iterable)
public static <E> com.gs.collections.api.list.MutableList<E> wrapList(java.lang.Iterable<E> iterable)
public static <E> com.gs.collections.api.collection.MutableCollection<E> adapt(java.util.Collection<E> collection)
public boolean equals(java.lang.Object o)
equals in interface java.util.Collection<T>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.util.Collection<T>hashCode in class java.lang.Objectpublic CollectionAdapter<T> with(T... elements)
public CollectionAdapter<T> with(T element)
com.gs.collections.api.collection.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 com.gs.collections.api.collection.MutableCollection<T>Collection.add(Object)public CollectionAdapter<T> without(T element)
com.gs.collections.api.collection.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 com.gs.collections.api.collection.MutableCollection<T>Collection.remove(Object)public CollectionAdapter<T> withAll(java.lang.Iterable<? extends T> elements)
com.gs.collections.api.collection.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 com.gs.collections.api.collection.MutableCollection<T>Collection.addAll(Collection)public CollectionAdapter<T> withoutAll(java.lang.Iterable<? extends T> elements)
com.gs.collections.api.collection.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 com.gs.collections.api.collection.MutableCollection<T>Collection.removeAll(Collection)@Deprecated public com.gs.collections.api.collection.MutableCollection<T> newEmpty()
com.gs.collections.api.collection.MutableCollectionnewEmpty in interface com.gs.collections.api.collection.MutableCollection<T>