Added protected copy constructor which makes a deep copy. This is used in the androi...
[debian/openrocket] / core / src / net / sf / openrocket / motor / ThrustCurveMotor.java
index 1f8acd2aa8a0316e877491138d0d3f0d7b9d3f24..8467c0a3ae9f5bfaeb261c6046b555bf08445343 100644 (file)
@@ -1,6 +1,5 @@
 package net.sf.openrocket.motor;
 
-import java.io.Serializable;
 import java.text.Collator;
 import java.util.Arrays;
 import java.util.Locale;
@@ -26,7 +25,7 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
        }
        private static final DesignationComparator DESIGNATION_COMPARATOR = new DesignationComparator();
        
-
+       private final String digest;
 
        private final Manufacturer manufacturer;
        private final String designation;
@@ -44,6 +43,31 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
        private double averageThrust;
        private double totalImpulse;
        
+       /**
+        * Deep copy constructor.
+        * Constructs a new ThrustCurveMotor from an existing ThrustCurveMotor.
+        * @param m
+        */
+       protected ThrustCurveMotor( ThrustCurveMotor m ) {
+               this.digest = m.digest;
+               this.manufacturer = m.manufacturer;
+               this.designation = m.designation;
+               this.description = m.description;
+               this.type = m.type;
+               this.delays = Arrays.copyOf(m.delays, m.delays.length);
+               this.diameter = m.diameter;
+               this.length = m.length;
+               this.time = Arrays.copyOf(m.time, m.time.length);
+               this.thrust = Arrays.copyOf(m.thrust, m.thrust.length);
+               this.cg = new Coordinate[ m.cg.length ];
+               for( int i = 0; i< cg.length; i++ ) {
+                       this.cg[i] = m.cg[i].clone();
+               }
+               this.maxThrust = m.maxThrust;
+               this.burnTime = m.burnTime;
+               this.averageThrust = m.averageThrust;
+               this.totalImpulse = m.totalImpulse;
+       }
        
        /**
         * Sole constructor.  Sets all the properties of the motor.
@@ -61,8 +85,8 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
         */
        public ThrustCurveMotor(Manufacturer manufacturer, String designation, String description,
                        Motor.Type type, double[] delays, double diameter, double length,
-                       double[] time, double[] thrust, Coordinate[] cg) {
-               
+                       double[] time, double[] thrust, Coordinate[] cg, String digest) {
+               this.digest = digest;
                // Check argument validity
                if ((time.length != thrust.length) || (time.length != cg.length)) {
                        throw new IllegalArgumentException("Array lengths do not match, " +
@@ -253,6 +277,10 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                return totalImpulse;
        }
        
+       @Override
+       public String getDigest() {
+               return digest;
+       }
        
 
        /**