Class SynchronizedMutableCollection<T>

All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>, MutableCollection<T>, InternalIterable<T>, RichIterable<T>

public class SynchronizedMutableCollection<T>
extends AbstractSynchronizedMutableCollection<T>
implements Serializable
A synchronized view of a MutableCollection. 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 per Collections.synchronizedCollection(Collection).
See Also:
MutableCollection.asSynchronized(), Serialized Form
  • Method Details

    • of

      public static <E,​ C extends 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 Collection<E>> SynchronizedMutableCollection<E> of​(C collection, 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.
    • with

      public MutableCollection<T> with​(T element)
      Description copied from interface: MutableCollection
      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.
      Specified by:
      with in interface MutableCollection<T>
      See Also:
      Collection.add(Object)
    • without

      public MutableCollection<T> without​(T element)
      Description copied from interface: MutableCollection
      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.
      Specified by:
      without in interface MutableCollection<T>
      See Also:
      Collection.remove(Object)
    • withAll

      public MutableCollection<T> withAll​(Iterable<? extends T> elements)
      Description copied from interface: MutableCollection
      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.
      Specified by:
      withAll in interface MutableCollection<T>
      See Also:
      Collection.addAll(Collection)
    • withoutAll

      public MutableCollection<T> withoutAll​(Iterable<? extends T> elements)
      Description copied from interface: MutableCollection
      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.
      Specified by:
      withoutAll in interface MutableCollection<T>
      See Also:
      Collection.removeAll(Collection)
    • asUnmodifiable

      public MutableCollection<T> asUnmodifiable()
      Description copied from interface: MutableCollection
      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.
      Specified by:
      asUnmodifiable in interface MutableCollection<T>
      Returns:
      an unmodifiable view of this collection.
      See Also:
      Collections.unmodifiableCollection(Collection)
    • asSynchronized

      public MutableCollection<T> asSynchronized()
      Description copied from interface: MutableCollection
      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.

      Specified by:
      asSynchronized in interface MutableCollection<T>
      Returns:
      a synchronized view of this collection.
      See Also:
      Collections.synchronizedCollection(Collection)
    • toImmutable

      public ImmutableCollection<T> toImmutable()
      Description copied from interface: MutableCollection
      Converts this MutableCollection to an ImmutableCollection.
      Specified by:
      toImmutable in interface MutableCollection<T>
    • newEmpty

      public MutableCollection<T> newEmpty()
      Description copied from interface: MutableCollection
      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.
      Specified by:
      newEmpty in interface MutableCollection<T>