[Bprocessor-commit] /model/src/net/sourceforge/bprocessor/model ClassificationType.java, NONE, 1.1
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-06-25 10:26:47
|
Update of /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21452/src/net/sourceforge/bprocessor/model Modified Files: Classification.java Space.java Project.java Persistence.java Added Files: ClassificationType.java ClassificationFileReader.java Log Message: Have refactored loadClassification and loadType as well as the storing of the types out of the Project and into a new class ClassificationFileLoader. Made A ClassificationType Class holding all type specific info such as u-value etc. Made Classification hold a ClassificationType root for all the possible types it can be. The Space now hold the classification and a ClassificationType that is the chosen Type of the possible types in the chosen classification. Persistence now have mothods to externalize the DBK to XML, but still need a load mechanism. NOTICE THAT PERSISTENCE AND PROJECT SEEM TO HAVE CHANGED INTIRELY BUT THEY HAVEN'T ONLY THE THINGS MENTIONED HERE HAVE BEEN CHANGED --- NEW FILE: ClassificationFileReader.java --- //--------------------------------------------------------------------------------- // $Id: ClassificationFileReader.java,v 1.1 2007/06/25 10:26:46 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.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; /** * A Class for reading in classifications in from txt files */ public class ClassificationFileReader { /** The logger */ private static Logger log = Logger.getLogger(ClassificationFileReader.class); /** * @param args The arguments */ public static void main(String[] args) { // TODO Auto-generated method stub try { if (args.length != 2) { System.out.println("Specify 1'st file prefix 2'nd log settings file"); } else { PropertyConfigurator.configure(args[1]); Classification construction = ClassificationFileReader.loadClassification(true, args[0]); Persistence.saveClassification(construction, new File(args[0] + "Construction.xml")); } } catch (Exception e) { log.error("Wern't able to load types and save it to xml got error:\n" + e.toString()); } } /** * This method loads the product classificationTypes * from a file into the loaded construction classification * @param locationPrefix The folderlocation of the type files * @exception IOException Thrown if an there were problems locating or reading file * @return The loaded classificationname to classificationType map */ public static Map<String, ClassificationType> loadTypes(String locationPrefix) throws IOException { Map<String, ClassificationType> res = new HashMap<String, ClassificationType>(); BufferedReader bf; bf = new BufferedReader( new InputStreamReader(new FileInputStream(locationPrefix + "typer.txt"), "ISO-8859-1")); String currentLine = ""; int lineNumber = 0; 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++; String[] tokens = currentLine.split(";"); if (tokens.length == 0) { continue; } if (!tokens[0].equals("")) { superClassificationType = new ClassificationType(tokens[0], 0, 0, 0); res.put(tokens[0], superClassificationType); continue; } if (tokens.length < 5) { continue; } if (!tokens[3].equals("")) { //classificationTypes currentClassificationType = new ClassificationType(tokens[4], 0.0, 0.0, 0.0); superClassificationType.addSubType(currentClassificationType); continue; } if (tokens.length < 6) { continue; } if (!tokens[4].equals("")) { //subtypes if (currentClassificationType != null) { currentClassificationType.addSubType( new ClassificationType(tokens[5], 0.0, 0.0, 0.0)); } else { log.error("Error in type file format at line " + currentLine); } } } bf.close(); return res; } /** * This method loads the classification document from a file * @exception IOException Thrown if there were problems locating or reading the file * @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 = ""; String token = ""; String curname = ""; String curid; boolean clasmade = false; Classification parent = null; Classification last = null; int depth = 0; int lastdepth = 0; BufferedReader bf; if (construction) { bf = new BufferedReader( 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(); while (current != null) { StringTokenizer st = new StringTokenizer(current, ";", true); while (st.hasMoreTokens()) { token = st.nextToken(); if (!clasmade) { if (depth == 0 && !token.equalsIgnoreCase(";")) { curid = new String(token); st.nextToken(); curname = st.nextToken(); Classification curclas; if (construction) { curclas = new Classification(curid, curname, clas, 0); ClassificationType typesForCur = typeMap.get(curname); if (typesForCur == null) { typesForCur = typeMap.get("default"); } curclas.setPossibleTypes(typesForCur); clasmade = true; } else { curclas = new Classification(curid, curname, clas, 1); //curclas.setPossibleTypes(possibleTypes); clasmade = true; } parent = curclas; clas.addChild(curclas); lastdepth = 0; last = curclas; } else if (token.equalsIgnoreCase(";")) { depth++; } else if (depth != 0 && !token.equalsIgnoreCase(";")) { curid = new String(token); st.nextToken(); curname = st.nextToken(); if (depth > lastdepth) { parent = last; } if (depth < lastdepth) { parent = parent.getParent(); } Classification curclas; if (construction) { curclas = new Classification(curid, curname, parent, 0); curclas.setPossibleTypes(typeMap.get(curname)); clasmade = true; } else { curclas = new Classification(curid, curname, parent, 1); clasmade = true; } parent.addChild(curclas); last = curclas; lastdepth = depth; } } else { if (!token.equalsIgnoreCase(";")) { last.setName(token); } } } depth = 0; current = bf.readLine(); clasmade = false; } if (construction) { clas.addChild( new Classification("-99", "Egne klassifikationer", clas, 0)); } else { clas.addChild( new Classification("-99", "Egne klassifikationer", clas, 1)); } bf.close(); return clas; } } Index: Classification.java =================================================================== RCS file: /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model/Classification.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Classification.java 30 May 2007 11:28:49 -0000 1.17 --- Classification.java 25 Jun 2007 10:26:45 -0000 1.18 *************** *** 34,48 **** /** The type of this classification */ ! private String product; ! ! /** The uvalue the classification */ ! private Double uvalue = 0.0; ! ! /** The density the classification */ ! private Double density = 0.0; /** The classification */ ! private Classification productType; ! /** Construction Type */ --- 34,41 ---- /** The type of this classification */ ! private ClassificationType classificationType; /** The classification */ ! private ClassificationType possibleTypes; /** Construction Type */ *************** *** 69,74 **** setId(id); setType(type); ! setParent(parent); ! setProdukt(""); } --- 62,66 ---- setId(id); setType(type); ! setParent(parent); } *************** *** 79,86 **** */ public Classification(String name, int type) { ! setName(name); ! setType(type); ! setId("-1"); ! setProdukt(""); } --- 71,75 ---- */ public Classification(String name, int type) { ! this("-1", name, null, type); } *************** *** 90,97 **** */ public Classification(int type) { ! setName("Classification"); ! setId("0"); ! setType(type); ! setProdukt(""); } --- 79,83 ---- */ public Classification(int type) { ! this("0", "Classification", null, type); } *************** *** 169,181 **** Space current = cur; String fullId = id; ! if (current != null && current.getTypeClassification() != null) { if (!("" + fullId.charAt(0)).equalsIgnoreCase("-")) { ! if (!current.getTypeClassification().getId().equalsIgnoreCase("0")) { ! fullId = current.getTypeClassification().getId() + fullId; ! } } else { ! if (!current.getTypeClassification().getId().equalsIgnoreCase("0")) { ! fullId = "-" + current.getTypeClassification().getId() + fullId.replaceFirst("-", ""); ! } } } --- 155,163 ---- Space current = cur; 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("-", ""); } } *************** *** 228,244 **** /** ! * Get the different types for this classification * @return produkt the produkt types */ ! public String getProduct() { ! return product; } /** ! * Set the produkt type for this classification ! * @param produkt the produkt types */ ! public void setProdukt(String produkt) { ! this.product = produkt; } --- 210,226 ---- /** ! * Get the root type for this classification * @return produkt the produkt types */ ! public ClassificationType getPossibleTypes() { ! return possibleTypes; } /** ! * Set the classification type for this classification ! * @param rootType the root classification type */ ! public void setPossibleTypes(ClassificationType rootType) { ! this.possibleTypes = rootType; } *************** *** 253,258 **** res.add(new Attribute("U-value", getUvalue(), true)); res.add(new Attribute("Density", getDensity(), true)); ! if (productType != null) { ! res.add(new Attribute("Type", productType)); } return res; --- 235,240 ---- 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; *************** *** 272,283 **** while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); - if (a.getName().equals("U-value")) { - setUvalue((Double)a.getValue()); - } - if (a.getName().equals("Density")) { - setDensity((Double)a.getValue()); - } if (a.getName().equals("Type")) { ! setTypeClassification((Classification)a.getValue()); } } --- 254,259 ---- while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); if (a.getName().equals("Type")) { ! setClassificationType((ClassificationType)a.getValue()); } } *************** *** 290,302 **** */ public Double getUvalue() { ! return uvalue; ! } ! ! /** ! * Set the U-value for this classification ! * @param uvalue the U-value ! */ ! public void setUvalue(Double uvalue) { ! this.uvalue = uvalue; } --- 266,270 ---- */ public Double getUvalue() { ! return getClassificationType().getUvalue(); } *************** *** 306,320 **** */ public Double getDensity() { ! return density; ! } ! ! /** ! * Set the density for this classification ! * @param density the density ! */ ! public void setDensity(Double density) { ! this.density = density; } - /** --- 274,279 ---- */ public Double getDensity() { ! return getClassificationType().getDensity(); } /** *************** *** 322,327 **** * @return The product type */ ! public Classification getTypeClassification() { ! return productType; } /** --- 281,286 ---- * @return The product type */ ! public ClassificationType getClassificationType() { ! return classificationType; } /** *************** *** 329,334 **** * @param productType The product type */ ! public void setTypeClassification(Classification productType) { ! this.productType = productType; } } --- 288,293 ---- * @param productType The product type */ ! public void setClassificationType(ClassificationType productType) { ! this.classificationType = productType; } } Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Persistence.java 18 May 2007 19:08:17 -0000 1.38 --- Persistence.java 25 Jun 2007 10:26:46 -0000 1.39 *************** *** 1,1405 **** ! //--------------------------------------------------------------------------------- ! // $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; [...2866 lines suppressed...] ! * @return the xml object ! */ ! private static XMLSpecificType externalizeClassificationType(ClassificationType type) { ! XMLSpecificType xml = new XMLSpecificTypeImpl(); ! xml.setIndex(type.getIndex()); ! xml.setName(type.getName()); ! for (ClassificationType clasType : type.getSubTypes()) { ! if (clasType != null) { ! xml.getXMLSpecificType().add(Persistence.externalizeClassificationType(clasType)); ! } else { ! log.warn("One subtype in " + type + " were null"); ! } ! } ! Map map = new HashMap(); ! for (Attribute a : type.getAttributes()) { ! xml.getAttributes().add(externalizeKeyValue(a.getName(), a.getValue(), map)); ! } ! return xml; ! } ! } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** Project.java 19 Jun 2007 14:03:27 -0000 1.128 --- Project.java 25 Jun 2007 10:26:45 -0000 1.129 *************** *** 1,1181 **** ! //--------------------------------------------------------------------------------- ! // $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.BufferedReader; [...2086 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.150 retrieving revision 1.151 diff -C2 -d -r1.150 -r1.151 *** Space.java 7 Jun 2007 07:04:40 -0000 1.150 --- Space.java 25 Jun 2007 10:26:45 -0000 1.151 *************** *** 125,129 **** /** The classification */ ! private Classification productType; /** If the constructionspace is transparent */ --- 125,129 ---- /** The classification */ ! private ClassificationType productType; /** If the constructionspace is transparent */ *************** *** 1132,1136 **** * @return The product type */ ! public Classification getTypeClassification() { return productType; } --- 1132,1136 ---- * @return The product type */ ! public ClassificationType getClassificationType() { return productType; } *************** *** 1139,1143 **** * @param productType The product type */ ! public void setTypeClassification(Classification productType) { this.productType = productType; } --- 1139,1143 ---- * @param productType The product type */ ! public void setClassificationType(ClassificationType productType) { this.productType = productType; } *************** *** 1494,1498 **** } } else if (a.getName().equals("Type")) { ! setTypeClassification((((Classification)a.getClassification()))); } else if (a.getName().equals("Building")) { setBuilding(((String)a.getValue().toString())); --- 1494,1498 ---- } } else if (a.getName().equals("Type")) { ! //TODO make ClassificationType attributes } else if (a.getName().equals("Building")) { setBuilding(((String)a.getValue().toString())); *************** *** 1566,1572 **** } } ! if (getClassification() != null && !getClassification().getProduct().equalsIgnoreCase("")) { ! res.add(new Attribute("Type", Project.getInstance(). ! getType(getClassification().getName()), getTypeClassification(), this)); } if (isFunctionalSpace()) { --- 1566,1573 ---- } } ! if (getClassification() != null && getClassification().getClassificationType() != null) { ! //TODO make classificationType attribute ! //res.add(new Attribute("Type", getClassification().getClassificationType(), ! // getClassificationType(), this)); } if (isFunctionalSpace()) { --- NEW FILE: ClassificationType.java --- //--------------------------------------------------------------------------------- // $Id: ClassificationType.java,v 1.1 2007/06/25 10:26:45 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.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; } } |