Class MultisetChangeListener.Change<E>

  • Type Parameters:
    E - The element type of the ObservableMultiset.
    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 an 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 Detail

      • Change

        public Change​(ObservableMultiset<E> source)
        Creates a new (atomic) change associated with the given source ObservableMultiset.
        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 using getElement(), getAddCount(), and getRemoveCount(). 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 calling next().
      • getMultiset

        public ObservableMultiset<E> getMultiset()
        The source ObservableMultiset 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 unmodifiable Multiset that contains the previous contents of the source ObservableMultiset 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 the ObservableMultiset 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() and reset().

        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() and reset().

        Returns:
        The number of occurrences that have been removed.
      • getElement

        public abstract E 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() and reset().

        Returns:
        The added element in case an element was added.