net.walend.lyophil.collection
Class AbstractHashMapToFreezables

java.lang.Object
  |
  +--net.walend.lyophil.collection.AbstractHashMapToFreezables
All Implemented Interfaces:
HasState, Map, MapToFreezables
Direct Known Subclasses:
HashMapToFreezables, MutableHashMapToFreezables

public abstract class AbstractHashMapToFreezables
extends java.lang.Object
implements MapToFreezables

This Map maps any Object as a key to a Freezable. It stores a mapping of keys to Freezables, and uses the Freezables to get the identifiers. Use this Map's subclasses when the Map has few entries, or when the application does not have time to go to the Freezer to get the Freezable.

Since:
20010712
Author:
David Walend

Nested Class Summary
private  class AbstractHashMapToFreezables.IDIterator
           
private  class AbstractHashMapToFreezables.IteratorOfFreezables
           
 
Field Summary
private  MutableMap keysToFreezables
           
 
Fields inherited from interface net.walend.collection.Map
EMPTY
 
Constructor Summary
protected AbstractHashMapToFreezables()
           
protected AbstractHashMapToFreezables(Identitor identitor)
           
protected AbstractHashMapToFreezables(Identitor identitor, int capacity)
           
protected AbstractHashMapToFreezables(Identitor identitor, int capacity, float loadFactor)
           
protected AbstractHashMapToFreezables(int capacity)
           
protected AbstractHashMapToFreezables(int capacity, float loadFactor)
           
protected AbstractHashMapToFreezables(Map map)
           
protected AbstractHashMapToFreezables(java.util.Map map)
           
 
Method Summary
protected  void clear()
          Removes all key, value pairs from this Map.
 boolean containsAll(Map c)
          Returns true if this collection contains all of the Objects in the specified collection.
 boolean containsIdentifier(java.io.Serializable identifier)
          Returns true if one of the keys in the map is associated with identifier.
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains an entry for key.
 boolean containsValue(java.lang.Object value)
          Returns true if this map contains value.
 java.lang.Object get(java.lang.Object key)
          Returns the value for the key.
 Collection getdentifiers()
          Returns a collection of all the identifiers.
protected  Freezable getFreezableForID(java.io.Serializable id)
           
protected  Freezer getFreezer()
           
 java.io.Serializable getIdentifier(java.lang.Object key)
          Returns the idetnifier associated with key, or null if no identifier is associated with the key.
 Identitor getIdentitor()
          Returns the Identitor for this Map.
protected  java.io.Serializable getIDForFreezable(Freezable freezy)
           
 java.util.Map getJavaMap()
          Return a java.util.Collection of these Objects.
 Set getKeys()
          Returns an immutable shallow copy of the Set of keys.
 java.lang.Class getPrincipleInterface()
          Returns the class's principle interface for state comparisons.
 Collection getValues()
          Returns an immutable shallow copy of the Collection of values.
 java.util.Iterator identifierIterator()
          Returns an iterator over the identifiers.
 boolean isEmpty()
          Returns true if this Map has no entries.
 java.util.Iterator keyIterator()
          Returns an iterator over the keys.
 Map keysToIdentifiers()
          Creates a new Map which maps the keys to their identifiers.
protected  java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
protected  void putAll(Map map)
           
protected  void putAllIdentifiers(Map map)
           
protected  java.lang.Object putIdentifier(java.lang.Object key, java.io.Serializable identifier)
           
protected  java.lang.Object remove(java.lang.Object key)
          Removes the key, value pair from this Map.
 boolean sameContentsAs(Map c)
          Returns true if this Collection's contents are equal to c's.
 boolean sameStateAs(HasState victem)
          If two HasStates have the same internal state, return true.
 int size()
          Returns the number of key-value pairs in this map.
 java.lang.String toString()
           
 FreezableIterator valueFreezableIterator()
          Returns a FreezableIterator over the values so that you can work with both identifiers and Freezables.
 java.util.Iterator valueIterator()
          Returns an iterator over the values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

keysToFreezables

private MutableMap keysToFreezables
Constructor Detail

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables(Identitor identitor,
                                      int capacity,
                                      float loadFactor)

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables(int capacity,
                                      float loadFactor)

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables(Identitor identitor,
                                      int capacity)

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables(int capacity)

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables(Identitor identitor)

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables()

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables(Map map)

AbstractHashMapToFreezables

protected AbstractHashMapToFreezables(java.util.Map map)
Method Detail

getIdentitor

