Package org.eclipse.viatra.query.runtime.base.api

## Class QueryResultAssociativeStore<KeyType,​ValueType>

- java.lang.Object
- - org.eclipse.viatra.query.runtime.base.api.QueryResultAssociativeStore<KeyType,​ValueType>

- Direct Known Subclasses:
    `QueryResultMap`

      public abstract class QueryResultAssociativeStore<KeyType,​ValueType>
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected static java.lang.String` | `NOT_ALLOW_MODIFICATIONS` | Error literal returned when associative store modification is attempted without a setter available

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `QueryResultAssociativeStore()` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addCallbackOnQueryResultUpdate​(IQueryResultUpdateListener<KeyType,​ValueType> listener, boolean fireNow)` | Registers a listener for this query result associative store that is invoked every time when a key-value pair is inserted or removed from the associative store.
    `protected boolean` | `checkModificationThroughQueryResultSetter​(KeyType key, ValueType value, Direction direction, int expectedChange, int size)` | Checks whether the model modification performed by the `IQueryResultSetter` resulted in the insertion or removal of exactly the required key-value pair.
    `protected abstract java.util.Collection<java.util.Map.Entry<KeyType,​ValueType>>` | `getCacheEntries()` | Returns the entries in the cache as a collection.
    `protected java.util.Collection<IQueryResultUpdateListener<KeyType,​ValueType>>` | `getListeners()` |
    `protected org.apache.log4j.Logger` | `getLogger()` |
    `protected IQueryResultSetter<KeyType,​ValueType>` | `getSetter()` |
    `protected abstract boolean` | `internalCacheContainsEntry​(KeyType key, ValueType value)` |
    `protected abstract boolean` | `internalCachePut​(KeyType key, ValueType value)` |
    `protected abstract boolean` | `internalCacheRemove​(KeyType key, ValueType value)` |
    `protected abstract int` | `internalCacheSize()` |
    `protected void` | `internalClear()` |
    `protected boolean` | `internalPut​(KeyType key, ValueType value)` | Implementations of QueryResultAssociativeStore can put a new key-value pair into the associative store with this method.
    `protected boolean` | `internalRemove​(KeyType key, ValueType value)` | Implementations of QueryResultAssociativeStore can remove a key-value pair from the associative store with this method.
    `protected boolean` | `modifyThroughQueryResultSetter​(KeyType key, ValueType value, Direction direction)` | This method is used for calling the query result setter to put or remove a value by modifying the model.
    `protected void` | `notifyListeners​(Direction direction, KeyType key, ValueType value)` | This method notifies the listeners that the query result associative store has changed.
    `void` | `removeCallbackOnQueryResultUpdate​(IQueryResultUpdateListener<KeyType,​ValueType> listener)` | Unregisters a callback registered by `addCallbackOnQueryResultUpdate(IQueryResultUpdateListener, boolean)` .
    `protected void` | `setListeners​(java.util.Collection<IQueryResultUpdateListener<KeyType,​ValueType>> listeners)` |
    `protected void` | `setLogger​(org.apache.log4j.Logger logger)` |
    `void` | `setQueryResultSetter​(IQueryResultSetter<KeyType,​ValueType> setter)` |
    `protected void` | `setSetter​(IQueryResultSetter<KeyType,​ValueType> setter)` |

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

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

