Class IndexDefinition<T,​V>

  • Type Parameters:
    T - the type that this is an index for
    V - the type of the value used for indexing

    @ThreadSafe
    public abstract class IndexDefinition<T,​V>
    extends java.lang.Object
    A class representing an index for an IndexedSet. For example, if an indexed set stores inodes, and we want to be able to look them up by their "id" field, we would define an index like so:
     public class IndexDefinition<Inode, Long>() {
       @Override
       Long getFieldValue(Inode) {
         return Inode.getId();
       }
     }
     
    • Constructor Detail

      • IndexDefinition

        public IndexDefinition​(boolean isUnique)
        Constructs a new IndexDefinition instance.
        Parameters:
        isUnique - whether the index is unique. A unique index is an index where each index value only maps to one object; A non-unique index is an index where an index value can map to one or more objects.
    • Method Detail

      • isUnique

        public boolean isUnique()
        Returns:
        whether the index requires all field values to be unique
      • getFieldValue

        public abstract V getFieldValue​(T o)
        Gets the value of the field that serves as index.
        Parameters:
        o - the instance to get the field value from
        Returns:
        the field value
      • ofUnique

        public static <T,​V> IndexDefinition<T,​V> ofUnique​(java.util.function.Function<T,​V> definition)
        Creates a new, unique index definition.
        Type Parameters:
        T - the element type in the indexed set
        V - the index type
        Parameters:
        definition - the mapping function that maps an indexed element in the set to its index
        Returns:
        the unique definition
      • ofNonUnique

        public static <T,​V> IndexDefinition<T,​V> ofNonUnique​(java.util.function.Function<T,​V> definition)
        Creates a new, non-unique index definition.
        Type Parameters:
        T - the element type in the indexed set
        V - the index type
        Parameters:
        definition - the mapping function that maps an indexed element in the set to its index
        Returns:
        the non-unique definition