Class WritableSet<E>

  • Type Parameters:
    E - the type of elements in this set
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, IObservable, IObservableCollection<E>, IObservableSet<E>

    public class WritableSet<E>
    extends ObservableSet<E>
    Mutable (writable) implementation of IObservableSet.

    This class is thread safe. All state accessing methods must be invoked from the current realm. Methods for adding and removing listeners may be invoked from any thread.

    Since:
    1.0
    • Constructor Detail

      • WritableSet

        public WritableSet()
        Constructs a new empty instance in the default realm with a null element type.
      • WritableSet

        public WritableSet​(java.util.Collection<? extends E> c,
                           java.lang.Object elementType)
        Constructs a new instance in the default realm containing the elements of the given collection. Changes to the given collection after calling this method do not affect the contents of the created WritableSet.
        Parameters:
        c - elements to initialize this set with
        elementType - can be null
      • WritableSet

        public WritableSet​(Realm realm)
        Constructs a new empty instance in the given realm and a null element type.
        Parameters:
        realm - the realm
      • WritableSet

        public WritableSet​(Realm realm,
                           java.util.Collection<? extends E> c,
                           java.lang.Object elementType)
        Constructs a new instance in the default realm with the given element type, containing the elements of the given collection. Changes to the given collection after calling this method do not affect the contents of the created WritableSet.
        Parameters:
        realm - the realm
        c - elements to initialize this set with
        elementType - can be null
    • Method Detail

      • add

        public boolean add​(E o)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface IObservableSet<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class ObservableSet<E>
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface IObservableSet<E>
        Specified by:
        addAll in interface java.util.Set<E>
        Overrides:
        addAll in class ObservableSet<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface IObservableSet<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class ObservableSet<E>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface IObservableSet<E>
        Specified by:
        removeAll in interface java.util.Set<E>
        Overrides:
        removeAll in class ObservableSet<E>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface IObservableSet<E>
        Specified by:
        retainAll in interface java.util.Set<E>
        Overrides:
        retainAll in class ObservableSet<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.Set<E>
        Overrides:
        clear in class ObservableSet<E>
      • withElementType

        public static <E> WritableSet<E> withElementType​(java.lang.Object elementType)
        Parameters:
        elementType - can be null
        Returns:
        new instance with the default realm
      • addListener

        protected void addListener​(java.lang.Object listenerType,
                                   IObservablesListener listener)
        Parameters:
        listenerType - arbitrary object to identify a type of the listener
        listener - the listener to add; not null
      • removeListener

        protected void removeListener​(java.lang.Object listenerType,
                                      IObservablesListener listener)
        Parameters:
        listenerType - arbitrary object to identify a type of the listener
        listener - the listener to remove; not null
      • hasListeners

        protected boolean hasListeners()
      • firstListenerAdded

        protected void firstListenerAdded()
      • lastListenerRemoved

        protected void lastListenerRemoved()
      • getRealm

        public Realm getRealm()
        Returns:
        Returns the realm.
      • clone

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException