Class MultisetChangeListener.Change<E>
- Type Parameters:
E
- The element type of theObservableMultiset
.
- Direct Known Subclasses:
MultisetListenerHelper.AtomicChange
- Enclosing interface:
- MultisetChangeListener<E>
ObservableMultiset
, i.e. a
change resulting from a single method invocation on an
ObservableMultiset
.
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)
or
Multiset.setCount(Object, int)
will lead to an atomic
change that comprises only a single elementary sub-change, while a call
to Collection.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 via
getElement()
, getAddCount()
, and
getRemoveCount()
(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 to next()
is required to access the first elementary
sub-change, while reset()
can be used to reset the cursor to
this initial state before the first elementary sub-change.
The getMultiset()
returns the source ObservableMultiset
that was changed (in the state after the atomic change was applied). The
previous contents of the source ObservableMultiset
(in the state
before the atomic change was applied) can be obtained via
getPreviousContents()
. Both are independent of the state of the
internal cursor and may be accessed at any time.
-
Constructor Summary
ConstructorsConstructorDescriptionChange
(ObservableMultiset<E> source) Creates a new (atomic) change associated with the given sourceObservableMultiset
. -
Method Summary
Modifier and TypeMethodDescriptionabstract int
Returns how often an element has been added in the current elementary sub-change, if one has been added.abstract E
Retrieves the element that was altered in the current elementary sub-change.The sourceObservableMultiset
this atomic change is associated with.Returns an unmodifiableMultiset
that contains the previous contents of the sourceObservableMultiset
before the atomic change was applied.abstract int
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 Details
-
Change
Creates a new (atomic) change associated with the given sourceObservableMultiset
.- Parameters:
source
- The source of the change.
-
-
Method Details
-
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
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
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.
-
getElement
Retrieves the element that was altered in the current elementary sub-change.This method depends on the state of the internal cursor that can be manipulated via
next()
andreset()
.- Returns:
- The added element in case an element was added.
-