edu.memphis.ccrg.lida.framework.shared
Class UnmodifiableNodeStructureImpl

java.lang.Object
  extended by edu.memphis.ccrg.lida.framework.shared.UnmodifiableNodeStructureImpl
All Implemented Interfaces:
NodeStructure

public class UnmodifiableNodeStructureImpl
extends java.lang.Object
implements NodeStructure

An immutable NodeStructureImpl. Throws UnsupportedOperationException if any methods which modify NodeStructureImpl are called.


Constructor Summary
UnmodifiableNodeStructureImpl(NodeStructure sourceNodeStructure)
          Default Constructor.
UnmodifiableNodeStructureImpl(NodeStructure sourceNodeStructure, boolean shouldCopy)
          Default Constructor.
 
Method Summary
 Link addDefaultLink(int idSource, ExtendedId idSink, LinkCategory type, double activation, double removalThreshold)
          Creates and adds a new Link with specified attributes.
 Link addDefaultLink(int idSource, int idSink, LinkCategory type, double activation, double removalThreshold)
          Creates and adds a new Link with specified attributes.
 Link addDefaultLink(Link l)
          Copies specified Link and then adds the copy to this NodeStructure.
 Link addDefaultLink(Node source, Linkable sink, LinkCategory category, double activation, double removalThreshold)
           
 java.util.Collection<Link> addDefaultLinks(java.util.Collection<Link> links)
          Copies specified Links and then adds the copies to this NodeStructure.
 Node addDefaultNode(Node n)
          Adds a COPY of specified Node to this NodeStructure.
 java.util.Collection<Node> addDefaultNodes(java.util.Collection<Node> nodes)
           
 Link addLink(Link l, java.lang.String linkType)
          Adds copy of specified Link.
 Node addNode(Node n, java.lang.String factoryType)
          Add a Node of a specified factory type to this NodeStructure
 void clearLinks()
          Removes all links from this NodeStructure
 void clearNodeStructure()
          Removes all nodes and links from this nodestructure
 boolean containsLink(ExtendedId id)
          Returns whether this NodeStructure contains Link with specified ExtendedId.
 boolean containsLink(Link l)
          Returns whether this NodeStructure contains specified Link.
 boolean containsLinkable(ExtendedId id)
          Returns whether this NodeStructure contains Linkable with specified ExtendedId.
 boolean containsLinkable(Linkable l)
          Returns whether this NodeStructure contains specified Linkable.
 boolean containsNode(ExtendedId id)
          Returns whether this NodeStructure contains Node with specified ExtendedId.
 boolean containsNode(int id)
          Returns whether this NodeStructure contains Node with specified id.
 boolean containsNode(Node n)
          Returns whether this NodeStructure contains specified Node.
 NodeStructure copy()
          Returns a deep copy of this NodeStructure
 void decayNodeStructure(long ticks)
          Decays the Linkables of this NodeStructure.
 boolean equals(java.lang.Object o)
          Returns true if both NodeStructures have the same nodes and links.
 java.util.Set<Link> getAttachedLinks(Linkable l)
          Gets all Links directly connected to specified Linkable.
 java.util.Set<Link> getAttachedLinks(Linkable linkable, LinkCategory cat)
          Gets all Links directly connected to specified Linkable with specified LinkCategory
 java.util.Map<Linkable,Link> getConnectedSinks(Node n)
          Finds and returns a Map of all sink Linkables connected to specified Node.
 java.util.Map<Node,Link> getConnectedSources(Linkable linkable)
          Finds and returns a Map of all source Nodes connected to specified Linkable.
 java.lang.String getDefaultLinkType()
          Gets defaultLinkType
 java.lang.String getDefaultNodeType()
          Gets defaultNodeType
 Link getLink(ExtendedId ids)
          Gets Link with specified ExtendedId if present.
 Linkable getLinkable(ExtendedId eid)
          Gets Linkable with specified ExtendedId
 int getLinkableCount()
          Returns count of Linkables
 java.util.Map<Linkable,java.util.Set<Link>> getLinkableMap()
          Returns linkableMap
 java.util.Collection<Linkable> getLinkables()
          Returns all Linkables, all Nodes and Links, in this NodeStructure
 int getLinkCount()
          returns a count of links
 java.util.Collection<Link> getLinks()
          Returns the Links of this NodeStructure
 java.util.Set<Link> getLinks(LinkCategory cat)
          Returns all Links of this NodeStructure with specified LinkCategory
 Node getNode(ExtendedId eid)
          Returns a copy of the node in this nodestructure with specified ExtendedId
 Node getNode(int id)
          Returns a copy of the node in this nodestructure with specified id
 int getNodeCount()
          Returns a count of nodes
 java.util.Collection<Node> getNodes()
          Returns all Nodes
 int hashCode()
           
 void mergeWith(NodeStructure ns)
          Merges specified NodeStructure into this one.
 void removeLink(Link l)
          Removes specified Link if present.
 void removeLinkable(ExtendedId id)
          Removes Linkable with specified ExtendedId if present.
 void removeLinkable(Linkable l)
          Removes specified Linkable if present.
 void removeNode(Node n)
          Removes specified Node if present.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnmodifiableNodeStructureImpl

