Top Description Fields Constructors Methods
org.eclipse.collections.impl.collection.mutable

public final Class CollectionAdapter<T>

extends AbstractCollectionAdapter<T>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.ArrayList, .Collection, .List, .Objects, .RandomAccess, .Set, org.eclipse.collections.api.collection.ImmutableCollection, .MutableCollection, org.eclipse.collections.api.factory.Lists, .Sets, org.eclipse.collections.api.list.MutableList, org.eclipse.collections.api.set.MutableSet, org.eclipse.collections.impl.block.procedure.CollectionAddProcedure, .CollectionRemoveProcedure, org.eclipse.collections.impl.list.mutable.ArrayListAdapter, .FastList, .ListAdapter, .RandomAccessListAdapter, org.eclipse.collections.impl.set.mutable.SetAdapter, .UnifiedSet, org.eclipse.collections.impl.utility.ArrayIterate, .Iterate

This class provides a MutableCollection interface wrapper around a JDK Collections Collection interface instance. All the MutableCollection interface methods are supported in addition to the JDK Collection interface methods.

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.

Field Summary

Modifier and TypeField and Description
private final Collection<T>
private static final long

Constructor Summary

AccessConstructor and Description
public
CollectionAdapter(Collection<T> newDelegate)

Method Summary

Modifier and TypeMethod and Description
public static <E> MutableCollection<E>
adapt(Collection<E> collection)

public MutableCollection<T>
asSynchronized()

Implements org.eclipse.collections.api.collection.MutableCollection.asSynchronized.

Returns a synchronized wrapper backed by this collection.

public MutableCollection<T>
asUnmodifiable()

Implements org.eclipse.collections.api.collection.MutableCollection.asUnmodifiable.

Returns an unmodifiable view of this collection.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Implements java.util.Collection.equals.

Compares the specified object with this collection for equality.

protected Collection<T>
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Collection.hashCode.

Returns the hash code value for this collection.

public MutableCollection<T>
newEmpty()

Implements org.eclipse.collections.api.collection.MutableCollection.newEmpty.

Deprecated use FastList#newList() or UnifiedSet#newSet() instead

Creates a new empty mutable version of the same collection type.

public ImmutableCollection<T>
toImmutable()

Implements org.eclipse.collections.api.collection.MutableCollection.toImmutable.

Converts this MutableCollection to an ImmutableCollection.

public CollectionAdapter<T>
with(T... elements)

Implements org.eclipse.collections.api.collection.MutableCollection.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements.

public CollectionAdapter<T>
with(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements.

public CollectionAdapter<T>
withAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withAll.

This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements.

public CollectionAdapter<T>
without(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.without.

This method allows mutable and fixed size collections the ability to remove elements from their existing elements.

public CollectionAdapter<T>
withoutAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withoutAll.

This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements.

public static <E> MutableList<E>
wrapList(Iterable<E> iterable)

public static <E> MutableSet<E>
wrapSet(Iterable<E> iterable)

Inherited from org.eclipse.collections.impl.collection.mutable.AbstractCollectionAdapter:
addaddAlladdAllIterableallSatisfyallSatisfyWithanySatisfyanySatisfyWithappendStringasLazychunkclearcollectcollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIfcollectIntcollectLongcollectShortcollectWithcollectWithcontainscontainsAllcontainsAllArgumentscontainsAllIterablecountcountWithdetectdetectIfNonedetectOptionaldetectWithdetectWithIfNonedetectWithOptionaleachflatCollectflatCollectforEachWithforEachWithIndexgetFirstgetLastgetOnlygroupBygroupBygroupByEachgroupByEachgroupByUniqueKeygroupByUniqueKeyinjectIntoinjectIntoinjectIntoinjectIntoinjectIntoinjectIntoWithintoisEmptyiteratormaxmaxmaxByminminminBynoneSatisfynoneSatisfyWithnotEmptypartitionpartitionWithrejectrejectrejectWithrejectWithremoveremoveAllremoveAllIterableremoveIfremoveIfWithretainAllretainAllIterableselectselectselectAndRejectWithselectInstancesOfselectWithselectWithsizesumByDoublesumByFloatsumByIntsumByLongsumOfDoublesumOfFloatsumOfIntsumOfLongtaptoArraytoArraytoBagtoBiMaptoListtoMaptoMaptoSettoSortedBagtoSortedBagtoSortedListtoSortedMaptoSortedMaptoSortedSettoSortedSettoStringwrapzipzipzipWithIndexzipWithIndex

Field Detail

delegateback to summary
private final Collection<T> delegate
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

CollectionAdapterback to summary
public CollectionAdapter(Collection<T> newDelegate)

Method Detail

adaptback to summary
public static <E> MutableCollection<E> adapt(Collection<E> collection)
asSynchronizedback to summary
public MutableCollection<T> asSynchronized()

Implements org.eclipse.collections.api.collection.MutableCollection.asSynchronized.

Doc from org.eclipse.collections.api.collection.MutableCollection.asSynchronized.

Returns a synchronized wrapper backed by this collection. This is the equivalent of using 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.

Annotations
@Override
asUnmodifiableback to summary
public MutableCollection<T> asUnmodifiable()

Implements org.eclipse.collections.api.collection.MutableCollection.asUnmodifiable.

Doc from org.eclipse.collections.api.collection.MutableCollection.asUnmodifiable.

Returns an unmodifiable view of this collection. This is the equivalent of using 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.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements java.util.Collection.equals.

Doc from java.util.Collection.equals.

Compares the specified object with this collection for equality.

While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementor may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)

The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)

