@Test public void testGetLongs() { final List<Object> misc = new ArrayList<Object>(); misc.add(Double.valueOf(1.0)); misc.add(-0.3); final Object[] args = { misc, Boolean.valueOf(false), -33L, 42, "501" }; final long[] expectedValues = { 1L, -1L, 0L, -33L, 42L, 501L }; try { assertArrayEquals("getLongs() failed!", expectedValues, FunctionUtil.getLongs(args)); } catch (final Exception e) { fail("getLongs() failed!"); } }
public static long[] getLongs(final Object[] args) throws FunctionError { final List<Long> numbers = new ArrayList<Long>(); 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 Long l = convertToLong(listElement); if (l == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to an integer.", i); numbers.add(l); } } else { final Long l = convertToLong(arg); if (l == null) throw new FunctionError("can't convert \"" + arg + "\" to an integer.", i); numbers.add(l); } } final long[] longs = new long[numbers.size()]; int index = 0; for (final Long l : numbers) longs[index++] = l; return longs; }
FunctionUtil { public static long[] getLongs(final Object[] args) throws FunctionError { final List<Long> numbers = new ArrayList<Long>(); 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 Long l = convertToLong(listElement); if (l == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to an integer.", i); numbers.add(l); } } else { final Long l = convertToLong(arg); if (l == null) throw new FunctionError("can't convert \"" + arg + "\" to an integer.", i); numbers.add(l); } } final long[] longs = new long[numbers.size()]; int index = 0; for (final Long l : numbers) longs[index++] = l; return longs; } }
FunctionUtil { public static long[] getLongs(final Object[] args) throws FunctionError { final List<Long> numbers = new ArrayList<Long>(); 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 Long l = convertToLong(listElement); if (l == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to an integer.", i); numbers.add(l); } } else { final Long l = convertToLong(arg); if (l == null) throw new FunctionError("can't convert \"" + arg + "\" to an integer.", i); numbers.add(l); } } final long[] longs = new long[numbers.size()]; int index = 0; for (final Long l : numbers) longs[index++] = l; return longs; } private  FunctionUtil(); }
FunctionUtil { public static long[] getLongs(final Object[] args) throws FunctionError { final List<Long> numbers = new ArrayList<Long>(); 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 Long l = convertToLong(listElement); if (l == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to an integer.", i); numbers.add(l); } } else { final Long l = convertToLong(arg); if (l == null) throw new FunctionError("can't convert \"" + arg + "\" to an integer.", i); numbers.add(l); } } final long[] longs = new long[numbers.size()]; int index = 0; for (final Long l : numbers) longs[index++] = l; return longs; } 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 long[] getLongs(final Object[] args) throws FunctionError { final List<Long> numbers = new ArrayList<Long>(); 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 Long l = convertToLong(listElement); if (l == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to an integer.", i); numbers.add(l); } } else { final Long l = convertToLong(arg); if (l == null) throw new FunctionError("can't convert \"" + arg + "\" to an integer.", i); numbers.add(l); } } final long[] longs = new long[numbers.size()]; int index = 0; for (final Long l : numbers) longs[index++] = l; return longs; } 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);  }