Class MapBackedMemoryView<T>

java.lang.Object
tools.refinery.interpreter.matchers.util.MapBackedMemoryView<T>
All Implemented Interfaces:
Iterable<T>, IMemoryView<T>

public class MapBackedMemoryView<T> extends Object implements IMemoryView<T>
Wraps a Mapinvalid input: '<'T, Integer> (mapping elements to non-zero multiplicities) into an IMemoryView.
Since:
2.0
  • Constructor Details

    • MapBackedMemoryView

      protected MapBackedMemoryView(Map<T,Integer> wrapped)
      Parameters:
      wrapped - an equivalent map from contained objects to multiplicities
  • Method Details

    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • getCount

      public int getCount(T value)
      Description copied from interface: IMemoryView
      Returns the number of occurrences of the given value.
      Specified by:
      getCount in interface IMemoryView<T>
      Returns:
      the number of occurrences
    • getCountUnsafe

      public int getCountUnsafe(Object value)
      Description copied from interface: IMemoryView
      Returns the number of occurrences of the given value (which may be of any type).
      Specified by:
      getCountUnsafe in interface IMemoryView<T>
      Returns:
      the number of occurrences
    • containsNonZero

      public boolean containsNonZero(T value)
      Specified by:
      containsNonZero in interface IMemoryView<T>
      Returns:
      true if the given value is contained with a nonzero multiplicity
    • containsNonZeroUnsafe

      public boolean containsNonZeroUnsafe(Object value)
      Specified by:
      containsNonZeroUnsafe in interface IMemoryView<T>
      Returns:
      true if the given value (which may be of any type) is contained with a nonzero multiplicity
    • size

      public int size()
      Specified by:
      size in interface IMemoryView<T>
      Returns:
      the number of distinct values
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface IMemoryView<T>
      Returns:
      iff contains at least one value with non-zero occurrences
    • distinctValues

      public Set<T> distinctValues()
      Description copied from interface: IMemoryView
      The set of distinct values
      Specified by:
      distinctValues in interface IMemoryView<T>
    • forEachEntryWithMultiplicities

      public void forEachEntryWithMultiplicities(BiConsumer<T,Integer> entryConsumer)
      Description copied from interface: IMemoryView
      Process contained values with their multiplicities
      Specified by:
      forEachEntryWithMultiplicities in interface IMemoryView<T>
    • entriesWithMultiplicities

      public Iterable<Map.Entry<T,Integer>> entriesWithMultiplicities()
      Specified by:
      entriesWithMultiplicities in interface IMemoryView<T>
      Returns:
      an unmodifiable view of contained values with their multiplicities
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object