com.devexperts.util
Class NumberKeyIndexer<V>

java.lang.Object
  extended by com.devexperts.util.Indexer<Long,V>
      extended by com.devexperts.util.NumberKeyIndexer<V>

public abstract class NumberKeyIndexer<V>
extends Indexer<Long,V>

A subclass of 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.


Field Summary
 
Fields inherited from class com.devexperts.util.Indexer
DEFAULT
 
Constructor Summary
protected NumberKeyIndexer()
          Sole constructor; for invocation by subclass constructors, typically implicit.
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberKeyIndexer

protected NumberKeyIndexer()
Sole constructor; for invocation by subclass constructors, typically implicit.

This implementation does nothing.

Method Detail

hashCodeByValue

public int hashCodeByValue(V value)
Returns hash code for specified value; called when performing value-based operations, including rehash.

This implementation computes hash function of getNumberKey(value) expression.

Overrides:
hashCodeByValue in class Indexer<Long,V>

matchesByValue

public boolean matchesByValue(V new_value,
                              V old_value)
Determines if specified new value matches specified old value; called when performing value-based operations.

This implementation delegates to (getNumberKey(new_value) == getNumberKey(old_value)) expression.

Overrides:
matchesByValue in class Indexer<Long,V>

getObjectKey

public 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.

This implementation delegates to new Long(getNumberKey(value)) expression.

Specified by:
getObjectKey in class Indexer<Long,V>
Throws:
UnsupportedOperationException - if this strategy does not support object keys.

hashCodeByKey

public int hashCodeByKey(Long key)
Returns hash code for specified object key; called when performing operations using object keys.

This implementation computes hash function of ((Number)key).longValue() expression.

Overrides:
hashCodeByKey in class Indexer<Long,V>
Throws:
UnsupportedOperationException - if this strategy does not support object keys.

matchesByKey

public boolean matchesByKey(Long key,
                            V value)
Determines if specified object key matches specified value; called when performing operations using object keys.

This implementation delegates to (((Number)key).longValue() == getNumberKey(value)) expression.

Overrides:
matchesByKey in class Indexer<Long,V>
Throws:
UnsupportedOperationException - if this strategy does not support object keys.

getNumberKey

public 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.

Overrides:
getNumberKey in class Indexer<Long,V>
Throws:
UnsupportedOperationException - if this strategy does not support number keys.

hashCodeByKey

public int hashCodeByKey(long key)
Returns hash code for specified number key; called when performing operations using number keys.

This implementation computes hash function for specified key.

Overrides:
hashCodeByKey in class Indexer<Long,V>
Throws:
UnsupportedOperationException - if this strategy does not support number keys.

matchesByKey

public boolean matchesByKey(long key,
                            V value)
Determines if specified number key matches specified value; called when performing operations using number keys.

This implementation delegates to (key == getNumberKey(value)) expression.

Overrides:
matchesByKey in class Indexer<Long,V>
Throws:
UnsupportedOperationException - if this strategy does not support number keys.


Copyright © 2013 Devexperts. All Rights Reserved.