Interface IMultiLookupAbstract<Key,Value,Bucket extends MarkedMemory<Value>>
- All Superinterfaces:
IMultiLookup<Key,
Value>
- All Known Subinterfaces:
IMultiLookupAbstract.ToMultisetsAbstract<Key,
,Value> IMultiLookupAbstract.ToSetsAbstract<Key,
Value>
See specialized IMultiLookupAbstract.ToSetsAbstract
, IMultiLookupAbstract.ToMultisetsAbstract
for various bucket types.
Implemented as a Key->Object map with invariant:
- key maps to null if associated with no values;
- key maps to a single Value iff it is associated with a single value of multiplicity +1;
- key maps to Bucket otherwise
Not intended as an API, but rather as a 'base class' for implementors. Realized as an interface with default implementations, instead of an abstract class, to ensure that implementors can easily choose a base class such as UnifiedMap to augment.
Implementor should inherit from a Mapinvalid input: '<'Key, Object>-like class (primitive map possible) and bind the lowLevel* methods accordingly.
- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A multi-lookup whose buckets are multisets.static interface
A multi-lookup whose buckets are sets.Nested classes/interfaces inherited from interface tools.refinery.interpreter.matchers.util.IMultiLookup
IMultiLookup.ChangeGranularity
-
Method Summary
Modifier and TypeMethodDescriptiondefault IMultiLookup.ChangeGranularity
Adds key-value pair to the lookup structure, or fails if not possible.default IMultiLookup.ChangeGranularity
addPairInternal
(Key key, Value value, boolean throwIfImpossible) default IMultiLookup.ChangeGranularity
addPairOrNop
(Key key, Value value) Adds key-value pair to the lookup structure.default IMultiLookup.ChangeGranularity
addPairPositiveMultiplicity
(Key key, Value value, int count) Updates multiplicity of key-value pair by a positive amount.boolean
addToBucket
(Bucket bucket, Value value, boolean throwIfImpossible) Increases the multiplicity of the value in the bucket.asSingleton
(Bucket bucket) Checks whether the bucket is a singleton, i.e.default int
createDeltaBucket
(Value positive, Value negative) createSingletonBucket
(Value value) Iterates once over each distinct value.Iterates once over each distinct value.boolean
default void
handleSingleton
(Key key, Bucket bucket) default IMemoryView
<Value> Returns a (read-only) bucket of values associated with the given key.default IMemoryView
<Value> lookupAndRemoveAll
(Key key) Returns a (read-only) bucket of values associated with the given key, while simultaneously removing them.default boolean
lookupExists
(Key key) Returns true if there are any values associated with the given key.default IMemoryView
<Value> lookupUnsafe
(Object key) Returns a (read-only) bucket of values associated with the given key, which can be of any type.lowLevelGet
(Key key) Implementor shall bind to the low-level get() or equivalent of the underlying Key-to-Object maplowLevelGetUnsafe
(Object key) Implementor shall bind to the low-level get() or equivalent of the underlying Key-to-Object mapImplementor shall bind to the low-level keySet() or equivalent of the underlying Key-to-Object mapvoid
lowLevelPut
(Key key, Object valueOrBucket) Implementor shall bind to the low-level put() or equivalent of the underlying Key-to-Object maplowLevelPutIfAbsent
(Key key, Value value) Implementor shall bind to the low-level putIfAbsent() or equivalent of the underlying Key-to-Object maplowLevelRemove
(Key key) Implementor shall bind to the low-level remove() or equivalent of the underlying Key-to-Object mapint
Implementor shall bind to the low-level size() or equivalent of the underlying Key-to-Object mapImplementor shall bind to the low-level values() or equivalent of the underlying Key-to-Object mapboolean
boolean
removeFromBucket
(Bucket bucket, Value value, boolean throwIfImpossible) Decreases the multiplicity of the value in the bucket.default IMultiLookup.ChangeGranularity
removePair
(Key key, Value value) Removes key-value pair from the lookup structure, or fails if not possible.default IMultiLookup.ChangeGranularity
removePairInternal
(Key key, Value value, boolean throwIfImpossible) default IMultiLookup.ChangeGranularity
removePairOrNop
(Key key, Value value) Removes key-value pair from the lookup structure.default IMemoryView
<Value> yieldSingleton
(Value value) Methods inherited from interface tools.refinery.interpreter.matchers.util.IMultiLookup
clear, isEmpty, lookupOrEmpty, lookupUnsafeOrEmpty
-
Method Details
-
lowLevelGet
Implementor shall bind to the low-level get() or equivalent of the underlying Key-to-Object map -
lowLevelGetUnsafe
Implementor shall bind to the low-level get() or equivalent of the underlying Key-to-Object map -
lowLevelRemove
Implementor shall bind to the low-level remove() or equivalent of the underlying Key-to-Object map -
lowLevelPutIfAbsent
Implementor shall bind to the low-level putIfAbsent() or equivalent of the underlying Key-to-Object map -
lowLevelPut
Implementor shall bind to the low-level put() or equivalent of the underlying Key-to-Object map -
lowLevelValues
Implementor shall bind to the low-level values() or equivalent of the underlying Key-to-Object map -
lowLevelKeySet
Implementor shall bind to the low-level keySet() or equivalent of the underlying Key-to-Object map -
lowLevelSize
int lowLevelSize()Implementor shall bind to the low-level size() or equivalent of the underlying Key-to-Object map -
lookupExists
Description copied from interface:IMultiLookup
Returns true if there are any values associated with the given key.- Specified by:
lookupExists
in interfaceIMultiLookup<Key,
Value> - Parameters:
key
- a key for which associated values are sought
-
lookup
Description copied from interface:IMultiLookup
Returns a (read-only) bucket of values associated with the given key. Clients must not modify the returned bucket.- Specified by:
lookup
in interfaceIMultiLookup<Key,
Value> - Parameters:
key
- a key for which associated values are sought- Returns:
- null if key not found, a bucket of values otherwise
-
lookupAndRemoveAll
Description copied from interface:IMultiLookup
Returns a (read-only) bucket of values associated with the given key, while simultaneously removing them. Clients must not modify the returned bucket.- Specified by:
lookupAndRemoveAll
in interfaceIMultiLookup<Key,
Value> - Parameters:
key
- a key for which associated values are sought- Returns:
- a bucket of values, never null
-
lookupUnsafe
Description copied from interface:IMultiLookup
Returns a (read-only) bucket of values associated with the given key, which can be of any type. Clients must not modify the returned bucket.- Specified by:
lookupUnsafe
in interfaceIMultiLookup<Key,
Value> - Parameters:
key
- a key for which associated values are sought (may or may not be of Key type)- Returns:
- null if key not found, a bucket of values otherwise
-
addPair
Description copied from interface:IMultiLookup
Adds key-value pair to the lookup structure, or fails if not possible.If the addition would cause duplicates but the bucket type does not allow it (
CollectionsFactory.MemoryType.SETS
), the operation throws anIllegalStateException
.- Specified by:
addPair
in interfaceIMultiLookup<Key,
Value> - Returns:
- the granularity of the change
-
addPairOrNop
Description copied from interface:IMultiLookup
Adds key-value pair to the lookup structure.If the addition would cause duplicates but the bucket type does not allow it (
CollectionsFactory.MemoryType.SETS
), the operation is silently ignored andIMultiLookup.ChangeGranularity.DUPLICATE
is returned.- Specified by:
addPairOrNop
in interfaceIMultiLookup<Key,
Value> - Returns:
- the granularity of the change, or
IMultiLookup.ChangeGranularity.DUPLICATE
if addition would result in a duplicate and therefore ignored
-
addPairInternal
default IMultiLookup.ChangeGranularity addPairInternal(Key key, Value value, boolean throwIfImpossible) -
addPairPositiveMultiplicity
Description copied from interface:IMultiLookup
Updates multiplicity of key-value pair by a positive amount.PRE: count > 0
- Specified by:
addPairPositiveMultiplicity
in interfaceIMultiLookup<Key,
Value> - Returns:
- the granularity of the change
-
removePair
Description copied from interface:IMultiLookup
Removes key-value pair from the lookup structure, or fails if not possible.When attempting to remove a key-value pair with zero multiplicity from a non-delta bucket type (
CollectionsFactory.MemoryType.SETS
orCollectionsFactory.MemoryType.MULTISETS
}), anIllegalStateException
is thrown.- Specified by:
removePair
in interfaceIMultiLookup<Key,
Value> - Returns:
- the granularity of the change
-
removePairOrNop
Description copied from interface:IMultiLookup
Removes key-value pair from the lookup structure.When attempting to remove a key-value pair with zero multiplicity from a non-delta bucket type (
CollectionsFactory.MemoryType.SETS
orCollectionsFactory.MemoryType.MULTISETS
}), the operation is silently ignored andIMultiLookup.ChangeGranularity.DUPLICATE
is returned.- Specified by:
removePairOrNop
in interfaceIMultiLookup<Key,
Value> - Returns:
- the granularity of the change
-
removePairInternal
default IMultiLookup.ChangeGranularity removePairInternal(Key key, Value value, boolean throwIfImpossible) -
handleSingleton
-
distinctValues
Description copied from interface:IMultiLookup
Iterates once over each distinct value.- Specified by:
distinctValues
in interfaceIMultiLookup<Key,
Value>
-
distinctValuesStream
Description copied from interface:IMultiLookup
Iterates once over each distinct value.- Specified by:
distinctValuesStream
in interfaceIMultiLookup<Key,
Value>
-
distinctKeys
- Specified by:
distinctKeys
in interfaceIMultiLookup<Key,
Value> - Returns:
- the set of distinct keys that have values associated.
-
distinctKeysStream
- Specified by:
distinctKeysStream
in interfaceIMultiLookup<Key,
Value> - Returns:
- the set of distinct keys that have values associated.
-
countKeys
default int countKeys()- Specified by:
countKeys
in interfaceIMultiLookup<Key,
Value> - Returns:
- the number of distinct keys that have values associated.
-
negativesAllowed
boolean negativesAllowed()- Returns:
- iff negative multiplicites are allowed
-
duplicatesAllowed
boolean duplicatesAllowed()- Returns:
- iff larger-than-1 multiplicites are allowed
- Since:
- 2.3
-
addToBucket
Increases the multiplicity of the value in the bucket.- Returns:
- true iff non-duplicate
- Throws:
IllegalStateException
- if disallowed duplication and throwIfImpossible is specified
-
removeFromBucket
Decreases the multiplicity of the value in the bucket.- Returns:
- false if removing duplicate value
- Throws:
IllegalStateException
- if removing non-existing value (unless delta map) and throwIfImpossible is specified
-
asSingleton
Checks whether the bucket is a singleton, i.e. it contains a single value with multiplicity +1- Returns:
- the singleton value, or null if the bucket is not singleton
-
createSingletonBucket
- Returns:
- a new bucket consisting of a sole value
-
yieldSingleton
- Returns:
- a read-only bucket consisting of a sole value, to be returned to the user
-
createDeltaBucket
- Parameters:
positive
- the previously existing value, or null if the delta is to contain a single negative tuple- Returns:
- a new bucket consisting of a delta of two values
- Throws:
IllegalStateException
- if deltas not supported
-