Interface IMemoryView<T>

All Superinterfaces:
Iterable<T>
All Known Subinterfaces:
IDeltaBag<T>, IMemory<T>, IMultiset<T>, ISetMemory<T>, MarkedMemory<Value>, MarkedMemory.MarkedDeltaBag<Value>, MarkedMemory.MarkedMultiset<Value>, MarkedMemory.MarkedSet<Value>
All Known Implementing Classes:
EclipseCollectionsBagMemory, EclipseCollectionsDeltaBag, EclipseCollectionsLongMultiset, EclipseCollectionsLongSetMemory, EclipseCollectionsMultiset, EclipseCollectionsSetMemory, EmptyMemory, MapBackedMemoryView, SingletonMemoryView

public interface IMemoryView<T> extends Iterable<T>
A read-only view on a memory containing a positive or negative number of equal() copies for some values. During iterations, each distinct value is iterated only once.

See IMemory.

Implementors must provide semantic (not identity-based) hashCode() and equals() using the static helpers hashCode(IMemoryView) and equals(IMemoryView, Object) here.

Since:
2.0
  • Method Details

    • getCount

      int getCount(T value)
      Returns the number of occurrences of the given value.
      Returns:
      the number of occurrences
    • getCountUnsafe

      int getCountUnsafe(Object value)
      Returns the number of occurrences of the given value (which may be of any type).
      Returns:
      the number of occurrences
    • containsNonZero

      boolean containsNonZero(T value)
      Returns:
      true if the given value is contained with a nonzero multiplicity
    • containsNonZeroUnsafe

      boolean containsNonZeroUnsafe(Object value)
      Returns:
      true if the given value (which may be of any type) is contained with a nonzero multiplicity
    • size

      int size()
      Returns:
      the number of distinct values
    • isEmpty

      boolean isEmpty()
      Returns:
      iff contains at least one value with non-zero occurrences
    • distinctValues

      Set<T> distinctValues()
      The set of distinct values
    • theContainedVersionOf

      default T theContainedVersionOf(T value)
      Where supported, returns the stored element that is equal to the given value, or null if none. Useful for canonicalization in case of non-identity equals().

      For collections that do not support canonicalization, simply returns the argument if contained, null if none.

      Returns:
      a value equal to the argument if such a value is stored, or null if none
    • theContainedVersionOfUnsafe

      default T theContainedVersionOfUnsafe(Object value)
      Where supported, returns the stored element that is equal to the given value (of any type), or null if none. Useful for canonicalization in case of non-identity equals().

      For collections that do not support canonicalization, simply returns the argument if contained, null if none.

      Returns:
      a value equal to the argument if such a value is stored, or null if none
    • entriesWithMultiplicities

      default Iterable<Map.Entry<T,Integer>> entriesWithMultiplicities()
      Returns:
      an unmodifiable view of contained values with their multiplicities
    • forEachEntryWithMultiplicities

      default void forEachEntryWithMultiplicities(BiConsumer<T,Integer> entryConsumer)
      Process contained values with their multiplicities
    • asMap

      default Map<T,Integer> asMap()
      For compatibility with legacy code relying on element-to-integer maps.
      Returns:
      an unmodifiable view of contained values with their multiplicities
    • fromMap

      static <T> IMemoryView<T> fromMap(Map<T,Integer> wrapped)
      For compatibility with legacy code relying on element-to-integer maps.
      Returns:
      an unmodifiable view of contained values with their multiplicities
    • asStream

      default Stream<T> asStream()
      Returns:
      a stream of values, iterable once
      Since:
      2.1
    • equals

      static <T> boolean equals(IMemoryView<T> self, Object obj)
      Provides semantic equality comparison.
    • hashCode

      static <T> int hashCode(IMemoryView<T> memory)
      Provides semantic hashCode() comparison.