org.deduced.utilities
Class IdentityReferenceMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.apache.commons.collections.map.AbstractHashedMap
          extended by org.apache.commons.collections.map.AbstractReferenceMap
              extended by org.apache.commons.collections.map.ReferenceMap
                  extended by org.deduced.utilities.IdentityReferenceMap
All Implemented Interfaces:
java.io.Serializable, java.util.Map, org.apache.commons.collections.IterableMap

public class IdentityReferenceMap
extends org.apache.commons.collections.map.ReferenceMap

IdentityReferenceMap is used to create a map where the developer can control the way keys and values are referenced and how keys and values are checked for equality. For the reference type on keys and values, see the documentation for ReferenceMap. During construction, boolean flags indicate if keys and values should be compared with the equal function call or the "==" operator.

Author:
Steve McDuff
See Also:
Serialized Form

Nested Class Summary
protected static class IdentityReferenceMap.IdentityReferenceEntry
          IdentityReferenceEntry is used to create hash entries in the map.
 
Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractReferenceMap
org.apache.commons.collections.map.AbstractReferenceMap.ReferenceEntry
 
Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractHashedMap
org.apache.commons.collections.map.AbstractHashedMap.EntrySet, org.apache.commons.collections.map.AbstractHashedMap.EntrySetIterator, org.apache.commons.collections.map.AbstractHashedMap.HashEntry, org.apache.commons.collections.map.AbstractHashedMap.HashIterator, org.apache.commons.collections.map.AbstractHashedMap.HashMapIterator, org.apache.commons.collections.map.AbstractHashedMap.KeySet, org.apache.commons.collections.map.AbstractHashedMap.KeySetIterator, org.apache.commons.collections.map.AbstractHashedMap.Values, org.apache.commons.collections.map.AbstractHashedMap.ValuesIterator
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
private  boolean keyByInstance
          if true, keys are compared with the "==" operator.
private static long serialVersionUID
          serial ID
private  boolean valueByInstance
          if true, values are compared with the "==" operator.
 
Fields inherited from class org.apache.commons.collections.map.AbstractReferenceMap
HARD, keyType, purgeValues, SOFT, valueType, WEAK
 
Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap
data, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, entrySet, GETKEY_INVALID, GETVALUE_INVALID, keySet, loadFactor, MAXIMUM_CAPACITY, modCount, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID, size, threshold, values
 
Constructor Summary
IdentityReferenceMap(boolean setKeyByInstance, boolean setValueByInstance, int setKeyType, int setValueType)
          IdentityReferenceMap constructor
IdentityReferenceMap(boolean setKeyByInstance, boolean setValueByInstance, int setKeyType, int setValueType, int capacity, float setLoadFactor, boolean setPurgeValues)
          IdentityReferenceMap constructor
 
Method Summary
protected  org.apache.commons.collections.map.AbstractHashedMap.HashEntry createEntry(org.apache.commons.collections.map.AbstractHashedMap.HashEntry next, int hashCode, java.lang.Object key, java.lang.Object value)
          Creates an entry to store the data.
 boolean equals(java.lang.Object obj)
          Compares this map with another.
 int getKeyType()
          getKeyType
 int getValueType()
          getValueType
protected  int hash(java.lang.Object key)
          Gets the hash code for the key specified.
 int hashCode()
          (non-Javadoc)
protected  int hashKey(java.lang.Object key)
          hash a key.
protected  int hashValue(java.lang.Object value)
          hash a value.
protected  boolean isEqualKey(java.lang.Object key1, java.lang.Object key2)
          Compares two keys for equals.
protected  boolean isEqualValue(java.lang.Object value1, java.lang.Object value2)
          Compares two values for equals.
 boolean isKeyByInstance()
          is Key By Instance
 boolean isValueByInstance()
          is Value By Instance
 
Methods inherited from class org.apache.commons.collections.map.AbstractReferenceMap
clear, containsKey, containsValue, createEntrySetIterator, createKeySetIterator, createValuesIterator, doReadObject, doWriteObject, entrySet, get, getEntry, hashEntry, init, isEmpty, keySet, mapIterator, purge, purge, purgeBeforeRead, purgeBeforeWrite, put, remove, size, values
 
Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap
addEntry, addMapping, calculateNewCapacity, calculateThreshold, checkCapacity, clone, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entryValue, hashIndex, putAll, removeEntry, removeMapping, reuseEntry, toString, updateEntry
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
serial ID

See Also:
Constant Field Values

keyByInstance