public UnmodifiableNodeStructureImpl(NodeStructure sourceNodeStructure)
Default Constructor.

Parameters:
sourceNodeStructure - supplied NodeStructure

UnmodifiableNodeStructureImpl

public UnmodifiableNodeStructureImpl(NodeStructure sourceNodeStructure,
                                     boolean shouldCopy)
Default Constructor.

Parameters:
sourceNodeStructure - supplied NodeStructure
shouldCopy - If true, the supplied NodeStructure will be copied. Otherwise supplied NodeStructure will be used directly.
Method Detail

equals

public boolean equals(java.lang.Object o)
Returns true if both NodeStructures have the same nodes and links.

Overrides:
equals in class java.lang.Object
Parameters:
o - Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

copy

public NodeStructure copy()
Description copied from interface: NodeStructure
Returns a deep copy of this NodeStructure

Specified by:
copy in interface NodeStructure
Returns:
NodeStructure

addDefaultLink

public Link addDefaultLink(Link l)
Description copied from interface: NodeStructure
Copies specified Link and then adds the copy to this NodeStructure. If Link with the same id already exists then the old Link's activation is updated. Copied link will have the default link type of this NodeStructure when it is added.

Specified by:
addDefaultLink in interface NodeStructure
Parameters:
l - Link to copy and add.
Returns:
the copied Link that is actually stored in this NodeStructure, or the existing link that is updated. If Link cannot be added then null is returned.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addDefaultLink

public Link addDefaultLink(int idSource,
                           ExtendedId idSink,
                           LinkCategory type,
                           double activation,
                           double removalThreshold)
Description copied from interface: NodeStructure
Creates and adds a new Link with specified attributes. Source and sink must already be in this NodeStructure.

Specified by:
addDefaultLink in interface NodeStructure
Parameters:
idSource - id of link's source
idSink - ExtendedId of link's sink
type - Link's LinkCategory
activation - initial link activation
removalThreshold - amount of activation Link must maintain to remain in this NodeStructure after decaying.
Returns:
created Link or null if either source or sink are not already present.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addDefaultLink

public Link addDefaultLink(int idSource,
                           int idSink,
                           LinkCategory type,
                           double activation,
                           double removalThreshold)
Description copied from interface: NodeStructure
Creates and adds a new Link with specified attributes. Source and sink must already be in this NodeStructure. Allows multiple links from the same source and sink as long as their LinkCategory differs.

Specified by:
addDefaultLink in interface NodeStructure
Parameters:
idSource - id of link's source
idSink - id of link's sink
type - Link's LinkCategory
activation - initial link activation
removalThreshold - amount of activation Link must maintain to remain in this NodeStructure after decaying.
Returns:
created Link or null if either source or sink are not already present.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addDefaultLinks

