1 package org.catacomb.numeric.data; 2 3 4 public final class DoubleArray { 5 6 7 double[] data; 8 int npoint; 9 10 11 public DoubleArray() { 12 data = new double[100]; 13 npoint = 0; 14 } 15 16 public DoubleArray(double[] da) { 17 data = da; 18 npoint = da.length; 19 } 20 21 22 public int getNPoint() { 23 return npoint; 24 } 25 26 public double[] getData() { 27 return data; 28 } 29 30 31 public void addPoint(double d) { 32 if (data == null) { 33 data = new double[100]; 34 } 35 36 if (npoint == data.length) { 37 double[] td = new double[2 * data.length]; 38 System.arraycopy(data, 0, td, 0, npoint); 39 data = td; 40 } 41 data[npoint++] = d; 42 } 43 44 45 public double getValue(int n) { 46 return (n >= 0 && n < npoint ? data[n] : 0.); 47 } 48 49 public double[] getCutDownArray() { 50 double[] da = new double[npoint]; 51 System.arraycopy(data, 0, da, 0, npoint); 52 return da; 53 } 54 }