package schedframe.net.pce.topology; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Class representing an abstract topology of a network. * * @author Bartosz Belter * */ public class AbstractTopology { /** * List of network nodes */ List nodes = new ArrayList(); /** * List of connections between the nodes */ List links = new ArrayList(); /** * Adds new node to the topology * * @param node Node to add */ public void addNode (Node node) throws IllegalArgumentException { if (nodes==null) nodes = new ArrayList(); try { nodes.add(node); } catch (Exception e) { throw new IllegalArgumentException(e); } } /** * Removes the node from the topology * * @param node Node to remove */ public void removeNode (Node node) throws IllegalArgumentException { if (nodes!=null) { try { nodes.remove(node); } catch (Exception e) { throw new IllegalArgumentException(e); } } } /** * Adds new link to the topology * * @param link Link to add */ public void addLink (DataLink link) throws IllegalArgumentException { if (links==null) links = new ArrayList(); try { links.add(link); } catch (Exception e) { throw new IllegalArgumentException(e); } } /** * Removes the link from the topology * * @param link Link to remove */ public void removeLink (DataLink link) throws IllegalArgumentException { if (links!=null) { try { links.remove(link); } catch (Exception e) { throw new IllegalArgumentException(e); } } } /** * Retrieves a list of nodes * * @return list of nodes */ public List getNodes () { return nodes; } /** * Retrieves a list of links * * @return list of links */ public List getLinks () { return links; } public Node getNode(String nodeName) { Node node = null; Iterator it = nodes.iterator(); while(it.hasNext()){ node = it.next(); if(node.getId().compareTo(nodeName) == 0) return node; } return null; } }