public java.util.Collection<Link> addDefaultLinks(java.util.Collection<Link> links)
Description copied from interface: NodeStructure
Copies specified Links and then adds the copies to this NodeStructure. If any Link with the same id already exists then the old Link's activation is updated. Copied links will have the default link type of this NodeStructure when they are added. Note if Links in supplied Collection link to each other then this method does NOT guarantee that all Links will be added properly. Links should be added one at a time in this case after the dependent links are already present.

Specified by:
addDefaultLinks in interface NodeStructure
Parameters:
links - Links to copy and add.
Returns:
the copied Links that are actually stored in this NodeStructure, or any existing links.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addDefaultNode

public Node addDefaultNode(Node n)
Description copied from interface: NodeStructure
Adds a COPY of specified Node to this NodeStructure. The copy will be of the default type of this NodeStructure, NOT of the type of the specified node. If Node with the same id already exists the the old node's activation is updated ONLY IF it is higher than the existing activation.

Specified by:
addDefaultNode in interface NodeStructure
Parameters:
n - Node to add.
Returns:
The copied Node that is stored in this NodeStructure or the existing, updated, Node already there.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addLink

public Link addLink(Link l,
                    java.lang.String linkType)
Description copied from interface: NodeStructure
Adds copy of specified Link. Copy is of specified type.

Specified by:
addLink in interface NodeStructure
Parameters:
l - original Link
linkType - type of copied Link
Returns:
new Link or null if such a link cannot be created.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addNode

public Node addNode(Node n,
                    java.lang.String factoryType)
Description copied from interface: NodeStructure
Add a Node of a specified factory type to this NodeStructure

Specified by:
addNode in interface NodeStructure
Parameters:
n - Node
factoryType - name of node's type in the factory
Returns:
copy of node actually added.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addDefaultNodes

public java.util.Collection<Node> addDefaultNodes(java.util.Collection<Node> nodes)
Specified by:
addDefaultNodes in interface NodeStructure
Parameters:
nodes - Node to be added.
Returns:
copied and/or updated nodes that are now present in this nodestructure
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.
See Also:
NodeStructure.addDefaultNode(Node)

removeLink

public void removeLink(Link l)
Description copied from interface: NodeStructure
Removes specified Link if present.

Specified by:
removeLink in interface NodeStructure
Parameters:
l - Link to remove.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

removeLinkable

public void removeLinkable(Linkable l)
Description copied from interface: NodeStructure
Removes specified Linkable if present.

Specified by:
removeLinkable in interface NodeStructure
Parameters:
l - Linkable to remove.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

removeNode

public void removeNode(Node n)
Description copied from interface: NodeStructure
Removes specified Node if present.

Specified by:
removeNode in interface NodeStructure
Parameters:
n - Node to remove.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

removeLinkable

public void removeLinkable(ExtendedId id)
Description copied from interface: NodeStructure
Removes Linkable with specified ExtendedId if present.

Specified by:
removeLinkable in interface NodeStructure
Parameters:
id - ExtendedId of Linkable to remove.
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

clearLinks

public void clearLinks()
Description copied from interface: NodeStructure
Removes all links from this NodeStructure

Specified by:
clearLinks in interface NodeStructure
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

clearNodeStructure

public void clearNodeStructure()
Description copied from interface: NodeStructure
Removes all nodes and links from this nodestructure

Specified by:
clearNodeStructure in interface NodeStructure
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

mergeWith

public void mergeWith(NodeStructure ns)
Description copied from interface: NodeStructure
Merges specified NodeStructure into this one. Adds all nodes and adds all Links. Activations are updated if Linkable is already present.

Specified by:
mergeWith in interface NodeStructure
Parameters:
ns - NodeStructure
Throws:
java.lang.UnsupportedOperationException - Cannot modify this object once created.

addDefaultLink

public Link addDefaultLink(Node source,
                           Linkable sink,
                           LinkCategory category,
                           double activation,
                           double removalThreshold)