- - ### Field Detail

    - #### NOT_ALLOW_MODIFICATIONS

          protected static final java.lang.String NOT_ALLOW_MODIFICATIONS

      Error literal returned when associative store modification is attempted without a setter available
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### QueryResultAssociativeStore

          public QueryResultAssociativeStore()

  - ### Method Detail

    - #### getListeners

          protected java.util.Collection<IQueryResultUpdateListener<KeyType,​ValueType>> getListeners()

      Returns:
        the listeners

    - #### setListeners

          protected void setListeners​(java.util.Collection<IQueryResultUpdateListener<KeyType,​ValueType>> listeners)

      Parameters:
        `listeners` - the listeners to set

    - #### getSetter

          protected IQueryResultSetter<KeyType,​ValueType> getSetter()

      Returns:
        the setter

    - #### setSetter

          protected void setSetter​(IQueryResultSetter<KeyType,​ValueType> setter)

      Parameters:
        `setter` - the setter to set

    - #### setLogger

          protected void setLogger​(org.apache.log4j.Logger logger)

      Parameters:
        `logger` - the logger to set

    - #### getCacheEntries

          protected abstract java.util.Collection<java.util.Map.Entry<KeyType,​ValueType>> getCacheEntries()

      Returns the entries in the cache as a collection.
      Returns:
        the entries

    - #### addCallbackOnQueryResultUpdate

          public void addCallbackOnQueryResultUpdate​(IQueryResultUpdateListener<KeyType,​ValueType> listener,
                                                     boolean fireNow)

      Registers a listener for this query result associative store that is invoked every time when a key-value pair is inserted or removed from the associative store.

      The listener can be unregistered via `removeCallbackOnQueryResultUpdate(IQueryResultUpdateListener)`.

      Parameters:
        `listener` - the listener that will be notified of each key-value pair that is inserted or removed, starting from now.
        `fireNow` - if true, notifyPut will be immediately invoked on all current key-values as a one-time effect.

    - #### removeCallbackOnQueryResultUpdate

          public void removeCallbackOnQueryResultUpdate​(IQueryResultUpdateListener<KeyType,​ValueType> listener)

      Unregisters a callback registered by `addCallbackOnQueryResultUpdate(IQueryResultUpdateListener, boolean)` .
      Parameters:
        `listener` - the listener that will no longer be notified.

    - #### notifyListeners

          protected void notifyListeners​(Direction direction,
                                         KeyType key,
                                         ValueType value)

      This method notifies the listeners that the query result associative store has changed.
      Parameters:
        `direction` - the type of the change (insert or delete)
        `key` - the key of the pair that changed
        `value` - the value of the pair that changed

    - #### internalPut

          protected boolean internalPut​(KeyType key,
                                        ValueType value)

      Implementations of QueryResultAssociativeStore can put a new key-value pair into the associative store with this method. If the insertion of the key-value pair results in a change, the listeners are notified.

      No validation or null-checking is performed during the method!

      Parameters:
        `key` - the key which identifies where the new value is put
        `value` - the value that is put into the collection of the key
      Returns:
        true, if the insertion resulted in a change (the key-value pair was not yet in the associative store)

    - #### internalRemove

          protected boolean internalRemove​(KeyType key,
                                           ValueType value)

      Implementations of QueryResultAssociativeStore can remove a key-value pair from the associative store with this method. If the removal of the key-value pair results in a change, the listeners are notified.

      No validation or null-checking is performed during the method!

      Parameters:
        `key` - the key which identifies where the value is removed from
        `value` - the value that is removed from the collection of the key
      Returns:
        true, if the removal resulted in a change (the key-value pair was in the associative store)

    - #### internalCachePut

          protected abstract boolean internalCachePut​(KeyType key,
                                                      ValueType value)

    - #### internalCacheRemove

          protected abstract boolean internalCacheRemove​(KeyType key,
                                                         ValueType value)

    - #### internalCacheSize

          protected abstract int internalCacheSize()

    - #### internalCacheContainsEntry

          protected abstract boolean internalCacheContainsEntry​(KeyType key,
                                                                ValueType value)

    - #### setQueryResultSetter

          public void setQueryResultSetter​(IQueryResultSetter<KeyType,​ValueType> setter)

      Parameters:
        `setter` - the setter to set

    - #### getLogger

          protected org.apache.log4j.Logger getLogger()

      Returns:
        the logger

    - #### internalClear

          protected void internalClear()

    - #### modifyThroughQueryResultSetter

          protected boolean modifyThroughQueryResultSetter​(KeyType key,
                                                           ValueType value,
                                                           Direction direction)

      This method is used for calling the query result setter to put or remove a value by modifying the model.

      The given key-value pair is first validated (see `IQueryResultSetter.validate(Object, Object)`, then the put or remove method is called (see `IQueryResultSetter.put(Object, Object)` and `IQueryResultSetter.remove(Object, Object)`). If the setter reported that the model has been changed, the change is checked.

      If the model modification did not change the result set in the desired way, a warning is logged.

      If the setter throws any `Throwable`, it is either rethrown in case of `Error` and logged otherwise.

      Parameters:
        `key` - the key of the pair to be inserted or removed
        `value` - the value of the pair to be inserted or removed
        `direction` - specifies whether a put or a remove is performed
      Returns:
        true, if the associative store changed according to the direction

    - #### checkModificationThroughQueryResultSetter

          protected boolean checkModificationThroughQueryResultSetter​(KeyType key,
                                                                      ValueType value,
                                                                      Direction direction,
                                                                      int expectedChange,
                                                                      int size)

      Checks whether the model modification performed by the `IQueryResultSetter` resulted in the insertion or removal of exactly the required key-value pair.
      Parameters:
        `key` - the key for the pair that was inserted or removed
        `value` - the value for the pair that was inserted or removed
        `direction` - the direction of the change
        `size` - the size of the cache before the change
      Returns:
        true, if the changes made by the query result setter were correct