private final boolean keyByInstance
if true, keys are compared with the "==" operator. If false, they are compared with a call to the equal method.


valueByInstance

private final boolean valueByInstance
if true, values are compared with the "==" operator. If false, they are compared with a call to the equal method.

Constructor Detail

IdentityReferenceMap

public IdentityReferenceMap(boolean setKeyByInstance,
                            boolean setValueByInstance,
                            int setKeyType,
                            int setValueType)
IdentityReferenceMap constructor

Parameters:
setKeyByInstance - if true, keys are compared with the "==" operator. If false, they are compared with a call to the equal method.
setValueByInstance - if true, keys are compared with the "==" operator. If false, they are compared with a call to the equal method.
setKeyType - the type of reference to use for keys; must be AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK
setValueType - the type of reference to use for values; must be AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK

IdentityReferenceMap

public IdentityReferenceMap(boolean setKeyByInstance,
                            boolean setValueByInstance,
                            int setKeyType,
                            int setValueType,
                            int capacity,
                            float setLoadFactor,
                            boolean setPurgeValues)
IdentityReferenceMap constructor

Parameters:
setKeyByInstance - if true, keys are compared with the "==" operator. If false, they are compared with a call to the equal method.
setValueByInstance - if true, keys are compared with the "==" operator. If false, they are compared with a call to the equal method.
setKeyType - the type of reference to use for keys; must be AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK
setValueType - the type of reference to use for values; must be AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK
capacity - the initial capacity for the map
setLoadFactor - the load factor for the map
setPurgeValues - should the value be automatically purged when the key is garbage collected
Method Detail

isKeyByInstance

public boolean isKeyByInstance()
is Key By Instance

Returns:
true if keys are referenced by instance

isValueByInstance

public boolean isValueByInstance()
is Value By Instance

Returns:
true if values are referenced by instance

getValueType

public int getValueType()
getValueType

Returns:
how values are held by the map : AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK

getKeyType

public int getKeyType()
getKeyType

Returns:
how keys are held by the map : AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK

hash

protected int hash(java.lang.Object key)
Gets the hash code for the key specified. This implementation uses the identity hash code if keys are by value or the .

Overrides:
hash in class org.apache.commons.collections.map.AbstractHashedMap
Parameters:
key - the key to get a hash code for
Returns:
the hash code

isEqualKey

protected boolean isEqualKey(java.lang.Object key1,
                             java.lang.Object key2)
Compares two keys for equals. This implementation uses ==.

Overrides:
isEqualKey in class org.apache.commons.collections.map.AbstractReferenceMap
Parameters:
key1 - the first key to compare
key2 - the second key to compare
Returns:
true if equal by identity

isEqualValue

protected boolean isEqualValue(java.lang.Object value1,
                               java.lang.Object value2)
Compares two values for equals. This implementation uses ==.

Overrides:
isEqualValue in class org.apache.commons.collections.map.AbstractHashedMap
Parameters:
value1 - the first value to compare
value2 - the second value to compare
Returns:
true if equal by identity

createEntry

protected org.apache.commons.collections.map.AbstractHashedMap.HashEntry createEntry(org.apache.commons.collections.map.AbstractHashedMap.HashEntry next,
                                                                                     int hashCode,
                                                                                     java.lang.Object key,
                                                                                     java.lang.Object value)
Creates an entry to store the data. This implementation creates an IdentityEntry instance.

Overrides:
createEntry in class org.apache.commons.collections.map.AbstractReferenceMap
Parameters:
next - the next entry in sequence
hashCode - the hash code to use
key - the key to store
value - the value to store
Returns:
the newly created entry

hashKey

protected int hashKey(java.lang.Object key)
hash a key. The output will depend on the keyByInstance flag.

Parameters:
key - the key to hash.
Returns:
the key hash code.

hashValue

protected int hashValue(java.lang.Object value)
hash a value. The output will depend on the valueByInstance flag.

Parameters:
value - the value to hash.
Returns:
the value hash code.

equals

public boolean equals(java.lang.Object obj)
Compares this map with another.

Specified by:
equals in interface java.util.Map
Overrides:
equals in class org.apache.commons.collections.map.AbstractHashedMap
Parameters:
obj - the object to compare to
Returns:
true if equal

hashCode

public int hashCode()
(non-Javadoc)

Specified by:
hashCode in interface java.util.Map
Overrides:
hashCode in class org.apache.commons.collections.map.AbstractHashedMap
See Also:
AbstractHashedMap.hashCode()