gov.sandia.cognition.framework
Class DefaultSemanticIdentifierMap

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.framework.DefaultSemanticIdentifierMap
All Implemented Interfaces:
SemanticIdentifierMap, CloneableSerializable, Serializable, Cloneable

public class DefaultSemanticIdentifierMap
extends AbstractCloneableSerializable
implements SemanticIdentifierMap

The DefaultSemanticIdentifierMap is an implementation of SemanticIdentifierMap that is backed by a HashMap (a hashtable).

Since:
1.0
Author:
Justin Basilico, Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
DefaultSemanticIdentifierMap()
          Creates a new instance of DefaultSemanticIdentifierMap.
 
Method Summary
 SemanticIdentifier addLabel(SemanticLabel label)
          Adds a SemanticLabel to the map, or returns an existing SemanticIdentifier if already in the map
 ArrayList<SemanticIdentifier> addLabels(Collection<SemanticLabel> labels)
          Adds a list of SemanticLabels to the map, returning the list of the corresponding SemanticIdentifiers for the given SemanticLabels.
 void addSemanticIdentifierMapListener(SemanticIdentifierMapListener listener)
          Adds a listener to this semantic identifier map.
 DefaultSemanticIdentifierMap clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 SemanticIdentifier findIdentifier(SemanticLabel label)
          Queries into the map to find a SemanticLabel
protected  void fireSemanticIdentifierAddedEvent(SemanticIdentifier identifier)
          Fires off a SemanticIdentifierMapEvent of type SemanticIdentifierAdded for the given identifier.
protected  int getIdentifierCounter()
          Getter for identifierCounter.
 Collection<SemanticIdentifier> getIdentifiers()
          Gets all the SemanticIdentifiers in the map.
protected  LinkedList<SemanticIdentifierMapListener> getListeners()
          Getter for listeners.
protected  LinkedHashMap<SemanticLabel,SemanticIdentifier> getMapping()
          Getter for mapping.
protected  int getNewIdentifier()
          Gets a new identifier for a new label.
 void removeSemanticIdentifierMapListener(SemanticIdentifierMapListener listener)
          Removes a listener from this semantic identifier map.
protected  void setIdentifierCounter(int identifierCounter)
          Setter for identifier Counter.
protected  void setMapping(LinkedHashMap<SemanticLabel,SemanticIdentifier> mapping)
          Sets the mapping used by the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSemanticIdentifierMap

public DefaultSemanticIdentifierMap()
Creates a new instance of DefaultSemanticIdentifierMap.

Method Detail

clone

public DefaultSemanticIdentifierMap clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

findIdentifier

public SemanticIdentifier findIdentifier(SemanticLabel label)
Queries into the map to find a SemanticLabel

Specified by:
findIdentifier in interface SemanticIdentifierMap
Parameters:
label - SemanticLabel to query into the map.
Returns:
SemanticIdentifier associated with SemanticLabel, or null if not found.

addLabel

public SemanticIdentifier addLabel(SemanticLabel label)
Adds a SemanticLabel to the map, or returns an existing SemanticIdentifier if already in the map

Specified by:
addLabel in interface SemanticIdentifierMap
Parameters:
label - SemanticLabel to add to or retrieve from the map.
Returns:
SemanticIdentifer or null if unable to add.
Throws:
IllegalArgumentException - if label is null.

addLabels

public ArrayList<SemanticIdentifier> addLabels(Collection<SemanticLabel> labels)
Adds a list of SemanticLabels to the map, returning the list of the corresponding SemanticIdentifiers for the given SemanticLabels.

Specified by:
addLabels in interface SemanticIdentifierMap
Parameters:
labels - The SemanticLabels to add.
Returns:
The list of SemanticIdentifiers corresponding to the given SemanticLabels.
Throws:
IllegalArgumentException - If one of the labels is null.

getIdentifiers

public Collection<SemanticIdentifier> getIdentifiers()
Gets all the SemanticIdentifiers in the map.

Specified by:
getIdentifiers in interface SemanticIdentifierMap
Returns:
All the SemanticIdentifiers in the map.

getNewIdentifier

protected int getNewIdentifier()
Gets a new identifier for a new label.

Returns:
A new identifier.

addSemanticIdentifierMapListener

public void addSemanticIdentifierMapListener(SemanticIdentifierMapListener listener)
Adds a listener to this semantic identifier map.

Specified by:
addSemanticIdentifierMapListener in interface SemanticIdentifierMap
Parameters:
listener - The listener to add.

removeSemanticIdentifierMapListener

public void removeSemanticIdentifierMapListener(SemanticIdentifierMapListener listener)
Removes a listener from this semantic identifier map.

Specified by:
removeSemanticIdentifierMapListener in interface SemanticIdentifierMap
Parameters:
listener - The listener to remove.

fireSemanticIdentifierAddedEvent

protected void fireSemanticIdentifierAddedEvent(SemanticIdentifier identifier)
Fires off a SemanticIdentifierMapEvent of type SemanticIdentifierAdded for the given identifier.

Parameters:
identifier - The identifier that was added.

setMapping

protected void setMapping(LinkedHashMap<SemanticLabel,SemanticIdentifier> mapping)
Sets the mapping used by the object.

Parameters:
mapping - The new mapping.

getIdentifierCounter

protected int getIdentifierCounter()
Getter for identifierCounter.

Returns:
The counter of identifiers, which ensures that each one is unique.

setIdentifierCounter

protected void setIdentifierCounter(int identifierCounter)
Setter for identifier Counter.

Parameters:
identifierCounter - The counter of identifiers, which ensures that each one is unique.

getMapping

protected LinkedHashMap<SemanticLabel,SemanticIdentifier> getMapping()
Getter for mapping.

Returns:
The mapping of semantic labels to semantic identifiers.

getListeners

protected LinkedList<SemanticIdentifierMapListener> getListeners()
Getter for listeners.

Returns:
The listeners for this map.