// XAAL toolkit // Copyright (C) 2009 Ville Karavirta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package xaal.objects.structures; import java.awt.Rectangle; import java.util.Iterator; import java.util.Stack; import xaal.objects.Xaal; /** * @author vkaravir * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class DataStructure extends Structure { public static final int GRAPH_TYPE = 0; public static final int STACK_TYPE = 1; public static final int TREE_TYPE = 2; public static final int ARRAY_TYPE = 3; public static final int QUEUE_TYPE = 4; public static final int LIST_TYPE = 5; private int type; private String cls; private Stack nodes; private Stack references; /** * */ public DataStructure(Xaal xaalDoc) { super(xaalDoc); nodes = new Stack(); references = new Stack(); } public DataStructure(Xaal xaalDoc, int type) { this(xaalDoc); this.type = type; } public DataStructure(Xaal xaalDoc, int type, String id) { this(xaalDoc, type); setId(id); } public void setStrClass(String cls) { this.cls = cls; } public String getStrClass() { return cls; } public void setType(int type) { this.type = type; } public int getType() { return type; } public void addNode(Node n) { nodes.push(n); } public void addReference(Edge ref) { references.push(ref); } public Iterator getNodes() { return nodes.iterator(); } public Iterator getReferences() { return references.iterator(); } public String toString() { /*String nodes = ""; Iterator i = getContents(); while (i.hasNext()) nodes += "\nNode: "+ i.next().toString(); String refs = ""; i = getReferences(); while (i.hasNext()) refs += "\nReference: " + i.next().toString();*/ if (type == GRAPH_TYPE) return "graph " + getNarrative() + "\nKeys:"+nodes+"\nReferences:"+references; else if (type == TREE_TYPE) return "tree " + getNarrative() + "\nKeys:"+nodes+"\nReferences:"+references; else if (type == ARRAY_TYPE) return "array " + getNarrative() + "\nKeys:"+nodes+"\nReferences:"+references+"\nGraphical:"+getGraphicals(); return "-"; } }