001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2005 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.graph.model;
021:
022: import java.util.*;
023:
024: public class SimpleNode extends Element {
025:
026: private ArrayList inputs;
027: private ArrayList outputs;
028: protected Object data;
029: private ArrayList children = new ArrayList();
030:
031: public SimpleNode() {
032: super ();
033: }
034:
035: public void addInput(Edge e) {
036: if (getInputs() == null) {
037: setInputs(new ArrayList());
038: }
039: getInputs().add(e);
040: fireStructureChange(INPUTS, e);
041: }
042:
043: public void addOutput(Edge e) {
044: if (getOutputs() == null) {
045: setOutputs(new ArrayList());
046: }
047: getOutputs().add(e);
048: fireStructureChange(OUTPUTS, e);
049: }
050:
051: public void removeInput(Edge e) {
052: if (getInputs() == null)
053: return;
054: if (getInputs().contains(e)) {
055: getInputs().remove(e);
056: fireStructureChange(INPUTS, e);
057: }
058: }
059:
060: public void removeOutput(Edge e) {
061: if (getOutputs() == null)
062: return;
063: if (getOutputs().contains(e)) {
064: getOutputs().remove(e);
065: fireStructureChange(OUTPUTS, e);
066: }
067: }
068:
069: public void removeAllInputs() {
070: if (getInputs() == null)
071: return;
072: Iterator it = getInputs().iterator();
073: while (it.hasNext()) {
074: Edge e = (Edge) it.next();
075: e.getSrc().removeOutput(e);
076: }
077: setInputs(new ArrayList());
078: fireStructureChange(INPUTS, null);
079: }
080:
081: public void removeAllOutputs() {
082: if (getOutputs() == null)
083: return;
084: Iterator it = getOutputs().iterator();
085: while (it.hasNext()) {
086: Edge e = (Edge) it.next();
087: e.getTgt().removeInput(e);
088: }
089: setOutputs(new ArrayList());
090: fireStructureChange(OUTPUTS, null);
091: }
092:
093: /**
094: * @return
095: */
096: public ArrayList getInputs() {
097: return inputs;
098: }
099:
100: /**
101: * @return
102: */
103: public ArrayList getOutputs() {
104: return outputs;
105: }
106:
107: /**
108: * @param list
109: */
110: public void setInputs(ArrayList list) {
111: inputs = list;
112: }
113:
114: /**
115: * @param list
116: */
117: public void setOutputs(ArrayList list) {
118: outputs = list;
119: }
120:
121: /**
122: * @return
123: */
124: public Object getData() {
125: return data;
126: }
127:
128: /**
129: * @param string
130: */
131: public void setData(Object string) {
132: data = string;
133: firePropertyChange(DATA, data.toString());
134: }
135:
136: /**
137: * @return
138: */
139: public ArrayList getChildren() {
140: return children;
141: }
142:
143: /**
144: * @param list
145: */
146: public void setChildren(ArrayList list) {
147: children = list;
148: }
149:
150: public void addChild(SimpleNode sn) {
151: children.add(sn);
152: fireStructureChange(COMPLEX_CHILD_ADDED, sn);
153: }
154:
155: }
|