Specified by:
addDefaultLink in interface NodeStructure
Parameters:
source - Link's source Node
sink - Link's sink, a Node or a Link
category - Link's LinkCategory
activation - initial link activation
removalThreshold - amount of activation Link must maintain to remain in this NodeStructure after decaying.
Returns:
created Link or null if either source or sink are not already present.

decayNodeStructure

public void decayNodeStructure(long ticks)
Description copied from interface: NodeStructure
Decays the Linkables of this NodeStructure.

Specified by:
decayNodeStructure in interface NodeStructure
Parameters:
ticks - the number of ticks to decay for.

containsLink

public boolean containsLink(Link l)
Description copied from interface: NodeStructure
Returns whether this NodeStructure contains specified Link.

Specified by:
containsLink in interface NodeStructure
Parameters:
l - Link checked for.
Returns:
true if contains a Link with the same id.

containsLink

public boolean containsLink(ExtendedId id)
Description copied from interface: NodeStructure
Returns whether this NodeStructure contains Link with specified ExtendedId.

Specified by:
containsLink in interface NodeStructure
Parameters:
id - Link checked for.
Returns:
true if contains a Link with the same ExtendedId.

containsLinkable

public boolean containsLinkable(Linkable l)
Description copied from interface: NodeStructure
Returns whether this NodeStructure contains specified Linkable.

Specified by:
containsLinkable in interface NodeStructure
Parameters:
l - Linkable checked for.
Returns:
true if contains a Linkable with the same ExtendedId.

containsLinkable

public boolean containsLinkable(ExtendedId id)
Description copied from interface: NodeStructure
Returns whether this NodeStructure contains Linkable with specified ExtendedId.

Specified by:
containsLinkable in interface NodeStructure
Parameters:
id - Linkable checked for.
Returns:
true if contains a Linkable with the same ExtendedId.

containsNode

public boolean containsNode(Node n)
Description copied from interface: NodeStructure
Returns whether this NodeStructure contains specified Node.

Specified by:
containsNode in interface NodeStructure
Parameters:
n - Node checked for.
Returns:
true if contains a Node with the same id.

containsNode

public boolean containsNode(int id)
Description copied from interface: NodeStructure
Returns whether this NodeStructure contains Node with specified id.

Specified by:
containsNode in interface NodeStructure
Parameters:
id - id of Node checked for.
Returns:
true if contains a Node with the same id.

containsNode

public boolean containsNode(ExtendedId id)
Description copied from interface: NodeStructure
Returns whether this NodeStructure contains Node with specified ExtendedId.

Specified by:
containsNode in interface NodeStructure
Parameters:
id - ExtendedId of Node checked for.
Returns:
true if contains a Node with the same ExtendedId.

getAttachedLinks

public java.util.Set<Link> getAttachedLinks(Linkable l)
Description copied from interface: NodeStructure
Gets all Links directly connected to specified Linkable.

Specified by:
getAttachedLinks in interface NodeStructure
Parameters:
l - Linkable to find Links to and from.
Returns:
an unmodifiable Set of all Links connected to specified Linkable.

getAttachedLinks

public java.util.Set<Link> getAttachedLinks(Linkable linkable,
                                            LinkCategory cat)
Description copied from interface: NodeStructure
Gets all Links directly connected to specified Linkable with specified LinkCategory

Specified by:
getAttachedLinks in interface NodeStructure
Parameters:
linkable - a Linkable
cat - LinkCategory
Returns:
Links

getConnectedSinks

public java.util.Map<Linkable,Link> getConnectedSinks(Node n)
Description copied from interface: NodeStructure
Finds and returns a Map of all sink Linkables connected to specified Node. Keys are the connected sinks Values are the Links connecting the sinks to the specified Node

Specified by:
getConnectedSinks in interface NodeStructure
Parameters:
n - supplied node
Returns:
map of sinks and links connecting node to them

getConnectedSources

