java.io.Serializable
, java.lang.Iterable<T>
, java.util.Collection<T>
, MutableCollection<T>
, InternalIterable<T>
, RichIterable<T>
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 | Description |
---|---|
CollectionAdapter(java.util.Collection<T> newDelegate) |
Modifier and Type | Method | Description |
---|---|---|
static <E> MutableCollection<E> |
adapt(java.util.Collection<E> collection) |
|
MutableCollection<T> |
asSynchronized() |
Returns a synchronized wrapper backed by this collection.
|
MutableCollection<T> |
asUnmodifiable() |
Returns an unmodifiable view of this collection.
|
boolean |
equals(java.lang.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 element) |
This method allows mutable and fixed size collections the ability to add elements to their existing elements.
|
CollectionAdapter<T> |
with(T... 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> MutableList<E> |
wrapList(java.lang.Iterable<E> iterable) |
|
static <E> MutableSet<E> |
wrapSet(java.lang.Iterable<E> iterable) |
add, addAll, addAllIterable, aggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, 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, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollect, forEach, forEachWith, forEachWithIndex, getFirst, getLast, getOnly, groupBy, groupBy, groupByEach, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoWith, into, isEmpty, iterator, 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, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zip, zipWithIndex, zipWithIndex
forEach
countBy, countByWith
appendString, appendString, countBy, countByWith, makeString, makeString, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, reduce, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toSortedList
public CollectionAdapter(java.util.Collection<T> newDelegate)
public MutableCollection<T> asUnmodifiable()
MutableCollection
Collections.unmodifiableCollection(this)
with a return type that supports the full
iteration protocols available on MutableCollection
. Methods which would
mutate the underlying collection will throw UnsupportedOperationExceptions.asUnmodifiable
in interface MutableCollection<T>
Collections.unmodifiableCollection(Collection)
public MutableCollection<T> asSynchronized()
MutableCollection
Collections.synchronizedCollection(this)
only with a return type that supports the full
iteration protocols available on MutableCollection
.
The preferred way of iterating over a synchronized collection is to use the internal iteration
methods which are properly synchronized internally.
MutableCollection synchedCollection = collection.asSynchronized(); ... synchedCollection.forEach(each -> ... ); synchedCollection.select(each -> ... ); synchedCollection.collect(each -> ... );If you want to iterate using an imperative style, you must protect external iterators using a synchronized block. This includes explicit iterators as well as JDK 5 style for loops.
asSynchronized
in interface MutableCollection<T>
Collections.synchronizedCollection(Collection)
public ImmutableCollection<T> toImmutable()
MutableCollection
MutableCollection
to an ImmutableCollection
.toImmutable
in interface MutableCollection<T>
public static <E> MutableSet<E> wrapSet(java.lang.Iterable<E> iterable)
public static <E> MutableList<E> wrapList(java.lang.Iterable<E> iterable)
public static <E> 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.Object
public int hashCode()
hashCode
in interface java.util.Collection<T>
hashCode
in class java.lang.Object
public CollectionAdapter<T> with(T... elements)
public CollectionAdapter<T> with(T element)
MutableCollection
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.with
in interface MutableCollection<T>
Collection.add(Object)
public CollectionAdapter<T> without(T element)
MutableCollection
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.without
in interface MutableCollection<T>
Collection.remove(Object)
public CollectionAdapter<T> withAll(java.lang.Iterable<? extends T> elements)
MutableCollection
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.withAll
in interface MutableCollection<T>
Collection.addAll(Collection)
public CollectionAdapter<T> withoutAll(java.lang.Iterable<? extends T> elements)
MutableCollection
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.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–2018. All rights reserved.