Class SynchronizedMutableCollection<T>
- java.lang.Object
-
- org.eclipse.collections.impl.collection.AbstractSynchronizedRichIterable<T>
-
- org.eclipse.collections.impl.collection.mutable.AbstractSynchronizedMutableCollection<T>
-
- org.eclipse.collections.impl.collection.mutable.SynchronizedMutableCollection<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<T>,java.util.Collection<T>,MutableCollection<T>,InternalIterable<T>,RichIterable<T>
public class SynchronizedMutableCollection<T> extends AbstractSynchronizedMutableCollection<T> implements java.io.Serializable
A synchronized view of aMutableCollection. It is imperative that the user manually synchronize on the collection when iterating over it using the standard JDK iterator or JDK 5 for loop, as perCollections.synchronizedCollection(Collection).
-
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUID-
Fields inherited from class org.eclipse.collections.impl.collection.AbstractSynchronizedRichIterable
delegate, lock
-
-
Constructor Summary
Constructors Constructor Description SynchronizedMutableCollection(MutableCollection<T> newCollection)SynchronizedMutableCollection(MutableCollection<T> newCollection, java.lang.Object newLock)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MutableCollection<T>asSynchronized()Returns a synchronized wrapper backed by this collection.MutableCollection<T>asUnmodifiable()Returns an unmodifiable view of this collection.MutableCollection<T>newEmpty()Creates a new empty mutable version of the same collection type.static <E,C extends java.util.Collection<E>>
SynchronizedMutableCollection<E>of(C collection)This method will take a MutableCollection and wrap it directly in a SynchronizedMutableCollection.static <E,C extends java.util.Collection<E>>
SynchronizedMutableCollection<E>of(C collection, java.lang.Object lock)This method will take a MutableCollection and wrap it directly in a SynchronizedMutableCollection.ImmutableCollection<T>toImmutable()Converts thisMutableCollectionto anImmutableCollection.MutableCollection<T>with(T element)This method allows mutable and fixed size collections the ability to add elements to their existing elements.MutableCollection<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.MutableCollection<T>without(T element)This method allows mutable and fixed size collections the ability to remove elements from their existing elements.MutableCollection<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.protected java.lang.ObjectwriteReplace()-
Methods inherited from class org.eclipse.collections.impl.collection.mutable.AbstractSynchronizedMutableCollection
add, addAll, addAllIterable, aggregateBy, aggregateInPlaceBy, clear, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, countBy, countByEach, countByWith, flatCollect, getDelegate, groupBy, groupByEach, groupByUniqueKey, injectIntoWith, partition, partitionWith, reject, rejectWith, remove, removeAll, removeAllIterable, removeIf, removeIfWith, retainAll, retainAllIterable, select, selectAndRejectWith, selectInstancesOf, selectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, tap, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.collection.AbstractSynchronizedRichIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, equals, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, forEachWith, forEachWithIndex, getFirst, getLast, getLock, getOnly, groupBy, groupByEach, groupByUniqueKey, hashCode, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, iterator, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduceBy, reject, rejectWith, select, selectWith, size, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableList, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toString, zip, zipWithIndex
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeIf, size, spliterator, stream, toArray
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith, forEachWithIndex
-
Methods inherited from interface org.eclipse.collections.api.collection.MutableCollection
flatCollectWith, toArray, toArray
-
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, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getFirst, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceBy, reduceBy, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, size, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SynchronizedMutableCollection
SynchronizedMutableCollection(MutableCollection<T> newCollection)
-
SynchronizedMutableCollection
SynchronizedMutableCollection(MutableCollection<T> newCollection, java.lang.Object newLock)
-
-
Method Detail
-
of
public static <E,C extends java.util.Collection<E>> SynchronizedMutableCollection<E> of(C collection)
This method will take a MutableCollection and wrap it directly in a SynchronizedMutableCollection. It will take any other non-Eclipse-Collections collection and first adapt it will a CollectionAdapter, and then return a SynchronizedMutableCollection that wraps the adapter.
-
of
public static <E,C extends java.util.Collection<E>> SynchronizedMutableCollection<E> of(C collection, java.lang.Object lock)
This method will take a MutableCollection and wrap it directly in a SynchronizedMutableCollection. It will take any other non-Eclipse-Collections collection and first adapt it will a CollectionAdapter, and then return a SynchronizedMutableCollection that wraps the adapter. Additionally, a developer specifies which lock to use with the collection.
-
writeReplace
protected java.lang.Object writeReplace()
-
with
public MutableCollection<T> with(T element)
Description copied from interface:MutableCollectionThis 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 ofFixedSizeCollectiona 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:
within interfaceMutableCollection<T>- See Also:
Collection.add(Object)
-
without
public MutableCollection<T> without(T element)
Description copied from interface:MutableCollectionThis 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 ofFixedSizeCollectiona 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:
withoutin interfaceMutableCollection<T>- See Also:
Collection.remove(Object)
-
withAll
public MutableCollection<T> withAll(java.lang.Iterable<? extends T> elements)
Description copied from interface:MutableCollectionThis 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 ofFixedSizeCollectiona 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:
withAllin interfaceMutableCollection<T>- See Also:
Collection.addAll(Collection)
-
withoutAll
public MutableCollection<T> withoutAll(java.lang.Iterable<? extends T> elements)
Description copied from interface:MutableCollectionThis 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 ofFixedSizeCollectiona 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:
withoutAllin interfaceMutableCollection<T>- See Also:
Collection.removeAll(Collection)
-
asUnmodifiable
public MutableCollection<T> asUnmodifiable()
Description copied from interface:MutableCollectionReturns an unmodifiable view of this collection. This is the equivalent of usingCollections.unmodifiableCollection(this)with a return type that supports the full iteration protocols available onMutableCollection. Methods which would mutate the underlying collection will throw UnsupportedOperationExceptions.- Specified by:
asUnmodifiablein interfaceMutableCollection<T>- Returns:
- an unmodifiable view of this collection.
- See Also:
Collections.unmodifiableCollection(Collection)
-
asSynchronized
public MutableCollection<T> asSynchronized()
Description copied from interface:MutableCollectionReturns a synchronized wrapper backed by this collection. This is the equivalent of usingCollections.synchronizedCollection(this)only with a return type that supports the full iteration protocols available onMutableCollection. 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.- Specified by:
asSynchronizedin interfaceMutableCollection<T>- Returns:
- a synchronized view of this collection.
- See Also:
Collections.synchronizedCollection(Collection)
-
toImmutable
public ImmutableCollection<T> toImmutable()
Description copied from interface:MutableCollectionConverts thisMutableCollectionto anImmutableCollection.- Specified by:
toImmutablein interfaceMutableCollection<T>
-
newEmpty
public MutableCollection<T> newEmpty()
Description copied from interface:MutableCollectionCreates 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.- Specified by:
newEmptyin interfaceMutableCollection<T>
-
-