Interface Indexer<T>
- Type Parameters:
T- The element type. Often a tuple. For example forfrom(A).join(B), the tuple isUniTuple<A>xorUniTuple<B>. For example forBi<A, B>.join(C), the tuple isBiTuple<A, B>xorUniTuple<C>.
- All Known Subinterfaces:
IndexerBackend<T>
- All Known Implementing Classes:
LinkedListIndexerBackend,RandomAccessIndexerBackend
An indexer for entity or fact
X,
maps a property or a combination of properties of X, denoted by compositeKey,
to all instances of X that match those properties,
depending on the indexer type (equal, lower than, contain, ...).
For example for {Lesson(id=1, room=A), Lesson(id=2, room=B), Lesson(id=3, room=A)},
calling visit(room=A) would visit lesson 1 and 3.
The fact X is wrapped in a Tuple, because the TupleState is needed by clients of
forEach(Object, Consumer).
Some indexer types (such as contain, containedIn, ...) have two different key types (modify key vs query key), depending on the operation type (modify operation vs query operation). For example, for a contain indexer the modify key is a collection, but the query key is not.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidQuery operation.booleanSome indexers can be empty (size 0 and an empty forEach for all keys) but not yet removable.Gets an iterator for the given composite key.Modify operation.randomIterator(Object queryCompositeKey, Random workingRandom) Iterator which picks elements randomly.randomIterator(Object queryCompositeKey, Random workingRandom, Predicate<T> filter) As defined byrandomIterator(Object, Random), but only returning elements matching the given filter.voidModify operation.intQuery operation.
-
Method Details
-
put
Modify operation.- Parameters:
modifyCompositeKey- modify composite keytuple- never null- Returns:
- the entry to allow remove it from the index directly
-
remove
Modify operation. Must not be called duringforEach(Object, Consumer)and invalidates anyiterator(Object)obtained before.- Parameters:
modifyCompositeKey- modify composite keyentry- never null
-
size
Query operation.- Parameters:
queryCompositeKey- query composite key- Returns:
- at least 0
-
forEach
Query operation.- Parameters:
queryCompositeKey- query composite keytupleConsumer- never null
-
iterator
Gets an iterator for the given composite key. The returned iterator does not supportIterator.remove().- Parameters:
queryCompositeKey- composite key uniquely identifying the backend or a set of backends- Returns:
- possibly empty iterator for the given composite key
-
isRemovable
boolean isRemovable()Some indexers can be empty (size 0 and an empty forEach for all keys) but not yet removable.- Returns:
- true if empty and all put() calls had a remove() call
-
randomIterator
Iterator which picks elements randomly. Selection probability is uniform over all elements for the given composite key. By callingIterator.remove(), the element is removed never to be returned again by this iterator. However, it is not removed from the index itself; the only way to remove from the index is to callremove(Object, ListEntry), which will make any existing iterators invalid.- Parameters:
queryCompositeKey- composite key uniquely identifying the backend or a set of backendsworkingRandom- used to pick random elements- Returns:
- iterator for the given composite key, possibly empty
-
randomIterator
As defined byrandomIterator(Object, Random), but only returning elements matching the given filter.
-