Had to implement Arrays.copyOf for doubles because froyo doesn't have that either.
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 18 Jul 2012 20:29:05 +0000 (20:29 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 18 Jul 2012 20:29:05 +0000 (20:29 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@906 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/motor/ThrustCurveMotor.java
core/src/net/sf/openrocket/util/ArrayUtils.java

index 8467c0a3ae9f5bfaeb261c6046b555bf08445343..0781c7c88ed5cbf499cc18d58eda15355b408ced 100644 (file)
@@ -7,6 +7,7 @@ import java.util.Locale;
 import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.models.atmosphere.AtmosphericConditions;
 import net.sf.openrocket.startup.Application;
+import net.sf.openrocket.util.ArrayUtils;
 import net.sf.openrocket.util.BugException;
 import net.sf.openrocket.util.Coordinate;
 import net.sf.openrocket.util.Inertia;
@@ -54,11 +55,11 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                this.designation = m.designation;
                this.description = m.description;
                this.type = m.type;
-               this.delays = Arrays.copyOf(m.delays, m.delays.length);
+               this.delays = ArrayUtils.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.time = ArrayUtils.copyOf(m.time, m.time.length);
+               this.thrust = ArrayUtils.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();
index 4202c53ce8623389b872f8184e69a866b171b793..ac32abbe0a057d42bac42a27e7ee7bf1bf6c0da7 100644 (file)
@@ -4,6 +4,10 @@ import java.lang.reflect.Array;
 
 public class ArrayUtils {
 
+       public static <T> T[] copyOf( T[] original, int length ) {
+               return copyOfRange(original,0,length);
+       }
+       
        /**
         * Implementation of java.util.Arrays.copyOfRange
         * 
@@ -42,5 +46,38 @@ public class ArrayUtils {
                return result;
                
        }
+
+       public static double[] copyOf( double[] original, int length ) {
+               return copyOfRange(original,0,length);
+       }
        
+       public static double[] copyOfRange( double[] original, int start, int end ) {
+               
+               if ( original == null ) {
+                       throw new NullPointerException();
+               }
+               
+               if ( start < 0 || start > original.length ) {
+                       throw new ArrayIndexOutOfBoundsException();
+               }
+               
+               if ( start > end ) {
+                       throw new IllegalArgumentException();
+               }
+               
+               double[] result = new double[(end-start)];
+               
+               int index = 0;
+               int stop = original.length < end ? original.length : end;
+               for ( int i = start; i < stop; i ++ ) {
+                       if ( i < original.length ) {
+                               result[index] = original[i];
+                       }
+                       index++;
+               }
+               
+               return result;
+               
+       }
+
 }