source: xssim/trunk/src/schedframe/net/pce/topology/AbstractTopology.java @ 104

Revision 104, 2.2 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.net.pce.topology;
2
3
4import java.util.ArrayList;
5import java.util.Iterator;
6import java.util.List;
7
8
9/**
10 * Class representing an abstract topology of a network.
11 *
12 * @author Bartosz Belter <bartosz.belter at man.poznan.pl>
13 *
14 */
15public class AbstractTopology {
16       
17        /**
18         * List of network nodes
19         */
20        List<Node> nodes = new ArrayList<Node>();
21       
22        /**
23         * List of connections between the nodes
24         */
25        List<DataLink> links = new ArrayList<DataLink>();
26       
27       
28        /**
29         * Adds new node to the topology
30         *
31         * @param node  Node to add
32         */
33        public void addNode (Node node) throws IllegalArgumentException {
34                if (nodes==null)
35                        nodes = new ArrayList<Node>();
36                try {
37                        nodes.add(node);
38                } catch (Exception e) {
39                        throw new IllegalArgumentException(e);
40                }
41        }
42       
43       
44        /**
45         * Removes the node from the topology
46         *
47         * @param node  Node to remove
48         */
49        public void removeNode (Node node) throws IllegalArgumentException {
50                if (nodes!=null) {
51                        try {
52                                nodes.remove(node);
53                        } catch (Exception e) {
54                                throw new IllegalArgumentException(e);
55                        }       
56                }
57        }
58       
59
60        /**
61         * Adds new link to the topology
62         *
63         * @param link  Link to add
64         */
65        public void addLink (DataLink link) throws IllegalArgumentException {
66                if (links==null)
67                        links = new ArrayList<DataLink>();
68                try {
69                        links.add(link);
70                } catch (Exception e) {
71                        throw new IllegalArgumentException(e);
72                }
73        }
74       
75       
76        /**
77         * Removes the link from the topology
78         *
79         * @param link  Link to remove
80         */
81        public void removeLink (DataLink link) throws IllegalArgumentException {
82                if (links!=null) {
83                        try {
84                                links.remove(link);
85                        } catch (Exception e) {
86                                throw new IllegalArgumentException(e);
87                        }       
88                }
89        }       
90       
91        /**
92         * Retrieves a list of nodes
93         *
94         * @return      list of nodes
95         */
96        public List<Node> getNodes () {
97                return nodes;
98        }
99       
100        /**
101         * Retrieves a list of links
102         *
103         * @return      list of links
104         */
105        public List<DataLink> getLinks () {
106                return links;
107        }
108       
109        public Node getNode(String nodeName) {
110                Node node = null;
111                Iterator<Node> it = nodes.iterator();
112                while(it.hasNext()){
113                        node = it.next();
114                        if(node.getId().compareTo(nodeName) == 0)
115                                return node;
116                }
117                return null;
118        }
119
120}
Note: See TracBrowser for help on using the repository browser.