public sealed interface IndexKeys
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. There is no NoIndexKeys, as that is handled by none(). There is also no SingleIndexKeys, see of(Object) for rationale. TwoIndexKeys exists to avoid wrapping two keys with an entire array, with the use case of two keys still being relatively common. ThreeIndexKeys and higher are sufficiently rare for ManyIndexKeys to suffice.

  • Method Summary

    Modifier and Type
    Method
    Description
    <Key_> Key_
    get(int id)
    Retrieves key at a given position.
    static IndexKeys
     
    static Object
    of(Object key)
     
    static <Key1_, Key2_>
    IndexKeys
    of(Key1_ key1, Key2_ key2)
     
    static IndexKeys
    ofMany(Object... keys)
     
  • Method Details

    • none

      static IndexKeys 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 IndexKeys. 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_> IndexKeys of(Key1_ key1, Key2_ key2)
    • ofMany

      static IndexKeys 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. EqualsIndexer 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.