public abstract class NumberKeyIndexer<V> extends Indexer<Long,V>
Indexer
that distinguishes and identifies elements using number keys.
It assumes that elements are fully identifiable by numeric ID and treats object keys as a mere wrappers. The hash function is computed using (int)(key ^ (key >>> 32)) formula.
The NumberKeyIndexer itself is not serializable. However, concrete subclasses shall be serializable in order to support serialization of indexed set and map.
Modifier | Constructor and Description |
---|---|
protected |
NumberKeyIndexer()
Sole constructor; for invocation by subclass constructors, typically implicit.
|
Modifier and Type | Method and Description |
---|---|
abstract 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.
|
Long |
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.
|
int |
hashCodeByKey(long key)
Returns hash code for specified number key; called when performing operations using number keys.
|
int |
hashCodeByKey(Long key)
Returns hash code for specified object key; called when performing operations using object keys.
|
int |
hashCodeByValue(V value)
Returns hash code for specified value; called when performing value-based operations, including rehash.
|
boolean |
matchesByKey(long key,
V value)
Determines if specified number key matches specified value; called when performing operations using number keys.
|
boolean |
matchesByKey(Long key,
V value)
Determines if specified object key matches specified value; called when performing operations using object keys.
|
boolean |
matchesByValue(V new_value,
V old_value)
Determines if specified new value matches specified old value; called when performing value-based operations.
|
protected NumberKeyIndexer()
This implementation does nothing.
public int hashCodeByValue(V value)
This implementation computes hash function of
expression.getNumberKey
(value)
hashCodeByValue
in class Indexer<Long,V>
public boolean matchesByValue(V new_value, V old_value)
This implementation delegates to (
expression.getNumberKey
(new_value) == getNumberKey
(old_value))
matchesByValue
in class Indexer<Long,V>
public Long getObjectKey(V value)
This implementation delegates to Long.
expression.valueOf
(getNumberKey
(value))
getObjectKey
in class Indexer<Long,V>
UnsupportedOperationException
- if this strategy does not support object keys.public int hashCodeByKey(Long key)
This implementation computes hash function of key.
expression.longValue
()
hashCodeByKey
in class Indexer<Long,V>
UnsupportedOperationException
- if this strategy does not support object keys.public boolean matchesByKey(Long key, V value)
This implementation delegates to (key.
expression.longValue
() == getNumberKey
(value))
matchesByKey
in class Indexer<Long,V>
UnsupportedOperationException
- if this strategy does not support object keys.public abstract long getNumberKey(V value)
getNumberKey
in class Indexer<Long,V>
UnsupportedOperationException
- if this strategy does not support number keys.public int hashCodeByKey(long key)
This implementation computes hash function for specified key.
hashCodeByKey
in class Indexer<Long,V>
UnsupportedOperationException
- if this strategy does not support number keys.public boolean matchesByKey(long key, V value)
This implementation delegates to (key ==
expression.getNumberKey
(value))
matchesByKey
in class Indexer<Long,V>
UnsupportedOperationException
- if this strategy does not support number keys.Copyright © 2014 Devexperts. All Rights Reserved.