[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Space.java, 1.151, 1.152 Persistence
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-06-26 10:57:07
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv9759/src/net/sourceforge/bprocessor/model Modified Files: Space.java Persistence.java Classification.java ClassificationType.java EnergyCalc.java Project.java ClassificationFileReader.java Log Message: Maded the readin of classification xml and made classificationType be only a container holding a list of parameters. Made all classes using classificationType reflect that. Now Classification only know of its possible ClassificationTypes and Space know which one is chosen Index: ClassificationFileReader.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ClassificationFileReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ClassificationFileReader.java 25 Jun 2007 10:26:46 -0000 1.1 --- ClassificationFileReader.java 26 Jun 2007 10:56:54 -0000 1.2 *************** *** 37,42 **** } else { PropertyConfigurator.configure(args[1]); ! Classification construction = ClassificationFileReader.loadClassification(true, args[0]); ! Persistence.saveClassification(construction, new File(args[0] + "Construction.xml")); } } catch (Exception e) { --- 37,52 ---- } else { PropertyConfigurator.configure(args[1]); ! Map<String, ClassificationType> typeMap = loadTypes(args[0]); ! Classification construction = ! ClassificationFileReader.loadClassification(true, args[0], typeMap); ! Classification functional = ! ClassificationFileReader.loadClassification(false, args[0], typeMap); ! Persistence.saveDBK(construction, functional, typeMap.values(), ! new File(args[0] + "Classification.xml")); ! log.info("Wrote XML"); ! Classification[] loaded = Persistence.loadDBK(new File(args[0] + "Classification.xml")); ! construction = loaded[0]; ! functional = loaded[1]; ! log.info("Read XML"); } } catch (Exception e) { *************** *** 63,69 **** ClassificationType currentClassificationType = null; ClassificationType superClassificationType = null; - ClassificationType defaultType = - new ClassificationType("default", 0.0, 0.0, 0.0); - res.put("default", defaultType); while ((currentLine = bf.readLine()) != null) { lineNumber++; --- 73,76 ---- *************** *** 109,117 **** * @param locationPrefix The folder location for the files * @param construction true if its construction space classification, false if functional * @return The loaded classification */ ! public static Classification loadClassification(boolean construction, String locationPrefix) throws IOException { - Map<String, ClassificationType> typeMap = loadTypes(locationPrefix); Classification clas; String current = ""; --- 116,125 ---- * @param locationPrefix The folder location for the files * @param construction true if its construction space classification, false if functional + * @param typeMap A map from name to type * @return The loaded classification */ ! public static Classification loadClassification( ! boolean construction, String locationPrefix, Map<String, ClassificationType> typeMap) throws IOException { Classification clas; String current = ""; *************** *** 129,138 **** new InputStreamReader( new FileInputStream(locationPrefix + "construction2.txt"), "ISO-8859-1")); ! clas = new Classification("-1", "Constructional", null, Classification.CONSTRUCTION); } else { bf = new BufferedReader( new InputStreamReader( new FileInputStream(locationPrefix + "functionals.txt"), "ISO-8859-1")); ! clas = new Classification("-1", "Functional", null, Classification.FUNCTIONAL); } current = bf.readLine(); --- 137,146 ---- new InputStreamReader( new FileInputStream(locationPrefix + "construction2.txt"), "ISO-8859-1")); ! clas = new Classification("-1", "Constructional", null, Space.CONSTRUCTION); } else { bf = new BufferedReader( new InputStreamReader( new FileInputStream(locationPrefix + "functionals.txt"), "ISO-8859-1")); ! clas = new Classification("-1", "Functional", null, Space.FUNCTIONAL); } current = bf.readLine(); *************** *** 151,155 **** ClassificationType typesForCur = typeMap.get(curname); if (typesForCur == null) { ! typesForCur = typeMap.get("default"); } curclas.setPossibleTypes(typesForCur); --- 159,165 ---- ClassificationType typesForCur = typeMap.get(curname); if (typesForCur == null) { ! //If type is not there make a new one for it ! typesForCur = new ClassificationType(curname, 0, 0, 0); ! typeMap.put(curname, typesForCur); } curclas.setPossibleTypes(typesForCur); Index: Classification.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Classification.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Classification.java 25 Jun 2007 10:26:45 -0000 1.18 --- Classification.java 26 Jun 2007 10:56:54 -0000 1.19 *************** *** 28,51 **** /** The children of this classification */ ! private Vector<Classification> children = new Vector<Classification>(); /** The parent of this classification */ private Classification parent; - /** The type of this classification */ - private ClassificationType classificationType; - /** The classification */ private ClassificationType possibleTypes; - /** Construction Type */ - public static final int CONSTRUCTION = 0; - - /** functional Type */ - public static final int FUNCTIONAL = 1; - - /** functional Type */ - public static final int TYPES = 2; - /** type */ private int type; --- 28,39 ---- /** The children of this classification */ ! private Vector<Classification> children; /** The parent of this classification */ private Classification parent; /** The classification */ private ClassificationType possibleTypes; /** type */ private int type; *************** *** 59,62 **** --- 47,51 ---- */ public Classification(String id, String name, Classification parent, int type) { + this(); setName(name); setId(id); *************** *** 83,86 **** --- 72,82 ---- /** + * Persistence constructor + */ + public Classification() { + children = new Vector<Classification>(); + } + + /** * Get the vector containing this classifications children * @return the children *************** *** 233,241 **** res.add(new Attribute("Name", getName(), false)); res.add(new Attribute("Code", getFullId(null), false)); ! res.add(new Attribute("U-value", getUvalue(), true)); ! res.add(new Attribute("Density", getDensity(), true)); ! if (classificationType != null) { ! res.add(new Attribute("Type", classificationType)); ! } return res; } --- 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; } *************** *** 254,293 **** while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); - if (a.getName().equals("Type")) { - setClassificationType((ClassificationType)a.getValue()); - } } } - - - /** - * Get the U-value for this classification - * @return uvalue the U-value - */ - public Double getUvalue() { - return getClassificationType().getUvalue(); - } - - /** - * Get the density for this classification - * @return density the density - */ - public Double getDensity() { - return getClassificationType().getDensity(); - } - - /** - * Return the product type - * @return The product type - */ - public ClassificationType getClassificationType() { - return classificationType; - } - /** - * Set the product type - * @param productType The product type - */ - public void setClassificationType(ClassificationType productType) { - this.classificationType = productType; - } } --- 246,250 ---- Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Persistence.java 25 Jun 2007 10:26:46 -0000 1.39 --- Persistence.java 26 Jun 2007 10:56:54 -0000 1.40 *************** *** 1,1490 **** ! //--------------------------------------------------------------------------------- ! // $Id$ ! // ! // 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 net.sourceforge.bprocessor.model.modellor.Modellor; ! import net.sourceforge.bprocessor.model.xml.AxisRotateType; [...3035 lines suppressed...] ! } else if (val instanceof BooleanType) { ! content.add(new Attribute(elem.getKey(), ((BooleanType)val).isBoolean())); ! } else if (val instanceof DoubleType) { ! content.add(new Attribute(elem.getKey(), new Double(((DoubleType)val).getDouble()))); ! } else if (val instanceof RefType) { ! content.add(new Attribute(elem.getKey(), get(((RefType)val).getRef(), map))); ! } else { ! log.warn("Non supported type"); ! } ! } ! res.setAttributes(content); ! ! for (XMLSpecificTypeType subType : (List<XMLSpecificTypeType>)type.getXMLSpecificType()) { ! ClassificationType out = internalizeTypes(subType, map); ! res.addSubType(out); ! } ! map.put(res.getId(), res); ! return res; ! } ! } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.129 retrieving revision 1.130 diff -C2 -d -r1.129 -r1.130 *** Project.java 25 Jun 2007 10:26:45 -0000 1.129 --- Project.java 26 Jun 2007 10:56:54 -0000 1.130 *************** *** 1,934 **** ! //--------------------------------------------------------------------------------- ! // $Id$ ! // ! // 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.io.File; [...1843 lines suppressed...] ! Iterator it = cl.getChildren().iterator(); ! while (it.hasNext()) { ! Classification current = (Classification) it.next(); ! if (curid.equalsIgnoreCase(current.getId())) { ! cl = current; ! } ! } ! } ! } ! return cl; ! } ! ! /** ! * getter for the copy buffer ! * @return The copyBuffer ! */ ! public Collection<Geometric> getCopyBuffer() { ! return copyBuffer; ! } ! } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.151 retrieving revision 1.152 diff -C2 -d -r1.151 -r1.152 *** Space.java 25 Jun 2007 10:26:45 -0000 1.151 --- Space.java 26 Jun 2007 10:56:54 -0000 1.152 *************** *** 154,158 **** /** the room the space belongs to */ private String room = "0"; ! /** * Constructor for persistence layer --- 154,158 ---- /** the room the space belongs to */ private String room = "0"; ! /** * Constructor for persistence layer *************** *** 1566,1570 **** } } ! if (getClassification() != null && getClassification().getClassificationType() != null) { //TODO make classificationType attribute //res.add(new Attribute("Type", getClassification().getClassificationType(), --- 1566,1570 ---- } } ! if (getClassification() != null && getClassificationType() != null) { //TODO make classificationType attribute //res.add(new Attribute("Type", getClassification().getClassificationType(), *************** *** 2984,2986 **** --- 2984,2997 ---- 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 + * @param string The string representation of the wanted parameter + * @return The resulting parameter + */ + public Attribute getParameter(String string) { + //TODO make space hold own parameters + return getClassificationType().getParameter(string); + } } Index: EnergyCalc.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/EnergyCalc.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** EnergyCalc.java 29 Mar 2007 22:00:12 -0000 1.8 --- EnergyCalc.java 26 Jun 2007 10:56:54 -0000 1.9 *************** *** 65,69 **** if (classification.getClassification().getFullId(null).equalsIgnoreCase("-210.01")) { ! loss = classification.getClassification().getUvalue() * current.getArea(); //loss = 0.15 * current.getArea(); return loss; --- 65,69 ---- if (classification.getClassification().getFullId(null).equalsIgnoreCase("-210.01")) { ! loss = (Double)classification.getParameter("uvalue").getValue() * current.getArea(); //loss = 0.15 * current.getArea(); return loss; *************** *** 71,90 **** if (classification.getClassification().getFullId(null).equalsIgnoreCase("-215.01") || classification.getClassification().getFullId(null).equalsIgnoreCase("-215")) { ! loss = classification.getClassification().getUvalue() * current.getArea(); //loss = 0.15 * current.getArea(); return loss; } if (classification.getClassification().getFullId(null).equalsIgnoreCase("-215.04")) { ! loss = classification.getClassification().getUvalue() * current.getArea(); //loss = 0.15 * current.getArea(); return loss; } if (classification.getClassification().getFullId(null).equalsIgnoreCase("-205")) { ! loss = classification.getClassification().getUvalue() * current.getArea(); //loss = 0.25 * current.getArea(); return loss; } if (classification.getClassification().getFullId(null).equalsIgnoreCase("-205.01")) { ! loss = classification.getClassification().getUvalue() * current.getArea(); return loss; } --- 71,90 ---- if (classification.getClassification().getFullId(null).equalsIgnoreCase("-215.01") || classification.getClassification().getFullId(null).equalsIgnoreCase("-215")) { ! loss = (Double)classification.getParameter("uvalue").getValue() * current.getArea(); //loss = 0.15 * current.getArea(); return loss; } if (classification.getClassification().getFullId(null).equalsIgnoreCase("-215.04")) { ! loss = (Double)classification.getParameter("uvalue").getValue() * current.getArea(); //loss = 0.15 * current.getArea(); return loss; } if (classification.getClassification().getFullId(null).equalsIgnoreCase("-205")) { ! loss = (Double)classification.getParameter("uvalue").getValue() * current.getArea(); //loss = 0.25 * current.getArea(); return loss; } if (classification.getClassification().getFullId(null).equalsIgnoreCase("-205.01")) { ! loss = (Double)classification.getParameter("uvalue").getValue() * current.getArea(); return loss; } *************** *** 101,105 **** if (classification.getClassification(). getFullId(null).equalsIgnoreCase("-205.02")) { ! loss = classification.getClassification().getUvalue() * current.getArea(); //loss = 0.8 * current.getArea(); return loss; --- 101,105 ---- if (classification.getClassification(). getFullId(null).equalsIgnoreCase("-205.02")) { ! loss = (Double)classification.getParameter("uvalue").getValue() * current.getArea(); //loss = 0.8 * current.getArea(); return loss; Index: ClassificationType.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ClassificationType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ClassificationType.java 25 Jun 2007 10:26:45 -0000 1.1 --- ClassificationType.java 26 Jun 2007 10:56:54 -0000 1.2 *************** *** 1,173 **** ! //--------------------------------------------------------------------------------- ! // $Id$ ! // ! // 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.ArrayList; ! import java.util.LinkedList; ! import java.util.List; ! ! /** ! * A placeholder for the different kind of types that can be ! * associated with the classifications ! * @author Rimestad ! */ ! public class ClassificationType { ! private String name; ! private double uvalue; ! private double density; ! private double cost; ! private List<ClassificationType> subTypes; ! private int index; ! ! /** ! * constructor ! * @param name The name for the type ! * @param uvalue the heatloss value ! * @param density the density ! * @param cost the cost pr m2 ! */ ! public ClassificationType(String name, double uvalue, double density, double cost) { ! this.name = name; ! this.uvalue = uvalue; ! this.density = density; ! this.cost = cost; ! ! subTypes = new LinkedList<ClassificationType>(); ! } ! ! /** ! * 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 cost value for the type ! * @return the cost ! */ ! public double getCost() { ! return cost; ! } ! ! /** ! * Set the cost for the type ! * @param cost the cost to set ! */ ! public void setCost(double cost) { ! this.cost = cost; ! } ! ! /** ! * Return the density of the type ! * @return the density ! */ ! public double getDensity() { ! return density; ! } ! ! /** ! * Set the density ! * @param density the density to set ! */ ! public void setDensity(double density) { ! this.density = density; ! } ! ! /** ! * 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 uvalue ! */ ! public double getUvalue() { ! return uvalue; ! } ! ! /** ! * @param uvalue the uvalue to set ! */ ! public void setUvalue(double uvalue) { ! this.uvalue = uvalue; ! } ! ! /** ! * @return the subTypes ! */ ! public List<ClassificationType> getSubTypes() { ! return subTypes; ! } ! ! /** ! * Getter for object attributes ! * @return the attributes associated with this object ! */ ! public List<Attribute> getAttributes() { ! List<Attribute> res = new ArrayList<Attribute>(); ! res.add(new Attribute("U-value", uvalue, true)); ! res.add(new Attribute("Density", density, true)); ! res.add(new Attribute("Cost", cost, true)); ! return res; ! } ! ! /** ! * Set the attribute values ! * @param attributes The new attribute values ! */ ! public void setAttributes(List<Attribute> attributes) { ! for (Attribute a : attributes) { ! if (a.getName().equals("U-value")) { ! uvalue = (Double)a.getValue(); ! continue; ! } ! if (a.getName().equals("Density")) { ! density = (Double)a.getValue(); ! continue; ! } ! if (a.getName().equals("Cost")) { ! cost = (Double)a.getValue(); ! } ! } ! } ! ! /** ! * {@inheritDoc} ! */ ! public String toString() { ! return name; ! } ! } --- 1,182 ---- ! //--------------------------------------------------------------------------------- ! // $Id$ ! // ! // 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.ArrayList; ! import java.util.LinkedList; ! import java.util.List; ! ! /** ! * A placeholder for the different kind of types that can be ! * associated with the classifications ! * @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; ! ! /** ! * constructor ! * @param name The name for the type ! * @param uvalue the heatloss value ! * @param density the density ! * @param cost the cost pr m2 ! */ ! public ClassificationType(String name, double uvalue, double density, double cost) { ! this(); ! setId(nextClassificationId); ! nextClassificationId++; ! this.name = name; ! addParameter("uvalue", uvalue); ! addParameter("density", density); ! addParameter("cost", cost); ! } ! ! /** ! * A constructor for the persistencs ! */ ! 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; ! } ! ! /** ! * Getter for object attributes ! * @return the attributes associated with this object ! */ ! 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; ! } ! ! /** ! * Set the attribute values ! * @param attributes The new attribute values ! */ ! public void setAttributes(List<Attribute> attributes) { ! for (Attribute a : attributes) { ! parameter.clear(); ! if (a.getName().equals("Name")) { ! continue; ! } ! if (a.getName().equals("Letter")) { ! continue; ! } ! parameter.add(a); ! } ! } ! ! /** ! * Getter for parameters ! * @return the parameters ! */ ! public List<Attribute> getParameters() { ! return parameter; ! } ! ! /** ! * Add a parameter to the Classification ! * @param name The name of the paramter ! * @param o The object linked to the name ! */ ! private void addParameter(String name, Object o) { ! parameter.add(new Attribute(name, o, true)); ! } ! ! /** ! * Find the parameter relating to the given string in first the space if it in not there ! * then the classification is asked for it ! * @param string The string representation of the wanted parameter ! * @return The resulting parameter ! */ ! public Attribute getParameter(String string) { ! //TODO make space hold own parameters ! for (Attribute a : getAttributes()) { ! if (a.getName().equalsIgnoreCase(string)) { ! return a; ! } ! } ! return null; ! } ! ! /** ! * {@inheritDoc} ! */ ! public String toString() { ! return name; ! } ! ! /** ! * Getter for id ! * @return the id ! */ ! public long getId() { ! return id; ! } ! ! /** ! * Setter for id ! * @param id The new id ! */ ! public void setId(long id) { ! this.id = id; ! } ! } |