@FunctionalInterface public interface IndexerFunction<K,V> extends Serializable
IndexedSet
and IndexedMap
.
The IndexerFunction defines 3 equivalent ways to identify elements:
The IndexerFunction is not restricted to use explicit key concept for identification. Identity of an element may be defined by a number of attributes, specified in a value itself, in a template object, in a formal key object, or encoded in a number key. The IndexerFunction may use all these ways interchangeable to distinguish and identify elements.
Being a strategy, the IndexerFunction is required to be stateless, concurrent and thread-safe.
The IndexerFunction is a functional interface with a sole abstract method that shall be implemented
in order to use identification using explicit object key - no other methods are required to be
overridden in such simple cases.
There are two other functional interfaces IndexerFunction.IntKey
and IndexerFunction.LongKey
which are similarly designed with sole abstract methods to simplify identification using explicit number keys.
There is also a functional interface IndexerFunction.IdentityKey
which is similarly designed
with sole abstract method for cases when explicit object keys must be compared by reference rather than
using their equals
method.
The IndexerFunction is Serializable
, so that all concrete subclasses
shall be serializable in order to support serialization of indexed set and map.
Modifier and Type | Interface and Description |
---|---|
static class |
IndexerFunction.DefaultIdentityKey
Default identity strategy that treats values as their own keys (key == value).
|
static class |
IndexerFunction.DefaultIndexerFunction
Default strategy that treats values as their own keys (key == value).
|
static interface |
IndexerFunction.IdentityKey<K,V>
A specialized
IndexerFunction that distinguishes and identifies elements using identity comparison of object keys. |
static interface |
IndexerFunction.IntKey<V>
An
IndexerFunction that distinguishes and identifies elements using int keys. |
static interface |
IndexerFunction.LongKey<V>
An
IndexerFunction that distinguishes and identifies elements using long keys. |
Modifier and Type | Field and Description |
---|---|
static IndexerFunction |
DEFAULT
Default strategy that treats values as their own keys (key == value) and delegates to
Object.hashCode() and Object.equals(Object)
methods as appropriate. |
static IndexerFunction.IdentityKey |
DEFAULT_IDENTITY_KEY
Default strategy that treats values as their own keys (key == value) and uses object identity
to compare keys (see
IndexerFunction.IdentityKey for details). |
Modifier and Type | Method and Description |
---|---|
default long |
getNumberKey(V value)
Returns number key for specified value to be used for hashing and identification;
called when explicit number key is needed or when other methods delegate operations as specified.
|
K |
getObjectKey(V value)
Returns object key for specified value to be used for hashing and identification;
called when explicit object key is needed or when other methods delegate operations as specified.
|
default int |
hashCodeByKey(K key)
Returns hash code for specified object key; called when performing operations using object keys.
|
default int |
hashCodeByKey(long key)
Returns hash code for specified number key; called when performing operations using long keys.
|
default int |
hashCodeByValue(V value)
Returns hash code for specified value; called when performing value-based operations, including rehash.
|
default boolean |
matchesByKey(K key,
V value)
Determines if specified object key matches specified value; called when performing operations using object keys.
|
default boolean |
matchesByKey(long key,
V value)
Determines if specified number key matches specified value; called when performing operations using number keys.
|
default boolean |
matchesByValue(V newValue,
V oldValue)
Determines if specified new value matches specified old value; called when performing value-based operations.
|
static final IndexerFunction DEFAULT
Object.hashCode()
and Object.equals(Object)
methods as appropriate. This strategy does not support primitive keys.
This strategy basically turns IndexedSet
into plain hash set of objects and IndexedMap
into a self-reference mapping.
static final IndexerFunction.IdentityKey DEFAULT_IDENTITY_KEY
IndexerFunction.IdentityKey
for details).K getObjectKey(V value)
default int hashCodeByKey(K key)
This implementation delegates to
(key == null ? 0 : key.
expression.hashCode
())
default boolean matchesByKey(K key, V value)
This implementation delegates to
(key == null ?
expression.getObjectKey
(value) == null : key.equals
(getObjectKey
(value)))
default int hashCodeByValue(V value)
This implementation delegates to
expression.hashCodeByKey
(getObjectKey
(value))
default boolean matchesByValue(V newValue, V oldValue)
This implementation delegates to
expression.matchesByKey
(getObjectKey
(newValue), oldValue)
default long getNumberKey(V value)
This implementation delegates to
expression.hashCodeByKey
(((Number)getObjectKey
(value)).longValue
())
default int hashCodeByKey(long key)
This implementation delegates to
Long.
expression.hashCode
(key)
default boolean matchesByKey(long key, V value)
This implementation delegates to
(key ==
expression.getNumberKey
(value))
Copyright © 2002–2025 Devexperts LLC. All rights reserved.