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 Details

    • none

      static CompositeKey none()
    • of

      static Object of(Object key)
      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 of CompositeKey. Wrapping is not necessary in this case, as the wrapper would do nothing but delegate Object.equals(Object) and Object.hashCode() to the wrapped key anyway. Avoiding the wrapper saves considerable memory and gets rid of a level of indirection.
    • of

      static <Key1_, Key2_> CompositeKey of(Key1_ key1, Key2_ key2)
    • ofMany

      static CompositeKey ofMany(Object... keys)
    • get

      <Key_> Key_ get(int id)
      Retrieves key at a given position.
      Type Parameters:
      Key_ - ComparisonIndexer will expect this to implement Comparable. EqualIndexer will treat items as the same if they are equal.
      Parameters:
      id - Maps to a single Indexer instance in the indexer chain.
      Returns:
      May be null if the key is null.