create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / file / rocksim / importt / FinSetHandler.java
index 1ddb5677ef9dc82d6f70dec1e9264bdb288b4441..01b49030d0ccf1428bee439da11601780e7416ac 100644 (file)
@@ -4,6 +4,10 @@
 package net.sf.openrocket.file.rocksim.importt;
 
 import net.sf.openrocket.aerodynamics.WarningSet;
+import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
+import net.sf.openrocket.file.rocksim.RocksimFinishCode;
+import net.sf.openrocket.file.rocksim.RocksimLocationMode;
+import net.sf.openrocket.file.simplesax.AbstractElementHandler;
 import net.sf.openrocket.file.simplesax.ElementHandler;
 import net.sf.openrocket.file.simplesax.PlainTextHandler;
 import net.sf.openrocket.material.Material;
@@ -28,7 +32,7 @@ import java.util.List;
  * characteristics are kept here until the closing FinSet tag. At that point, <code>asOpenRocket</code> method is called
  * to construct the corresponding OpenRocket FinSet.
  */
-class FinSetHandler extends ElementHandler {
+class FinSetHandler extends AbstractElementHandler {
     /**
      * The parent component.
      */
@@ -159,80 +163,80 @@ class FinSetHandler extends ElementHandler {
     public void closeElement (String element, HashMap<String, String> attributes, String content, WarningSet warnings)
             throws SAXException {
         try {
-            if ("Name".equals(element)) {
+            if (RocksimCommonConstants.NAME.equals(element)) {
                 name = content;
             }
-            if ("Material".equals(element)) {
+            if (RocksimCommonConstants.MATERIAL.equals(element)) {
                 materialName = content;
             }
-            if ("FinishCode".equals(element)) {
+            if (RocksimCommonConstants.FINISH_CODE.equals(element)) {
                 finish = RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket();
             }
-            if ("Xb".equals(element)) {
-                location = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.XB.equals(element)) {
+                location = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("LocationMode".equals(element)) {
+            if (RocksimCommonConstants.LOCATION_MODE.equals(element)) {
                 position = RocksimLocationMode.fromCode(Integer.parseInt(content)).asOpenRocket();
             }
-            if ("FinCount".equals(element)) {
+            if (RocksimCommonConstants.FIN_COUNT.equals(element)) {
                 finCount = Integer.parseInt(content);
             }
-            if ("RootChord".equals(element)) {
-                rootChord = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.ROOT_CHORD.equals(element)) {
+                rootChord = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("TipChord".equals(element)) {
-                tipChord = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.TIP_CHORD.equals(element)) {
+                tipChord = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("SemiSpan".equals(element)) {
-                semiSpan = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.SEMI_SPAN.equals(element)) {
+                semiSpan = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
             if ("MidChordLen".equals(element)) {
-                midChordLen = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+                midChordLen = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("SweepDistance".equals(element)) {
-                sweepDistance = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.SWEEP_DISTANCE.equals(element)) {
+                sweepDistance = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("Thickness".equals(element)) {
-                thickness = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.THICKNESS.equals(element)) {
+                thickness = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("TipShapeCode".equals(element)) {
+            if (RocksimCommonConstants.TIP_SHAPE_CODE.equals(element)) {
                 tipShapeCode = Integer.parseInt(content);
             }
-            if ("TabLength".equals(element)) {
-                tabLength = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.TAB_LENGTH.equals(element)) {
+                tabLength = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("TabDepth".equals(element)) {
-                tabDepth = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.TAB_DEPTH.equals(element)) {
+                tabDepth = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("TabOffset".equals(element)) {
-                taboffset = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.TAB_OFFSET.equals(element)) {
+                taboffset = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
-            if ("RadialAngle".equals(element)) {
+            if (RocksimCommonConstants.RADIAL_ANGLE.equals(element)) {
                 radialAngle = Double.parseDouble(content);
             }
-            if ("ShapeCode".equals(element)) {
+            if (RocksimCommonConstants.SHAPE_CODE.equals(element)) {
                 shapeCode = Integer.parseInt(content);
             }
-            if ("PointList".equals(element)) {
+            if (RocksimCommonConstants.POINT_LIST.equals(element)) {
                 pointList = content;
             }
-            if ("KnownMass".equals(element)) {
-                mass = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
+            if (RocksimCommonConstants.KNOWN_MASS.equals(element)) {
+                mass = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
             }
-            if ("Density".equals(element)) {
-                density = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
+            if (RocksimCommonConstants.DENSITY.equals(element)) {
+                density = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
             }
-            if ("KnownCG".equals(element)) {
-                cg = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
+            if (RocksimCommonConstants.KNOWN_CG.equals(element)) {
+                cg = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
             }
-            if ("UseKnownCG".equals(element)) {
+            if (RocksimCommonConstants.USE_KNOWN_CG.equals(element)) {
                 override = "1".equals(content);
             }
-            if ("CalcMass".equals(element)) {
-                calcMass = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS;
+            if (RocksimCommonConstants.CALC_MASS.equals(element)) {
+                calcMass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
             }
-            if ("CalcCg".equals(element)) {
-                calcCg = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+            if (RocksimCommonConstants.CALC_CG.equals(element)) {
+                calcCg = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
         }
         catch (NumberFormatException nfe) {
@@ -326,15 +330,15 @@ class FinSetHandler extends ElementHandler {
      */
     private Coordinate[] toCoordinates (String pointList, WarningSet warnings) {
         List<Coordinate> result = new ArrayList<Coordinate>();
-        if (pointList != null && !pointList.isEmpty()) {
+        if (pointList != null && pointList.length() > 0) {
             String[] points = pointList.split("\\Q|\\E");
             for (String point : points) {
                 String[] aPoint = point.split(",");
                 try {
                     if (aPoint.length > 1) {
                         Coordinate c = new Coordinate(
-                                Double.parseDouble(aPoint[0]) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH,
-                                Double.parseDouble(aPoint[1]) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
+                                Double.parseDouble(aPoint[0]) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH,
+                                Double.parseDouble(aPoint[1]) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
                         result.add(c);
                     }
                     else {