Annotations
@Override
getDelegateback to summary
protected Collection<T> getDelegate()

Implements abstract org.eclipse.collections.impl.collection.mutable.AbstractCollectionAdapter.getDelegate.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Collection.hashCode.

Doc from java.util.Collection.hashCode.

Returns the hash code value for this collection. While the Collection interface adds no stipulations to the general contract for the Object.hashCode method, programmers should take note that any class that overrides the Object.equals method must also override the Object.hashCode method in order to satisfy the general contract for the Object.hashCode method. In particular, c1.equals(c2) implies that c1.hashCode()==c2.hashCode().

Annotations
@Override
newEmptyback to summary
public MutableCollection<T> newEmpty()

Implements org.eclipse.collections.api.collection.MutableCollection.newEmpty.

Doc from org.eclipse.collections.api.collection.MutableCollection.newEmpty.

Deprecated

use FastList#newList() or UnifiedSet#newSet() instead

Creates a new empty mutable version of the same collection type. For example, if this instance is a FastList, this method will return a new empty FastList. If the class of this instance is immutable or fixed size (i.e. SingletonList) then a mutable alternative to the class will be provided.

Annotations
@Override
@Deprecated
toImmutableback to summary
public ImmutableCollection<T> toImmutable()

Implements org.eclipse.collections.api.collection.MutableCollection.toImmutable.

Doc from org.eclipse.collections.api.collection.MutableCollection.toImmutable.

Converts this MutableCollection to an ImmutableCollection.

Annotations
@Override
withback to summary
public CollectionAdapter<T> with(T... elements)

Implements org.eclipse.collections.api.collection.MutableCollection.with.

Doc from org.eclipse.collections.api.collection.MutableCollection.with.

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.
withback to summary
public CollectionAdapter<T> with(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.with.

Doc from org.eclipse.collections.api.collection.MutableCollection.with.

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.
Annotations
@Override
withAllback to summary
public CollectionAdapter<T> withAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withAll.

Doc from org.eclipse.collections.api.collection.MutableCollection.withAll.

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.
Annotations
@Override
withoutback to summary
public CollectionAdapter<T> without(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.without.

Doc from org.eclipse.collections.api.collection.MutableCollection.without.

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.
Annotations
@Override
withoutAllback to summary
public CollectionAdapter<T> withoutAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withoutAll.

Doc from org.eclipse.collections.api.collection.MutableCollection.withoutAll.

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.
Annotations
@Override
wrapListback to summary
public static <E> MutableList<E> wrapList(Iterable<E> iterable)
wrapSetback to summary
public static <E> MutableSet<E> wrapSet(Iterable<E> iterable)