[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Structure.java, NONE, 1.1 Space.java
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-07-23 14:37:30
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv18117/src/net/sourceforge/bprocessor/model Modified Files: Space.java Attribute.java Persistence.java Classification.java ClassificationType.java Project.java ClassificationFileReader.java Added Files: Structure.java Log Message: Made a superclass to Classification and ClassificationType called Structure and made all uses reflect that... Index: ClassificationFileReader.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ClassificationFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ClassificationFileReader.java 26 Jun 2007 10:56:54 -0000 1.2 --- ClassificationFileReader.java 23 Jul 2007 13:58:13 -0000 1.3 *************** *** 90,94 **** //classificationTypes currentClassificationType = new ClassificationType(tokens[4], 0.0, 0.0, 0.0); ! superClassificationType.addSubType(currentClassificationType); continue; } --- 90,94 ---- //classificationTypes currentClassificationType = new ClassificationType(tokens[4], 0.0, 0.0, 0.0); ! superClassificationType.addChild(currentClassificationType); continue; } *************** *** 99,103 **** //subtypes if (currentClassificationType != null) { ! currentClassificationType.addSubType( new ClassificationType(tokens[5], 0.0, 0.0, 0.0)); } else { --- 99,103 ---- //subtypes if (currentClassificationType != null) { ! currentClassificationType.addChild( new ClassificationType(tokens[5], 0.0, 0.0, 0.0)); } else { Index: Classification.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Classification.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Classification.java 26 Jun 2007 10:56:54 -0000 1.19 --- Classification.java 23 Jul 2007 13:58:13 -0000 1.20 *************** *** 10,14 **** import java.util.Iterator; import java.util.List; - import java.util.Vector; import org.apache.log4j.Logger; --- 10,13 ---- *************** *** 17,36 **** * This class persist the model from/to an XML document */ ! public class Classification implements Parametric { /** The logger */ private static Logger log = Logger.getLogger(Classification.class); - /** The name of the classification */ - private String name; - /** The id of the classification */ private String id; - /** The children of this classification */ - private Vector<Classification> children; - - /** The parent of this classification */ - private Classification parent; - /** The classification */ private ClassificationType possibleTypes; --- 16,26 ---- * This class persist the model from/to an XML document */ ! public class Classification extends Structure<Classification> implements Parametric { /** The logger */ private static Logger log = Logger.getLogger(Classification.class); /** The id of the classification */ private String id; /** The classification */ private ClassificationType possibleTypes; *************** *** 75,103 **** */ public Classification() { ! children = new Vector<Classification>(); ! } ! ! /** ! * Get the vector containing this classifications children ! * @return the children ! */ ! public Vector<Classification> getChildren() { ! return children; ! } ! ! /** ! * Get the name of this classification ! * @return the name ! */ ! public String getName() { ! return name; ! } ! ! /** ! * Sets the name of the classification ! * @param name the new name for the classification ! */ ! public void setName (String name) { ! this.name = name; } --- 65,69 ---- */ public Classification() { ! super(); } *************** *** 119,147 **** /** - * Adds a child to the classification - * @param child the child to be added - */ - public void addChild(Classification child) { - children.add(child); - } - - /** - * Returns the parent of this classification - * @return the parent - */ - public Classification getParent() { - return parent; - } - - /** - * Set the parent of this classification - * @param parent the new parent - */ - public void setParent(Classification parent) { - this.parent = parent; - } - - - /** * Generates the full id for this classification * @param cur the Space that the full id is generated for --- 85,88 ---- *************** *** 152,162 **** String fullId = id; if (current != null && current.getClassificationType() != null) { ! if (!("" + fullId.charAt(0)).equalsIgnoreCase("-")) { ! fullId = current.getClassificationType().getName(); } else { ! fullId = "-" + current.getClassificationType().getName() + fullId.replaceFirst("-", ""); ! } } ! Classification par = parent; if (par != null) { if (cur != null && cur.getOwner().getLevel() != Space.PROJECT_LEVEL) { --- 93,104 ---- String fullId = id; if (current != null && current.getClassificationType() != null) { ! /*if (!("" + fullId.charAt(0)).equalsIgnoreCase("-")) { ! fullId = current.getClassificationType().getPrefix(); } else { ! fullId = "-" + current.getClassificationType().getPrefix() + fullId.replaceFirst("-", ""); ! }*/ ! fullId = "-" + current.getClassificationType().getPrefix() + fullId.replaceFirst("-", ""); } ! Classification par = getParent(); if (par != null) { if (cur != null && cur.getOwner().getLevel() != Space.PROJECT_LEVEL) { *************** *** 185,189 **** */ public String toString() { ! return name; } --- 127,131 ---- */ public String toString() { ! return getName(); } *************** *** 229,233 **** res.add(new Attribute("Name", getName(), false)); res.add(new Attribute("Code", getFullId(null), false)); ! res.add(new Attribute("Type link", possibleTypes)); return res; } --- 171,175 ---- res.add(new Attribute("Name", getName(), false)); res.add(new Attribute("Code", getFullId(null), false)); ! res.add(new Attribute("Type link", possibleTypes, possibleTypes)); return res; } Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** Persistence.java 28 Jun 2007 13:03:42 -0000 1.43 --- Persistence.java 23 Jul 2007 13:58:13 -0000 1.44 *************** *** 271,275 **** space.setUnion(xml.isUnion()); space.setClassification(internalizeClassifaction(xml.getClassification(), type)); ! mapper.put(new Long(xml.getId()), space); --- 271,278 ---- space.setUnion(xml.isUnion()); space.setClassification(internalizeClassifaction(xml.getClassification(), type)); ! ClassificationType classType = internalizeClassificationType(xml.getClassification(), type); ! if (classType != null) { ! space.setClassificationType(classType); ! } mapper.put(new Long(xml.getId()), space); *************** *** 370,373 **** --- 373,384 ---- } + private static ClassificationType internalizeClassificationType(String string, int type) { + if (type == Space.CONSTRUCTION) { + ClassificationType classType = Project.getInstance().findClassificationType(string, 0); + return classType; + } + return null; + } + /** * create model object of the xml *************** *** 1479,1486 **** private static XMLSpecificType externalizeClassificationType(ClassificationType type) { XMLSpecificType xml = new XMLSpecificTypeImpl(); - xml.setIndex(type.getIndex()); xml.setName(type.getName()); xml.setId(type.getId()); ! for (ClassificationType clasType : type.getSubTypes()) { if (clasType != null) { xml.getXMLSpecificType().add(Persistence.externalizeClassificationType(clasType)); --- 1490,1497 ---- private static XMLSpecificType externalizeClassificationType(ClassificationType type) { XMLSpecificType xml = new XMLSpecificTypeImpl(); xml.setName(type.getName()); xml.setId(type.getId()); ! xml.setIndex(type.getIndex()); ! for (ClassificationType clasType : type.getChildren()) { if (clasType != null) { xml.getXMLSpecificType().add(Persistence.externalizeClassificationType(clasType)); *************** *** 1490,1494 **** } Map map = new HashMap(); ! for (Attribute a : type.getParameters()) { xml.getAttributes().add(externalizeKeyValue(a.getName(), a.getValue(), map)); } --- 1501,1505 ---- } Map map = new HashMap(); ! for (Attribute a : type.getAllParameters().values()) { xml.getAttributes().add(externalizeKeyValue(a.getName(), a.getValue(), map)); } *************** *** 1508,1512 **** XMLSpecificTypeType rootType = xml.getXMLSpecificType(); Map<Long, ClassificationType> typeMap = new HashMap<Long, ClassificationType>(); ! internalizeTypes(rootType, typeMap); Classification construction = internalizeClassification( (XMLClassificationType)xml.getXMLClassification().get(0), typeMap, Space.CONSTRUCTION); --- 1519,1525 ---- XMLSpecificTypeType rootType = xml.getXMLSpecificType(); Map<Long, ClassificationType> typeMap = new HashMap<Long, ClassificationType>(); ! for (XMLSpecificTypeType specType : (List<XMLSpecificTypeType>)rootType.getXMLSpecificType()) { ! internalizeTypes(specType, typeMap); ! } Classification construction = internalizeClassification( (XMLClassificationType)xml.getXMLClassification().get(0), typeMap, Space.CONSTRUCTION); *************** *** 1533,1538 **** if (classiType != null) { res.setPossibleTypes(classiType); - } else { - log.error("There were no classificationType associated with " + res + " in the XML"); } for (XMLClassificationType subType : --- 1546,1549 ---- *************** *** 1571,1575 **** for (XMLSpecificTypeType subType : (List<XMLSpecificTypeType>)type.getXMLSpecificType()) { ClassificationType out = internalizeTypes(subType, map); ! res.addSubType(out); } map.put(res.getId(), res); --- 1582,1587 ---- for (XMLSpecificTypeType subType : (List<XMLSpecificTypeType>)type.getXMLSpecificType()) { ClassificationType out = internalizeTypes(subType, map); ! res.addChild(out); ! res.setParent(res); } map.put(res.getId(), res); --- NEW FILE: Structure.java --- //--------------------------------------------------------------------------------- // $Id: Structure.java,v 1.1 2007/07/23 13:58:13 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.Vector; /** * A super class for classes that need to point to others of itself * @param <Type> The class type that should be pointet to */ public class Structure <Type> { /** The children of this classification */ private Vector<Type> children; /** The parent of this classification */ private Type parent; private String name; /** * The constructor */ public Structure() { children = new Vector<Type>(); parent = null; } /** * @return the children */ public Vector<Type> getChildren() { return children; } /** * @param child the child to add */ public void addChild(Type child) { this.children.add(child); ((Structure<Type>)child).setParent((Type)this); } /** * @return the parent */ public Type getParent() { return parent; } /** * @param parent the parent to set */ public void setParent(Type parent) { this.parent = parent; } /** * Get the name of this classification * @return the name */ public String getName() { return name; } /** * Sets the name of the classification * @param name the new name for the classification */ public void setName(String name) { this.name = name; } } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.130 retrieving revision 1.131 diff -C2 -d -r1.130 -r1.131 *** Project.java 26 Jun 2007 10:56:54 -0000 1.130 --- Project.java 23 Jul 2007 13:58:13 -0000 1.131 *************** *** 871,875 **** StringTokenizer st = new StringTokenizer(id, "."); Classification cl; ! if (type == 0) { cl = constructionClas; --- 871,875 ---- StringTokenizer st = new StringTokenizer(id, "."); Classification cl; ! if (type == Space.CONSTRUCTION) { cl = constructionClas; *************** *** 929,932 **** --- 929,990 ---- } + /** + * + * @param id The string to find the ClassificationType in + * @param type The Space type + * @return The found classification Type could be null (then it is just default) + */ + public ClassificationType findClassificationType(String id, int type) { + StringTokenizer st = new StringTokenizer(id, "."); + ClassificationType res = null; + Classification cl; + if (type == Space.CONSTRUCTION) { + cl = constructionClas; + + String curid; + while (st.hasMoreTokens()) { + curid = st.nextToken(); + if (("" + curid.charAt(0)).equalsIgnoreCase("-")) { + if (!Character.isDigit(curid.charAt(1))) { + if (cl.getPossibleTypes() != null && cl.getPossibleTypes().getChildren() != null) { + res = cl.getPossibleTypes().getChildren().get((int)'A' - (int)curid.charAt(1)); + } + if (!Character.isDigit(curid.charAt(2))) { + if (cl.getPossibleTypes() != null && cl.getPossibleTypes().getChildren() != null) { + res = res.getChildren().get((int)'A' - (int)curid.charAt(2)); + } + curid = "-" + curid.substring(3); + } else { + curid = "-" + curid.substring(2); + } + } + } else { + if (!Character.isDigit(curid.charAt(0))) { + if (cl.getPossibleTypes() != null && cl.getPossibleTypes().getChildren() != null) { + res = cl.getPossibleTypes().getChildren().get((int)'A' - (int)curid.charAt(1)); + } + if (!Character.isDigit(curid.charAt(1))) { + if (cl.getPossibleTypes() != null && cl.getPossibleTypes().getChildren() != null) { + res = res.getChildren().get((int)'A' - (int)curid.charAt(2)); + } + curid = curid.substring(2); + } else { + curid = curid.substring(1); + } + } + } + + Iterator it = cl.getChildren().iterator(); + while (it.hasNext()) { + Classification current = (Classification) it.next(); + if (curid.equalsIgnoreCase(current.getId())) { + cl = current; + } + } + } + } + return res; + } + /** * getter for the copy buffer Index: Attribute.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Attribute.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Attribute.java 8 May 2007 12:35:38 -0000 1.20 --- Attribute.java 23 Jul 2007 13:58:11 -0000 1.21 *************** *** 25,34 **** private Object value; /** The name */ private String name; - /** The classification */ - private Classification classification; - /** The space the classification is for */ private Space level; --- 25,34 ---- private Object value; + /** The 2nd value object */ + private Object the2ndValue; + /** The name */ private String name; /** The space the classification is for */ private Space level; *************** *** 101,105 **** setName(name); setValue(value); ! setClassification(classification); setLevel(level); editable = true; --- 101,105 ---- setName(name); setValue(value); ! setThe2ndValue(classification); setLevel(level); editable = true; *************** *** 107,110 **** --- 107,125 ---- /** + * Constructor for Classification Attribute + * @param name The name + * @param rootClassification The outermost possible type + * @param selectedClassification The chosen type (can be null) + */ + public Attribute(String name, + ClassificationType rootClassification, + ClassificationType selectedClassification) { + setName(name); + setThe2ndValue(selectedClassification); + setValue(rootClassification); + editable = true; + } + + /** * @return Returns the name. */ *************** *** 133,150 **** this.precision = precision; } - - /** - * @return Returns the classification. - */ - public Classification getClassification() { - return classification; - } - - /** - * @param classification The classification to set. - */ - public void setClassification(Classification classification) { - this.classification = classification; - } /** --- 148,151 ---- *************** *** 237,239 **** --- 238,256 ---- public void delete() { } + + /** + * Getter for the2ndValue + * @return The the2ndValue + */ + public Object getThe2ndValue() { + return the2ndValue; + } + + /** + * Set the the2ndValue to the given object + * @param the2ndValue The 2nd value + */ + public void setThe2ndValue(Object the2ndValue) { + this.the2ndValue = the2ndValue; + } } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.162 retrieving revision 1.163 diff -C2 -d -r1.162 -r1.163 *** Space.java 20 Jul 2007 13:33:26 -0000 1.162 --- Space.java 23 Jul 2007 13:58:10 -0000 1.163 *************** *** 14,17 **** --- 14,18 ---- import java.util.HashSet; import java.util.Iterator; + import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; *************** *** 39,43 **** /** functional Type */ public static final int FUNCTIONAL = 1; - /** project level */ public static final int PROJECT_LEVEL = 2; --- 40,43 ---- *************** *** 60,64 **** private Set<Surface> envelope; ! /** type */ private int type; --- 60,64 ---- private Set<Surface> envelope; ! /** type of space */ private int type; *************** *** 80,84 **** private Classification classification; ! /** The classification */ private ClassificationType productType; --- 80,84 ---- private Classification classification; ! /** The classification type*/ private ClassificationType productType; *************** *** 142,145 **** --- 142,147 ---- private String room = "0"; + private Map<String, Attribute> ownParameters = new HashMap<String, Attribute>(); + /** * Constructor for persistence layer *************** *** 943,947 **** */ public void setClassification(Classification classification) { ! this.classification = classification; } --- 945,952 ---- */ public void setClassification(Classification classification) { ! if (classification != null) { ! this.classification = classification; ! setClassificationType(classification.getPossibleTypes()); ! } } *************** *** 1302,1316 **** setName((String)a.getValue()); } else if (a.getName().equals("Classification")) { ! if (getOwner() == Project.getInstance().world()) { ! setClassification(((Classification)a.getClassification())); ! } ! if (getLevel() == Space.ELEMENT_LEVEL) { ! setClassification(((Classification)a.getClassification())); ! } ! if (getLevel() == Space.PART_LEVEL) { ! setClassification(((Classification)a.getClassification())); ! } } else if (a.getName().equals("Type")) { ! //TODO make ClassificationType attributes } else if (a.getName().equals("Building")) { setBuilding(((String)a.getValue().toString())); --- 1307,1316 ---- setName((String)a.getValue()); } else if (a.getName().equals("Classification")) { ! setClassification(((Classification)a.getThe2ndValue())); } else if (a.getName().equals("Type")) { ! ClassificationType cst = (ClassificationType)a.getThe2ndValue(); ! if (getClassification().getPossibleTypes().isPossibleSubtype(cst)) { ! setClassificationType(cst); ! } } else if (a.getName().equals("Building")) { setBuilding(((String)a.getValue().toString())); *************** *** 1345,1391 **** } } else { ! ! if (getLevel() == Space.ELEMENT_LEVEL) { ! if (isConstructionSpace()) { ! if (getOwner().getClassification() != null) { ! res.add(new Attribute("Classification", ! getOwner().getClassification(), getClassification(), this)); ! } else { ! res.add(new Attribute("Classification", ! Project.getInstance().getConstructionClas(), getClassification(), this)); ! } } else { ! if (getOwner().getClassification() != null) { ! res.add(new Attribute("Classification", ! getOwner().getClassification(), getClassification(), this)); ! } else { ! res.add(new Attribute("Classification", ! Project.getInstance().getFunctionalClas(), getClassification(), this)); ! } } ! } else if (getLevel() == Space.PART_LEVEL) { ! if (isConstructionSpace()) { ! if (getOwner().getClassification() != null) { ! res.add(new Attribute("Classification", ! getOwner().getClassification(), getClassification(), this)); ! } else { ! res.add(new Attribute("Classification", ! Project.getInstance().getConstructionClas(), getClassification(), this)); ! } } else { ! if (getOwner().getClassification() != null) { ! res.add(new Attribute("Classification", ! getOwner().getClassification(), getClassification(), this)); ! } else { ! res.add(new Attribute("Classification", ! Project.getInstance().getFunctionalClas(), getClassification(), this)); ! } } } } if (getClassification() != null && getClassificationType() != null) { ! //TODO make classificationType attribute ! //res.add(new Attribute("Type", getClassification().getClassificationType(), ! // getClassificationType(), this)); } if (isFunctionalSpace()) { --- 1345,1370 ---- } } else { ! if (isConstructionSpace()) { ! if (getOwner().getClassification() != null) { ! res.add(new Attribute("Classification", ! getOwner().getClassification(), getClassification(), this)); } else { ! res.add(new Attribute("Classification", ! Project.getInstance().getConstructionClas(), getClassification(), this)); } ! } else { ! if (getOwner().getClassification() != null) { ! res.add(new Attribute("Classification", ! getOwner().getClassification(), getClassification(), this)); } else { ! res.add(new Attribute("Classification", ! Project.getInstance().getFunctionalClas(), getClassification(), this)); } } } if (getClassification() != null && getClassificationType() != null) { ! res.add(new Attribute("Type", getClassification().getPossibleTypes(), ! getClassificationType())); ! res.addAll(getOwnParameters().values()); } if (isFunctionalSpace()) { *************** *** 2817,2820 **** --- 2796,2812 ---- /** + * Get all own parameters (along with those implied by the classification type + * @return A linkedHashMap with alle the parameters + */ + public LinkedHashMap<String, Attribute> getOwnParameters() { + LinkedHashMap<String, Attribute> res = new LinkedHashMap<String, Attribute>(); + if (getClassificationType() != null) { + res.putAll(getClassificationType().getAllParameters()); + } + res.putAll(ownParameters); + return res; + } + + /** * Find the parameter relating to the given string in first the space if it in not there * then the classification is asked for it *************** *** 2823,2828 **** */ public Attribute getParameter(String string) { ! //TODO make space hold own parameters ! return getClassificationType().getParameter(string); } } --- 2815,2823 ---- */ public Attribute getParameter(String string) { ! Attribute a = ownParameters.get(string); ! if (a == null) { ! a = getClassificationType().getParameter(string); ! } ! return a; } } Index: ClassificationType.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ClassificationType.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ClassificationType.java 26 Jun 2007 10:56:54 -0000 1.2 --- ClassificationType.java 23 Jul 2007 13:58:13 -0000 1.3 *************** *** 8,12 **** import java.util.ArrayList; ! import java.util.LinkedList; import java.util.List; --- 8,12 ---- import java.util.ArrayList; ! import java.util.LinkedHashMap; import java.util.List; *************** *** 16,26 **** * @author Rimestad */ ! public class ClassificationType { private static int nextClassificationId = 0; ! private String name; ! private List<Attribute> parameter; ! private List<ClassificationType> subTypes; ! private int index; private long id; /** --- 16,24 ---- * @author Rimestad */ ! public class ClassificationType extends Structure<ClassificationType> implements Parametric { private static int nextClassificationId = 0; ! private LinkedHashMap<String, Attribute> parameter; private long id; + private int index; /** *************** *** 33,39 **** public ClassificationType(String name, double uvalue, double density, double cost) { this(); setId(nextClassificationId); nextClassificationId++; ! this.name = name; addParameter("uvalue", uvalue); addParameter("density", density); --- 31,38 ---- public ClassificationType(String name, double uvalue, double density, double cost) { this(); + setIndex(-1); setId(nextClassificationId); nextClassificationId++; ! setName(name); addParameter("uvalue", uvalue); addParameter("density", density); *************** *** 45,97 **** */ public ClassificationType() { ! subTypes = new LinkedList<ClassificationType>(); ! parameter = new LinkedList<Attribute>(); ! } ! ! /** ! * Add a type as subtype to this ! * @param subType the type to add ! */ ! public void addSubType(ClassificationType subType) { ! subTypes.add(subType); ! subType.setIndex(subTypes.size() - 1); ! } ! ! /** ! * Set the index of the classificationType ! * @param i The index ! */ ! private void setIndex(int i) { ! this.index = i; ! } ! ! /** ! * Return the index of the classificationType ! * @return The index ! */ ! public int getIndex() { ! return this.index; ! } ! ! /** ! * Return the name ! * @return the name ! */ ! public String getName() { ! return name; ! } ! ! /** ! * @param name the name to set ! */ ! public void setName(String name) { ! this.name = name; } /** ! * @return the subTypes */ ! public List<ClassificationType> getSubTypes() { ! return subTypes; } --- 44,58 ---- */ public ClassificationType() { ! super(); ! parameter = new LinkedHashMap<String, Attribute>(); } /** ! * {@inheritDoc} */ ! @Override ! public void addChild(ClassificationType child) { ! super.addChild(child); ! child.setIndex(getChildren().size() - 1); } *************** *** 102,108 **** public List<Attribute> getAttributes() { List<Attribute> res = new ArrayList<Attribute>(); ! res.add(new Attribute("Name", name)); ! res.add(new Attribute("Letter", (char)(index + 'A'))); ! res.addAll(getParameters()); return res; } --- 63,68 ---- public List<Attribute> getAttributes() { List<Attribute> res = new ArrayList<Attribute>(); ! res.add(new Attribute("Name", getName())); ! res.addAll(getAllParameters().values()); return res; } *************** *** 113,118 **** */ public void setAttributes(List<Attribute> attributes) { for (Attribute a : attributes) { - parameter.clear(); if (a.getName().equals("Name")) { continue; --- 73,78 ---- */ public void setAttributes(List<Attribute> attributes) { + parameter.clear(); for (Attribute a : attributes) { if (a.getName().equals("Name")) { continue; *************** *** 121,125 **** continue; } ! parameter.add(a); } } --- 81,85 ---- continue; } ! addParameter(a.getName(), a.getValue()); } } *************** *** 129,133 **** * @return the parameters */ ! public List<Attribute> getParameters() { return parameter; } --- 89,93 ---- * @return the parameters */ ! public LinkedHashMap<String, Attribute> getAllParameters() { return parameter; } *************** *** 139,143 **** */ private void addParameter(String name, Object o) { ! parameter.add(new Attribute(name, o, true)); } --- 99,103 ---- */ private void addParameter(String name, Object o) { ! parameter.put(name, new Attribute(name, o, true)); } *************** *** 149,159 **** */ public Attribute getParameter(String string) { ! //TODO make space hold own parameters ! for (Attribute a : getAttributes()) { ! if (a.getName().equalsIgnoreCase(string)) { ! return a; ! } ! } ! return null; } --- 109,114 ---- */ public Attribute getParameter(String string) { ! Attribute a = parameter.get(string); ! return a; } *************** *** 162,166 **** */ public String toString() { ! return name; } --- 117,121 ---- */ public String toString() { ! return getName(); } *************** *** 180,182 **** --- 135,188 ---- this.id = id; } + + /** + * {@inheritDoc} + */ + public String getGeneralName() { + return "Classification Type"; + } + + /** + * @return the index + */ + public int getIndex() { + return index; + } + + /** + * @param index the index to set + */ + public void setIndex(int index) { + this.index = index; + } + + /** + * A sptring prefix for the type + * @return The prefix + */ + public String getPrefix() { + String res = ""; + if (getParent() == null || getParent() == this) { + return res; + } + res = getParent().getPrefix() + String.valueOf((char)('A' + index)); + return res; + } + + /** + * Check if a ClassificationType is one of the given subtypes + * @param cst The classificationType + * @return Wether or not it is a usable type + */ + public boolean isPossibleSubtype(ClassificationType cst) { + if (this == cst) { + return true; + } + for (ClassificationType c : getChildren()) { + if (c.isPossibleSubtype(cst)) { + return true; + } + } + return false; + } } |