Package groovy.util
Class ObservableSet<E>
java.lang.Object
groovy.util.ObservableSet<E>
- All Implemented Interfaces:
- java.lang.Iterable<E>,- java.util.Collection<E>,- java.util.Set<E>
public class ObservableSet<E>
extends java.lang.Object
implements java.util.Set<E>
Set decorator that will trigger PropertyChangeEvents when a value changes.
An optional Closure may be specified and will work as a filter, if it returns true the property will trigger an event (if the value indeed changed), otherwise it won't. The Closure may receive 1 or 2 parameters, the single one being the value, the other one both the key and value, for example:
An optional Closure may be specified and will work as a filter, if it returns true the property will trigger an event (if the value indeed changed), otherwise it won't. The Closure may receive 1 or 2 parameters, the single one being the value, the other one both the key and value, for example:
 // skip all properties whose value is a closure
 def set = new ObservableSet( {!(it instanceof Closure)} )
 <p/>
 // skip all properties whose name matches a regex
 def set = new ObservableSet( { name, value -> !(name =˜ /[A-Z+]/) } )
 
 The current implementation will trigger specialized events in the following scenarios, you need
 not register a different listener as those events extend from PropertyChangeEvent
 - ObservableSet.ElementAddedEvent - a new element is added to the set
- ObservableSet.ElementRemovedEvent - an element is removed from the set
- ObservableSet.ElementUpdatedEvent - an element changes value (same as regular PropertyChangeEvent)
- ObservableSet.ElementClearedEvent - all elements have been removed from the list
- ObservableSet.MultiElementAddedEvent - triggered by calling set.addAll()
- ObservableSet.MultiElementRemovedEvent - triggered by calling set.removeAll()/set.retainAll()
Bound properties
- content - read-only.
- size - read-only.
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classObservableSet.ChangeTypestatic classObservableSet.ElementAddedEventstatic classObservableSet.ElementClearedEventstatic classObservableSet.ElementEventstatic classObservableSet.ElementRemovedEventstatic classObservableSet.MultiElementAddedEventstatic classObservableSet.MultiElementRemovedEventprotected classObservableSet.ObservableIterator<E>
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringCONTENT_PROPERTYstatic java.lang.StringSIZE_PROPERTY
- 
Constructor SummaryConstructors Constructor Description ObservableSet()ObservableSet(Closure test)ObservableSet(java.util.Set<E> delegate)ObservableSet(java.util.Set<E> delegate, Closure test)
- 
Method SummaryModifier and Type Method Description booleanadd(E e)booleanaddAll(java.util.Collection<? extends E> c)voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)voidaddPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> objects)protected voidfireElementAddedEvent(java.lang.Object element)protected voidfireElementClearedEvent(java.util.List values)protected voidfireElementEvent(ObservableSet.ElementEvent event)protected voidfireElementRemovedEvent(java.lang.Object element)protected voidfireMultiElementAddedEvent(java.util.List values)protected voidfireMultiElementRemovedEvent(java.util.List values)protected voidfireSizeChangedEvent(int oldValue, int newValue)java.util.Set<E>getContent()protected java.util.Set<E>getDelegateSet()java.beans.PropertyChangeListener[]getPropertyChangeListeners()java.beans.PropertyChangeListener[]getPropertyChangeListeners(java.lang.String propertyName)protected ClosuregetTest()booleanhasListeners(java.lang.String propertyName)booleanisEmpty()java.util.Iterator<E>iterator()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)voidremovePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)booleanretainAll(java.util.Collection<?> c)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] ts)Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, stream, toArrayMethods inherited from interface java.lang.IterableforEachMethods inherited from interface java.util.Setequals, hashCode, spliterator
- 
Field Details- 
SIZE_PROPERTYpublic static final java.lang.String SIZE_PROPERTY- See Also:
- Constant Field Values
 
- 
CONTENT_PROPERTYpublic static final java.lang.String CONTENT_PROPERTY- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
ObservableSetpublic ObservableSet()
- 
ObservableSet
- 
ObservableSet
- 
ObservableSet
 
- 
- 
Method Details- 
getContent
- 
getDelegateSet
- 
getTest
- 
fireElementAddedEventprotected void fireElementAddedEvent(java.lang.Object element)
- 
fireMultiElementAddedEventprotected void fireMultiElementAddedEvent(java.util.List values)
- 
fireElementClearedEventprotected void fireElementClearedEvent(java.util.List values)
- 
fireElementRemovedEventprotected void fireElementRemovedEvent(java.lang.Object element)
- 
fireMultiElementRemovedEventprotected void fireMultiElementRemovedEvent(java.util.List values)
- 
fireElementEvent
- 
fireSizeChangedEventprotected void fireSizeChangedEvent(int oldValue, int newValue)
- 
addPropertyChangeListenerpublic void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
- 
addPropertyChangeListenerpublic void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
- 
getPropertyChangeListenerspublic java.beans.PropertyChangeListener[] getPropertyChangeListeners()
- 
getPropertyChangeListenerspublic java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
- 
removePropertyChangeListenerpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
- 
removePropertyChangeListenerpublic void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
- 
hasListenerspublic boolean hasListeners(java.lang.String propertyName)
- 
sizepublic int size()
- 
isEmptypublic boolean isEmpty()
- 
containspublic boolean contains(java.lang.Object o)
- 
iterator
- 
toArraypublic java.lang.Object[] toArray()
- 
toArraypublic <T> T[] toArray(T[] ts)
- 
add
- 
removepublic boolean remove(java.lang.Object o)
- 
containsAllpublic boolean containsAll(java.util.Collection<?> objects)
- 
addAll
- 
retainAllpublic boolean retainAll(java.util.Collection<?> c)
- 
removeAllpublic boolean removeAll(java.util.Collection<?> c)
- 
clearpublic void clear()
 
-