public Identitor getIdentitor()
Returns the Identitor for this Map.

Specified by:
getIdentitor in interface Map

size

public int size()
Returns the number of key-value pairs in this map.

Specified by:
size in interface Map

isEmpty

public boolean isEmpty()
Returns true if this Map has no entries.

Specified by:
isEmpty in interface Map

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this map contains an entry for key.

Specified by:
containsKey in interface Map
Throws:
java.lang.NullPointerException - if key is null.

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this map contains value.

Specified by:
containsValue in interface Map
Throws:
java.lang.NullPointerException - if value is null.

getIDForFreezable

protected java.io.Serializable getIDForFreezable(Freezable freezy)

get

public java.lang.Object get(java.lang.Object key)
Returns the value for the key. Returns null if the Map contains no value for key.

Specified by:
get in interface Map
Throws:
java.lang.NullPointerException - if the key is null.

getKeys

public Set getKeys()
Returns an immutable shallow copy of the Set of keys.

Specified by:
getKeys in interface Map

getValues

public Collection getValues()
Returns an immutable shallow copy of the Collection of values.

Specified by:
getValues in interface Map

keyIterator

public java.util.Iterator keyIterator()
Returns an iterator over the keys.

Specified by:
keyIterator in interface Map

valueIterator

public java.util.Iterator valueIterator()
Returns an iterator over the values.

Specified by:
valueIterator in interface Map

containsAll

public boolean containsAll(Map c)
Returns true if this collection contains all of the Objects in the specified collection. This method uses the contains() method.

Specified by:
containsAll in interface Map

sameContentsAs

public boolean sameContentsAs(Map c)
Returns true if this Collection's contents are equal to c's.

Specified by:
sameContentsAs in interface Map

getJavaMap

public java.util.Map getJavaMap()
Return a java.util.Collection of these Objects.

Specified by:
getJavaMap in interface Map

containsIdentifier

public boolean containsIdentifier(java.io.Serializable identifier)
Description copied from interface: MapToFreezables
Returns true if one of the keys in the map is associated with identifier.

Specified by:
containsIdentifier in interface MapToFreezables

getIdentifier

public java.io.Serializable getIdentifier(java.lang.Object key)
Description copied from interface: MapToFreezables
Returns the idetnifier associated with key, or null if no identifier is associated with the key.

Specified by:
getIdentifier in interface MapToFreezables

getdentifiers

public Collection getdentifiers()
Description copied from interface: MapToFreezables
Returns a collection of all the identifiers.

Specified by:
getdentifiers in interface MapToFreezables

identifierIterator

public java.util.Iterator identifierIterator()
Description copied from interface: MapToFreezables
Returns an iterator over the identifiers.

Specified by:
identifierIterator in interface MapToFreezables

keysToIdentifiers

public Map keysToIdentifiers()
Description copied from interface: MapToFreezables
Creates a new Map which maps the keys to their identifiers.

Specified by:
keysToIdentifiers in interface MapToFreezables

put

protected java.lang.Object put(java.lang.Object key,
                               java.lang.Object value)

remove

protected java.lang.Object remove(java.lang.Object key)
Removes the key, value pair from this Map. Returns the value associated with key, or null if no value was associated.

Throws:
java.lang.NullPointerException - if the key is null.

putAll

protected void putAll(Map map)

clear

protected void clear()
Removes all key, value pairs from this Map.


getFreezer

protected Freezer getFreezer()

getFreezableForID

protected Freezable getFreezableForID(java.io.Serializable id)

putIdentifier

protected java.lang.Object putIdentifier(java.lang.Object key,
                                         java.io.Serializable identifier)

putAllIdentifiers

protected void putAllIdentifiers(Map map)

valueFreezableIterator

public FreezableIterator valueFreezableIterator()
Returns a FreezableIterator over the values so that you can work with both identifiers and Freezables.

Specified by:
valueFreezableIterator in interface MapToFreezables

getPrincipleInterface

public java.lang.Class getPrincipleInterface()
Returns the class's principle interface for state comparisons. If two objects have different principle interfaces, they never have the same state.

Specified by:
getPrincipleInterface in interface HasState

sameStateAs

public boolean sameStateAs(HasState victem)
If two HasStates have the same internal state, return true.

For objects with subobjects, Generally this method should only return true if the internal objects are equal. Implement a contentsHaveSameState() method to determine if the contents have the same state.

Specified by:
sameStateAs in interface HasState

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright (c) 2000, 2001, David Walend