org.eclipse.viatra.query.runtime.rete.tuple

## Class TupleMemory

- java.lang.Object
- - org.eclipse.viatra.query.runtime.rete.tuple.TupleMemory

- All Implemented Interfaces:
    java.lang.Iterable<Tuple>, java.util.Collection<Tuple>, Clearable

      public class TupleMemory
      extends java.lang.Object
      implements Clearable, java.util.Collection<Tuple>

  Multiset for tuples. Can contain duplicate occurrences of the same matching.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Map<Tuple,java.lang.Integer>` | `occurrences` Counts the number of occurrences of each pattern.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TupleMemory()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(Tuple ps)` Adds one tuple occurrence to the memory.
    `boolean` | `add(Tuple ps, int count)` Adds the given number of tuple occurrences to the memory.
    `boolean` | `addAll(java.util.Collection<? extends Tuple> arg0)`
    `void` | `clear()` Clear all partial matchings stored in memory
    `void` | `clear(Tuple ps)` Removes all occurrences of the given tuple from the memory.
    `boolean` | `contains(java.lang.Object arg)`
    `boolean` | `containsAll(java.util.Collection<?> arg0)`
    `boolean` | `demandAdd(Tuple ps)` Adds one tuple occurrence to the memory if the tuple was already contained in the memory.
    `boolean` | `demandAdd(Tuple ps, int count)` Adds the given number of tuple occurrences to the memory if the tuple was already contained in the memory.
    `int` | `get(Tuple ps)` Returns the number of occurrences of the given tuple.
    `boolean` | `isEmpty()`
    `java.util.Iterator<Tuple>` | `iterator()`
    `boolean` | `remove(java.lang.Object arg0)`
    `boolean` | `remove(Tuple ps)` Removes one occurrence of the given tuple from the memory
    `boolean` | `removeAll(java.util.Collection<?> arg0)`
    `boolean` | `retainAll(java.util.Collection<?> arg0)`
    `int` | `size()`
    `java.lang.Object[]` | `toArray()`
    `<T> T[]` | `toArray(T[] arg0)`
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Collection

      `equals, hashCode, parallelStream, removeIf, spliterator, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Field Detail

    - #### occurrences

          protected java.util.Map<Tuple,java.lang.Integer> occurrences

      Counts the number of occurrences of each pattern. Element is deleted if # of occurences drops to 0.

  - ### Constructor Detail

    - #### TupleMemory

          public TupleMemory()

  - ### Method Detail

    - #### get

          public int get(Tuple ps)

      Returns the number of occurrences of the given tuple.
      Parameters:
        `ps` - the tuple
      Returns:
        the number of occurrences
      Since:
        1.6

    - #### add

          public boolean add(Tuple ps)

      Adds one tuple occurrence to the memory.
      Specified by:
        `add` in interface `java.util.Collection<Tuple>`
      Parameters:
        `ps` - the tuple
      Returns:
        true if the tuple was not present before in the memory

    - #### add

          public boolean add(Tuple ps,
                             int count)

      Adds the given number of tuple occurrences to the memory. The count value must be a positive number.
      Parameters:
        `ps` - the tuple
        `count` - the number of occurrences
      Returns:
        true if the tuple was not present before in the memory
      Since:
        1.6

    - #### demandAdd

          public boolean demandAdd(Tuple ps)

      Adds one tuple occurrence to the memory if the tuple was already contained in the memory. In this case the method returns true. If the tuple is not present in the memory, it will not be added and the method returns false.
      Parameters:
        `ps` - the tuple
      Returns:
        true if the addition was successful, that is, the tuple was already present, false otherwise
      Since:
        1.6

    - #### demandAdd

          public boolean demandAdd(Tuple ps,
                                   int count)

      Adds the given number of tuple occurrences to the memory if the tuple was already contained in the memory. In this case the method returns true. If the tuple is not present in the memory, it will not be added and the method returns false.
      Parameters:
        `ps` - the tuple
        `count` - the number of occurrences
      Returns:
        true if the addition was successful, that is, the tuple was already present, false otherwise
      Since:
        1.6

    - #### remove

          public boolean remove(Tuple ps)

      Removes one occurrence of the given tuple from the memory
      Returns:
        true if this was the the last occurrence of the tuple

    - #### clear

          public void clear(Tuple ps)

      Removes all occurrences of the given tuple from the memory.
      Parameters:
        `ps` - the tuple to remove
      Since:
        1.6

    - #### clear

          public void clear()

      Description copied from interface: `Clearable`
      Clear all partial matchings stored in memory
      Specified by:
        `clear` in interface `java.util.Collection<Tuple>`
      Specified by:
        `clear` in interface `Clearable`

    - #### iterator

          public java.util.Iterator<Tuple> iterator()

      Specified by:
        `iterator` in interface `java.lang.Iterable<Tuple>`
      Specified by:
        `iterator` in interface `java.util.Collection<Tuple>`

    - #### addAll

          public boolean addAll(java.util.Collection<? extends Tuple> arg0)

      Specified by:
        `addAll` in interface `java.util.Collection<Tuple>`

    - #### contains

          public boolean contains(java.lang.Object arg)

      Specified by:
        `contains` in interface `java.util.Collection<Tuple>`

    - #### containsAll

          public boolean containsAll(java.util.Collection<?> arg0)

      Specified by:
        `containsAll` in interface `java.util.Collection<Tuple>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `java.util.Collection<Tuple>`

    - #### remove

          public boolean remove(java.lang.Object arg0)

      Specified by:
        `remove` in interface `java.util.Collection<Tuple>`

    - #### removeAll

          public boolean removeAll(java.util.Collection<?> arg0)

      Specified by:
        `removeAll` in interface `java.util.Collection<Tuple>`

    - #### retainAll

          public boolean retainAll(java.util.Collection<?> arg0)

      Specified by:
        `retainAll` in interface `java.util.Collection<Tuple>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `java.util.Collection<Tuple>`

    - #### toArray

          public java.lang.Object[] toArray()

      Specified by:
        `toArray` in interface `java.util.Collection<Tuple>`

    - #### toArray

          public <T> T[] toArray(T[] arg0)

      Specified by:
        `toArray` in interface `java.util.Collection<Tuple>`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`