swpchat.server
Class SpecializedCollection

java.lang.Object
  |
  +--swpchat.server.SpecializedCollection
Direct Known Subclasses:
ConnectionCollection

public abstract class SpecializedCollection
extends java.lang.Object

This class is a collection specialized in ClientConnection objects. The class is abstract, because you could not use the collection to receive objects of a special class, when you do not now the class at compile time. It means in detail, that to my oppinion it is not possible to do something as follows:

   Class objectClass = Class.forName("someClassName");
   
   public objectClass getClass() {
       return objectClass;
   }
 

This would fail to compile, because the Class objectClass is no valid Class.

Therefore we need to use a subclass of this class, which encapsulates for each special object to store, the correct method to receive the correct instances of the stored values of the map.

Author:
Christian Stüllenberg

Field Summary
private  java.util.HashMap map
          Map for the collection elements.
private  java.lang.Class objectClass
          The class which represents the special objects that could be stored in the map.
 
Constructor Summary
protected SpecializedCollection()
          Constructor to create a new map with only spezified objects as values.
 
Method Summary
 boolean containsKey(java.lang.String key)
          Method tests if a key is in the map.
protected  java.lang.Object getObject(java.lang.String key)
          Method tries to return the object identified by its key.
protected abstract  java.lang.Class getSpecialObjectClass()
           
 java.util.Iterator iterator()
          Method could be invoked to get all values
 java.util.Iterator keyIterator()
          Method could be invoked to get a keySet over all keys.
 void removeObject(java.lang.String key)
          Remove the object identified by its key from the collection.
 boolean tryToAddObject(java.lang.String key, java.lang.Object object)
          Method tries to add an object to the map and is threadsave
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

map

private java.util.HashMap map
Map for the collection elements.

objectClass

private java.lang.Class objectClass
The class which represents the special objects that could be stored in the map.
Constructor Detail

SpecializedCollection

protected SpecializedCollection()
Constructor to create a new map with only spezified objects as values.
Method Detail

getSpecialObjectClass

protected abstract java.lang.Class getSpecialObjectClass()

tryToAddObject

public boolean tryToAddObject(java.lang.String key,
                              java.lang.Object object)
Method tries to add an object to the map and is threadsave
Parameters:
key - represents the identifier for the object.
object - is the object to be added.

removeObject

public void removeObject(java.lang.String key)
                  throws NoSuchMemberException
Remove the object identified by its key from the collection.
Parameters:
key - identifies the object.
Throws:
NoSuchMemberException - if there is no object with the key in the collection.

iterator

public java.util.Iterator iterator()
Method could be invoked to get all values
Returns:
a Iterator containing any values of the map

keyIterator

public java.util.Iterator keyIterator()
Method could be invoked to get a keySet over all keys.
Returns:
a Iterator conaining all keys of the map.

containsKey

public boolean containsKey(java.lang.String key)
Method tests if a key is in the map.
Parameters:
{@link - java.lang.String} identifying the searched key.

getObject

protected java.lang.Object getObject(java.lang.String key)
                              throws NoSuchMemberException
Method tries to return the object identified by its key.
Parameters:
{@link - java.lang.String} identifying the object that is searched.
Returns:
the object