com.devexperts.util
Class IdentityIndexer<K,V>

java.lang.Object
  extended by com.devexperts.util.Indexer<K,V>
      extended by com.devexperts.util.IdentityIndexer<K,V>

public abstract class IdentityIndexer<K,V>
extends Indexer<K,V>

A subclass of Indexer that distinguishes and identifies elements using identity comparison of object keys.

It uses System.identityHashCode(Object) method instead of Object.hashCode() method to compute hashcode and reference comparison instead of Object.equals(Object) method to determine identity.

The IdentityIndexer 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 IdentityIndexer()
          Sole constructor; for invocation by subclass constructors, typically implicit.
 
Method Summary
 int hashCodeByKey(K 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(K 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 com.devexperts.util.Indexer
getNumberKey, getObjectKey, hashCodeByKey, matchesByKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IdentityIndexer

protected IdentityIndexer()
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 delegates to System.identityHashCode(getObjectKey(value)) expression.

Overrides:
hashCodeByValue in class Indexer<K,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 (getObjectKey(new_value) == getObjectKey(old_value)) expression.

Overrides:
matchesByValue in class Indexer<K,V>

hashCodeByKey

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

This implementation delegates to System.identityHashCode(key) expression.

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

matchesByKey

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

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

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


Copyright © 2013 Devexperts. All Rights Reserved.