Package alluxio.collections
Class IndexDefinition<T,V>
- java.lang.Object
-
- alluxio.collections.IndexDefinition<T,V>
-
- Type Parameters:
T
- the type that this is an index forV
- 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 anIndexedSet
. 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 Summary
Constructors Constructor Description IndexDefinition(boolean isUnique)
Constructs a newIndexDefinition
instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract V
getFieldValue(T o)
Gets the value of the field that serves as index.boolean
isUnique()
static <T,V>
IndexDefinition<T,V>ofNonUnique(java.util.function.Function<T,V> definition)
Creates a new, non-unique index definition.static <T,V>
IndexDefinition<T,V>ofUnique(java.util.function.Function<T,V> definition)
Creates a new, unique index definition.
-
-
-
Constructor Detail
-
IndexDefinition
public IndexDefinition(boolean isUnique)
Constructs a newIndexDefinition
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 setV
- 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 setV
- the index type- Parameters:
definition
- the mapping function that maps an indexed element in the set to its index- Returns:
- the non-unique definition
-
-