From 34a5c097b7da493ce56f9170267b456c6e8d7bd4 Mon Sep 17 00:00:00 2001 From: Kevin Ruland Date: Wed, 16 May 2012 06:17:22 +0000 Subject: [PATCH] Added protected copy constructor which makes a deep copy. This is used in the android application so ExtendedThrustCurveMotor can extend ThrustCurveMotor instead of use delegation. --- .../sf/openrocket/motor/ThrustCurveMotor.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java index e1ba1d77c..8467c0a3a 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java @@ -43,6 +43,31 @@ public class ThrustCurveMotor implements Motor, Comparable { 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.