Class MultisetChangeListener.Change<E>
- java.lang.Object
-
- org.eclipse.gef.common.collections.MultisetChangeListener.Change<E>
-
- Type Parameters:
E
- The element type of theObservableMultiset
.
- Direct Known Subclasses:
MultisetListenerHelper.AtomicChange
- Enclosing interface:
- MultisetChangeListener<E>
public abstract static class MultisetChangeListener.Change<E> extends java.lang.Object
Represents an atomic change done to anObservableMultiset
, i.e. a change resulting from a single method invocation on anObservableMultiset
.The change may internally consist of several elementary sub-changes, which are related to changes of a single element. That is, a call to
Multiset.add(Object)
orMultiset.setCount(Object, int)
will lead to an atomic change that comprises only a single elementary sub-change, while a call toCollection.clear()
will potentially lead to several elementary sub-changes (one for each element contained in the Multiset).The comprised elementary sub-changes need to be navigated using
next()
, the relevant information can then be retrieved viagetElement()
,getAddCount()
, andgetRemoveCount()
(for the current elementary sub-change the internal cursor currently points at). Initially, the internal cursor is set to point before the first elementary sub-change, so that an initial call tonext()
is required to access the first elementary sub-change, whilereset()
can be used to reset the cursor to this initial state before the first elementary sub-change.The
getMultiset()
returns the sourceObservableMultiset
that was changed (in the state after the atomic change was applied). The previous contents of the sourceObservableMultiset
(in the state before the atomic change was applied) can be obtained viagetPreviousContents()
. Both are independent of the state of the internal cursor and may be accessed at any time.
-
-
Constructor Summary
Constructors Constructor Description Change(ObservableMultiset<E> source)
Creates a new (atomic) change associated with the given sourceObservableMultiset
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
getAddCount()
Returns how often an element has been added in the current elementary sub-change, if one has been added.abstract E
getElement()
Retrieves the element that was altered in the current elementary sub-change.ObservableMultiset<E>
getMultiset()
The sourceObservableMultiset
this atomic change is associated with.abstract Multiset<E>
getPreviousContents()
Returns an unmodifiableMultiset
that contains the previous contents of the sourceObservableMultiset
before the atomic change was applied.abstract int
getRemoveCount()
Returns how often an element has been removed in the current elementary sub-change, if one has been removed.abstract boolean
next()
Places the internal cursor on the next elementary sub-change, so that it be processed usinggetElement()
,getAddCount()
, andgetRemoveCount()
.abstract void
reset()
Reset the internal cursor to the initial state, so that the first elementary sub-change can be accessed by callingnext()
.
-
-
-
Constructor Detail
-
Change
public Change(ObservableMultiset<E> source)
Creates a new (atomic) change associated with the given sourceObservableMultiset
.- Parameters:
source
- The source of the change.
-
-
Method Detail
-
next
public abstract boolean next()
Places the internal cursor on the next elementary sub-change, so that it be processed usinggetElement()
,getAddCount()
, andgetRemoveCount()
. This method has to be called initially to have the internal cursor point to the first elementary sub-change that is comprised.- Returns:
true
if the internal cursor could be switched to the next elementary sub-change,false
if the current elementary sub-change was the last change that is comprised.
-
reset
public abstract void reset()
Reset the internal cursor to the initial state, so that the first elementary sub-change can be accessed by callingnext()
.
-
getMultiset
public ObservableMultiset<E> getMultiset()
The sourceObservableMultiset
this atomic change is associated with.This method does not depend on the state of the internal cursor, may thus be accessed independent on which elementary sub-change is currently processed.
- Returns:
- The source
ObservableMultiset
.
-
getPreviousContents
public abstract Multiset<E> getPreviousContents()
Returns an unmodifiableMultiset
that contains the previous contents of the sourceObservableMultiset
before the atomic change was applied.This method does not depend on the state of the internal cursor, may thus be accessed independent on which elementary sub-change is currently processed.
- Returns:
- An unmodifiable
Multiset
representing the contents of theObservableMultiset
before the change.
-
getAddCount
public abstract int getAddCount()
Returns how often an element has been added in the current elementary sub-change, if one has been added.This method depends on the state of the internal cursor that can be manipulated via
next()
andreset()
.- Returns:
- The number of occurrences that have been added.
-
getRemoveCount
public abstract int getRemoveCount()
Returns how often an element has been removed in the current elementary sub-change, if one has been removed.This method depends on the state of the internal cursor that can be manipulated via
next()
andreset()
.- Returns:
- The number of occurrences that have been removed.
-
-