Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / simulation / FlightDataBranch.java
index f3eb3d9c751d1a7b0d6ef5faf6f3dff0e9ea22c3..76bef7642841cc5150969b912d1efd19032b8796 100644 (file)
@@ -68,7 +68,16 @@ public class FlightDataBranch implements Monitorable {
                }
        }
        
-       
+       /**
+        * Makes an 'empty' flight data branch which has no data but all built in data types are defined.
+        */
+       public FlightDataBranch() {
+               branchName = "Empty branch";
+               for (FlightDataType type : FlightDataType.ALL_TYPES){
+                       this.setValue(type, Double.NaN);
+               }
+               this.immute();
+       }
 
        /**
         * Adds a new point into the data branch.  The value for all types is set to NaN by default.
@@ -97,8 +106,8 @@ public class FlightDataBranch implements Monitorable {
                mutable.check();
                
                ArrayList<Double> list = values.get(type);
+               
                if (list == null) {
-                       
                        list = new ArrayList<Double>();
                        int n = getLength();
                        for (int i = 0; i < n; i++) {
@@ -106,10 +115,13 @@ public class FlightDataBranch implements Monitorable {
                        }
                        values.put(type, list);
                        minValues.put(type, value);
-                       maxValues.put(type, value);
-                       
+                       maxValues.put(type, value);             
                }
-               list.set(list.size() - 1, value);
+               
+               if (list.size() > 0){
+                       list.set(list.size() - 1, value);
+               }
+               
                double min = minValues.get(type);
                double max = maxValues.get(type);