public java.util.Map<Node,Link> getConnectedSources(Linkable linkable)
Description copied from interface: NodeStructure
Finds and returns a Map of all source Nodes connected to specified Linkable. Keys are the connected sources Values are the Links connecting the sources to the specified Linkable

Specified by:
getConnectedSources in interface NodeStructure
Parameters:
linkable - specified linkable
Returns:
map of sources and links connecting Linkable to them

getDefaultLinkType

public java.lang.String getDefaultLinkType()
Description copied from interface: NodeStructure
Gets defaultLinkType

Specified by:
getDefaultLinkType in interface NodeStructure
Returns:
link type used when creating new link copies that are being added to this NodeStructure.

getDefaultNodeType

public java.lang.String getDefaultNodeType()
Description copied from interface: NodeStructure
Gets defaultNodeType

Specified by:
getDefaultNodeType in interface NodeStructure
Returns:
node type used when creating new nodes that are being added to this NodeStructure.

getLink

public Link getLink(ExtendedId ids)
Description copied from interface: NodeStructure
Gets Link with specified ExtendedId if present.

Specified by:
getLink in interface NodeStructure
Parameters:
ids - ExtendedId of sought Link.
Returns:
Link or null if no Link exists.

getLinkCount

public int getLinkCount()
Description copied from interface: NodeStructure
returns a count of links

Specified by:
getLinkCount in interface NodeStructure
Returns:
number of links

getLinkable

public Linkable getLinkable(ExtendedId eid)
Description copied from interface: NodeStructure
Gets Linkable with specified ExtendedId

Specified by:
getLinkable in interface NodeStructure
Parameters:
eid - ExtendedId
Returns:
a Linkable

getLinkableCount

public int getLinkableCount()
Description copied from interface: NodeStructure
Returns count of Linkables

Specified by:
getLinkableCount in interface NodeStructure
Returns:
number of Linkables

getLinkableMap

public java.util.Map<Linkable,java.util.Set<Link>> getLinkableMap()
Description copied from interface: NodeStructure
Returns linkableMap

Specified by:
getLinkableMap in interface NodeStructure
Returns:
An unmodifiable Map of the linkables of this NodeStructure and their links.s

getLinkables

public java.util.Collection<Linkable> getLinkables()
Description copied from interface: NodeStructure
Returns all Linkables, all Nodes and Links, in this NodeStructure

Specified by:
getLinkables in interface NodeStructure
Returns:
all Linkables

getLinks

public java.util.Collection<Link> getLinks()
Description copied from interface: NodeStructure
Returns the Links of this NodeStructure

Specified by:
getLinks in interface NodeStructure
Returns:
an unmodifiable Collection of all Links

getLinks

public java.util.Set<Link> getLinks(LinkCategory cat)
Description copied from interface: NodeStructure
Returns all Links of this NodeStructure with specified LinkCategory

Specified by:
getLinks in interface NodeStructure
Parameters:
cat - LinkCategory to search for.
Returns:
Links having specified LinkCategory

getNode

public Node getNode(int id)
Description copied from interface: NodeStructure
Returns a copy of the node in this nodestructure with specified id

Specified by:
getNode in interface NodeStructure
Parameters:
id - id of node
Returns:
Node with specified id or null if not present

getNode

public Node getNode(ExtendedId eid)
Description copied from interface: NodeStructure
Returns a copy of the node in this nodestructure with specified ExtendedId

Specified by:
getNode in interface NodeStructure
Parameters:
eid - ExtendedId of node
Returns:
Node with specified ExtendedId or null if not present

getNodeCount

public int getNodeCount()
Description copied from interface: NodeStructure
Returns a count of nodes

Specified by:
getNodeCount in interface NodeStructure
Returns:
number of nodes

getNodes

public java.util.Collection<Node> getNodes()
Description copied from interface: NodeStructure
Returns all Nodes

Specified by:
getNodes in interface NodeStructure
Returns:
All Nodes in this NodeStructure.