- Type Parameters:
V- The type of values stored in the collection.
public interface ValueIndexer<V>
A collection that stores values and assigns them a unique
long identifier.
The engine uses this API to store fact field values expressed as Object[].
Aside from hashing and equality, the default implementation of this interface essentially works as shown below:
private final AtomicLong indexer = new AtomicLong(0);
private final Map<Object[], Long> mapping = new ConcurrentHashMap<>();
private final Map<Long, Object[]> reverse = new ConcurrentHashMap<>();
public long getOrCreateId(Object[] fieldValues) {
return mapping.computeIfAbsent(fieldValues, k -> {
long id = indexer.getAndIncrement();
reverse.put(id, k);
return id;
});
}
When a RuleSession is created, the engine will generate
as many instances of this interface as there are logical types in the ruleset. The implementations
must be thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAssigns the given value to the specified identifier.voidclear()Clears the internally stored mapping.delete(long id) Deletes the value associated with the given unique identifier.get(long id) Retrieves the value associated with the given unique identifier.longgetOrCreateId(V value) Returns the unique identifier for the specified value, creating a new one if it does not already exist.
-
Method Details
-
getOrCreateId
Returns the unique identifier for the specified value, creating a new one if it does not already exist.- Parameters:
value- The value for which the identifier is to be retrieved or created.- Returns:
- The unique
longidentifier assigned to the specified value.
-
get
Retrieves the value associated with the given unique identifier.- Parameters:
id- The unique identifier for the desired value.- Returns:
- The value associated with the specified identifier, or
nullif no such value exists.
-
delete
Deletes the value associated with the given unique identifier.- Parameters:
id- The unique identifier for the value to be deleted.- Returns:
- The value that was associated with the specified identifier, or
nullif no such value exists.
-
assignId
Assigns the given value to the specified identifier.- Parameters:
id- The unique identifier for the value.value- The value to be associated with the specified identifier.
-
clear
void clear()Clears the internally stored mapping.
-