mapss.dif.graph.hierarchy
Class PortList

java.lang.Object
  extended by mapss.dif.graph.hierarchy.PortList

public class PortList
extends java.lang.Object

List of ports in a hierarchy. It provides methods to check if a name is defined previously as a port or if an edge is connected to another port prior to a connection. Ports are stored in the order they are added, getAll() and iterator() methods maintain this order.

Version:
$Id: PortList.java 409 2007-05-13 19:47:16Z plishker $
Author:
Fuat Keceli

Constructor Summary
PortList()
          Construct a port list.
 
Method Summary
protected  void _add(Port port)
          Adds a port to this list.
protected  void _remove(Port port)
          Removes a port form the port list.
 void disconnectAll()
          Disconnects all port connections with the super-hierarchy.
 Port get(mocgraph.Node node)
          Returns the port related to the given node or one of its ports.
 Port get(java.lang.String name)
          Returns the port defined with the given name.
 java.util.List getAll()
          Returns a list of all ports in the order they are added.
 Port[] getConnectedPort(mocgraph.Edge edge)
          Returns the port(s) that this edge is connected.
 boolean isConnected(mocgraph.Edge edge)
          Checks if an edge is already connected to a port in this list.
 boolean isDefined(java.lang.String name)
          Checks if a port name is previously defined.
 java.util.ListIterator iterator()
          Returns an iterator over the list of port added.
 java.lang.String newName()
          Returns a string that is guaranteed to be unused in this port list as a port name.
 java.lang.String toString()
          Returns the names of the ports listed in this list in the order they are added.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PortList

public PortList()
Construct a port list.

Method Detail

disconnectAll

public void disconnectAll()
Disconnects all port connections with the super-hierarchy.


get

public Port get(java.lang.String name)
Returns the port defined with the given name.

Parameters:
name - Name of the port that is being searched.
Returns:
Port with the given name. Null if not found.

get

public Port get(mocgraph.Node node)
Returns the port related to the given node or one of its ports.

Parameters:
node - Node that is being searched.
Returns:
Port related to the given node. Null if not found.

getAll

public java.util.List getAll()
Returns a list of all ports in the order they are added. Returned list is a copy so the user is free to modify it.

Returns:
A list of all ports in the order they are added.

getConnectedPort

public Port[] getConnectedPort(mocgraph.Edge edge)
Returns the port(s) that this edge is connected. If the edge is not connected length of the returned array is 0. If the edge is connected length of the returned array might be 1 or 2 (depending on the number of ends connected to ports of sub-hierarchies).

Parameters:
edge - A graph edge.
Returns:
An array of length 0, 1 or 2.

isConnected

public boolean isConnected(mocgraph.Edge edge)
Checks if an edge is already connected to a port in this list.

Returns:
True if the edge is connected. False otherwise.

isDefined

public boolean isDefined(java.lang.String name)
Checks if a port name is previously defined.

Returns:
True is the name is previously defined. False otherwise.

iterator

public java.util.ListIterator iterator()
Returns an iterator over the list of port added. The order of the iterator is the order that ports are added.

Returns:
An iterator over the added ports.

newName

public java.lang.String newName()
Returns a string that is guaranteed to be unused in this port list as a port name.

Returns:
An port name.

toString

public java.lang.String toString()
Returns the names of the ports listed in this list in the order they are added.

Overrides:
toString in class java.lang.Object
Returns:
The names of the ports listed in this list.

_add

protected void _add(Port port)
Adds a port to this list. This method doesn't perform any error checking so it is the users responsibility to preserve consistency of ports. isDefined and isConnected methods can be used to perform most of these checks.


_remove

protected void _remove(Port port)
Removes a port form the port list.