Utils { public static double[] extract(int[] indicator, int value, double[] arr) { if (arr.length != indicator.length) { throw new IllegalArgumentException("Length of arr and indicator must be the same."); } int newLen = 0; for (int v: indicator) if (v == value) newLen++; double[] newx = new double[newLen]; int j = 0; for (int i=0; i<arr.length; i++) { if (indicator[i] == value) { newx[j] = arr[i]; j++; } } return newx; }  static double median(ArrayList<Double> arrList); static double mean(double[] x); static double[] interp(double[] x, double[] xp, double[] yp); static double stdev(double[] a); static double[] extract(int[] indicator, int value, double[] arr); static String array2string(double[] a, String format); static int argmax(double[] a); static int argmin(double[] a); static double findBestShift(double[] laserT, double[] touchT, double[] touchY);  }
@Test public void testExtract() { assertThat(Utils.extract(new int[]{1, 2, 2, 1, 2, 2, 1, 2, 2}, 1, new double[]{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}), is(new double[]{1.5, 4.5, 7.5})); }
@Test public void testExtract_empty() { assertThat(Utils.extract(new int[]{}, 1, new double[]{}), is(new double[]{})); }