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 Object
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 and Description |
---|
IndexDefinition(boolean isUnique)
Constructs a new
IndexDefinition instance. |
Modifier and Type | Method and 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.
|
public IndexDefinition(boolean isUnique)
IndexDefinition
instance.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.public boolean isUnique()
public abstract V getFieldValue(T o)
o
- the instance to get the field value frompublic static <T,V> IndexDefinition<T,V> ofUnique(java.util.function.Function<T,V> definition)
T
- the element type in the indexed setV
- the index typedefinition
- the mapping function that maps an indexed element in the set to its indexpublic static <T,V> IndexDefinition<T,V> ofNonUnique(java.util.function.Function<T,V> definition)
T
- the element type in the indexed setV
- the index typedefinition
- the mapping function that maps an indexed element in the set to its indexCopyright © 2023. All Rights Reserved.