Interface CompositeKey
public sealed interface CompositeKey
Cached in tuples; each tuple carries its unique instance.
Instances are shallow immutable and implement Object.equals(Object) and Object.hashCode().
If two instances contain elements which are equal, they must be equal.
Instances should be obtained using none(),
of(Object),
of(Object, Object)
or ofMany(Object[]).
This interface only has two implementations,
giving the JVM simple bi-morphic call sites.
Use case of no key is handled by none().
There is also no case of a single key, see of(Object) for rationale.
BiCompositeKey exists to avoid wrapping two keys with an entire array,
with the use case of two keys still being relatively common.
TriCompositeKey and higher are rare enough for MegaCompositeKey to suffice.
-
Method Summary
Modifier and TypeMethodDescription<Key_> Key_get(int id) Retrieves key at a given position.static CompositeKeynone()static Objectstatic <Key1_,Key2_>
CompositeKeyof(Key1_ key1, Key2_ key2) static CompositeKey
-
Method Details
-
none
-
of
- Parameters:
key- may be null, typically in cases where the indexed property is a nullable planning variable.- Returns:
- When the key is not
null, returns the key itself, as opposed to some wrapping instance ofCompositeKey. Wrapping is not necessary in this case, as the wrapper would do nothing but delegateObject.equals(Object)andObject.hashCode()to the wrapped key anyway. Avoiding the wrapper saves considerable memory and gets rid of a level of indirection.
-
of
-
ofMany
-
get
<Key_> Key_ get(int id) Retrieves key at a given position.- Type Parameters:
Key_-ComparisonIndexerwill expect this to implementComparable.EqualIndexerwill treat items as the same if they are equal.- Parameters:
id- Maps to a singleIndexerinstance in the indexer chain.- Returns:
- May be null if the key is null.
-