@Test public void testGetBooleans() { final List<Object> misc = new ArrayList<Object>(); misc.add(Long.valueOf(1L)); misc.add(-0.3); final Object[] args = { misc, "false", 42, "true", true, false }; final boolean[] expectedValues = { true, true, false, true, true, true, false }; try { final boolean[] actualValues = FunctionUtil.getBooleans(args); assertEquals("getBooleans() failed!", expectedValues.length, actualValues.length); for (int i = 0; i < actualValues.length; ++i) assertEquals("getBooleans() failed!", expectedValues[i], actualValues[i]); } catch (final Exception e) { fail("getBooleans() failed!"); } }
public static boolean[] getBooleans(final Object[] args) throws FunctionError { final List<Boolean> booleans = new ArrayList<Boolean>(); 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 Boolean b = convertToBoolean(listElement); if (b == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a boolean value.", i); booleans.add(b); } } else { final Boolean b = convertToBoolean(arg); if (b == null) throw new FunctionError("can't convert \"" + arg + "\" to a boolean number.", i); booleans.add(b); } } final boolean[] retval = new boolean[booleans.size()]; int index = 0; for (final Boolean b : booleans) retval[index++] = b; return retval; }
FunctionUtil { public static boolean[] getBooleans(final Object[] args) throws FunctionError { final List<Boolean> booleans = new ArrayList<Boolean>(); 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 Boolean b = convertToBoolean(listElement); if (b == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a boolean value.", i); booleans.add(b); } } else { final Boolean b = convertToBoolean(arg); if (b == null) throw new FunctionError("can't convert \"" + arg + "\" to a boolean number.", i); booleans.add(b); } } final boolean[] retval = new boolean[booleans.size()]; int index = 0; for (final Boolean b : booleans) retval[index++] = b; return retval; } }
FunctionUtil { public static boolean[] getBooleans(final Object[] args) throws FunctionError { final List<Boolean> booleans = new ArrayList<Boolean>(); 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 Boolean b = convertToBoolean(listElement); if (b == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a boolean value.", i); booleans.add(b); } } else { final Boolean b = convertToBoolean(arg); if (b == null) throw new FunctionError("can't convert \"" + arg + "\" to a boolean number.", i); booleans.add(b); } } final boolean[] retval = new boolean[booleans.size()]; int index = 0; for (final Boolean b : booleans) retval[index++] = b; return retval; } private  FunctionUtil(); }
FunctionUtil { public static boolean[] getBooleans(final Object[] args) throws FunctionError { final List<Boolean> booleans = new ArrayList<Boolean>(); 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 Boolean b = convertToBoolean(listElement); if (b == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a boolean value.", i); booleans.add(b); } } else { final Boolean b = convertToBoolean(arg); if (b == null) throw new FunctionError("can't convert \"" + arg + "\" to a boolean number.", i); booleans.add(b); } } final boolean[] retval = new boolean[booleans.size()]; int index = 0; for (final Boolean b : booleans) retval[index++] = b; return retval; } 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 boolean[] getBooleans(final Object[] args) throws FunctionError { final List<Boolean> booleans = new ArrayList<Boolean>(); 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 Boolean b = convertToBoolean(listElement); if (b == null) throw new FunctionError("can't convert list element \"" + listElement + "\" to a boolean value.", i); booleans.add(b); } } else { final Boolean b = convertToBoolean(arg); if (b == null) throw new FunctionError("can't convert \"" + arg + "\" to a boolean number.", i); booleans.add(b); } } final boolean[] retval = new boolean[booleans.size()]; int index = 0; for (final Boolean b : booleans) retval[index++] = b; return retval; } 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);  }