@Test public void testGetDoubles2() { final List<Object> misc = new ArrayList<Object>(); misc.add(Long.valueOf(1L)); misc.add("-0.3"); final Object[] args = { misc, Boolean.valueOf(false) }; final double[] expectedValues = { 1.0, -0.3, 0.0 }; try { assertArrayEquals("getDoubles() failed!", expectedValues, FunctionUtil.getDoubles(args), 0.00001); } catch (final Exception e) { fail("getDoubles() failed!"); } }
public static double[] getDoubles(final Object[] args) throws FunctionError { final List<Double> numbers = new ArrayList<Double>(); for (int i = 0; i < args.length; ++i) { final Object arg = args[i]; if (arg instanceof List) { final List list = (List)arg; for (final Object listElement : list) { final Double d = convertToDouble(listElement); if (d == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a number.", i); numbers.add(d); } } else { final Double d = convertToDouble(arg); if (d == null) throw new FunctionError("can't convert \"" + arg + "\" to a number.", i); numbers.add(d); } } final double[] doubles = new double[numbers.size()]; int index = 0; for (final Double d : numbers) doubles[index++] = d; return doubles; }
FunctionUtil { public static double[] getDoubles(final Object[] args) throws FunctionError { final List<Double> numbers = new ArrayList<Double>(); for (int i = 0; i < args.length; ++i) { final Object arg = args[i]; if (arg instanceof List) { final List list = (List)arg; for (final Object listElement : list) { final Double d = convertToDouble(listElement); if (d == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a number.", i); numbers.add(d); } } else { final Double d = convertToDouble(arg); if (d == null) throw new FunctionError("can't convert \"" + arg + "\" to a number.", i); numbers.add(d); } } final double[] doubles = new double[numbers.size()]; int index = 0; for (final Double d : numbers) doubles[index++] = d; return doubles; } }
FunctionUtil { public static double[] getDoubles(final Object[] args) throws FunctionError { final List<Double> numbers = new ArrayList<Double>(); for (int i = 0; i < args.length; ++i) { final Object arg = args[i]; if (arg instanceof List) { final List list = (List)arg; for (final Object listElement : list) { final Double d = convertToDouble(listElement); if (d == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a number.", i); numbers.add(d); } } else { final Double d = convertToDouble(arg); if (d == null) throw new FunctionError("can't convert \"" + arg + "\" to a number.", i); numbers.add(d); } } final double[] doubles = new double[numbers.size()]; int index = 0; for (final Double d : numbers) doubles[index++] = d; return doubles; } private  FunctionUtil(); }
FunctionUtil { public static double[] getDoubles(final Object[] args) throws FunctionError { final List<Double> numbers = new ArrayList<Double>(); for (int i = 0; i < args.length; ++i) { final Object arg = args[i]; if (arg instanceof List) { final List list = (List)arg; for (final Object listElement : list) { final Double d = convertToDouble(listElement); if (d == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a number.", i); numbers.add(d); } } else { final Double d = convertToDouble(arg); if (d == null) throw new FunctionError("can't convert \"" + arg + "\" to a number.", i); numbers.add(d); } } final double[] doubles = new double[numbers.size()]; int index = 0; for (final Double d : numbers) doubles[index++] = d; return doubles; } private  FunctionUtil(); static double getArgAsDouble(final Object arg); static String getArgAsString(final Object arg); static long getArgAsLong(final Object arg); static boolean getArgAsBoolean(final Object arg); static double numericallySafeSum(final double a[]); static String getOrdinal(final int i); static double calcSampleVariance(final double[] x); static double[] listToArray(final List<Double> a); static boolean isScalarArgType(final Class type); static boolean isTypeOfList(final Class listClassCandidate); static void addScalarArgumentTypes(final List<Class> argTypes); static double[] getDoubles(final Object[] args); static long[] getLongs(final Object[] args); static String[] getStrings(final Object[] args); static boolean[] getBooleans(final Object[] args); static Object translateObjectType(final Object input); }
FunctionUtil { public static double[] getDoubles(final Object[] args) throws FunctionError { final List<Double> numbers = new ArrayList<Double>(); for (int i = 0; i < args.length; ++i) { final Object arg = args[i]; if (arg instanceof List) { final List list = (List)arg; for (final Object listElement : list) { final Double d = convertToDouble(listElement); if (d == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a number.", i); numbers.add(d); } } else { final Double d = convertToDouble(arg); if (d == null) throw new FunctionError("can't convert \"" + arg + "\" to a number.", i); numbers.add(d); } } final double[] doubles = new double[numbers.size()]; int index = 0; for (final Double d : numbers) doubles[index++] = d; return doubles; } private  FunctionUtil(); static double getArgAsDouble(final Object arg); static String getArgAsString(final Object arg); static long getArgAsLong(final Object arg); static boolean getArgAsBoolean(final Object arg); static double numericallySafeSum(final double a[]); static String getOrdinal(final int i); static double calcSampleVariance(final double[] x); static double[] listToArray(final List<Double> a); static boolean isScalarArgType(final Class type); static boolean isTypeOfList(final Class listClassCandidate); static void addScalarArgumentTypes(final List<Class> argTypes); static double[] getDoubles(final Object[] args); static long[] getLongs(final Object[] args); static String[] getStrings(final Object[] args); static boolean[] getBooleans(final Object[] args); static Object translateObjectType(final Object input);  }