@Test public void testDivide() { assertEquals(BigDecimal.valueOf(2), NumberFieldActions.divide(new Divide(), Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(4), BigDecimal.valueOf(2) }))); assertEquals(2.0, NumberFieldActions.divide(new Divide(), Arrays.asList(4.0, 2.0))); assertEquals(2.0, NumberFieldActions.divide(new Divide(), Arrays.asList(4, 2))); assertEquals(0, NumberFieldActions.divide(new Divide(), null)); assertEquals(2.0, NumberFieldActions.divide(new Divide(), Arrays.asList(null, 4, null, 2, null))); }
@AtlasActionProcessor public static Number divide(Divide divide, List<Number> inputs) { if (inputs == null) { return 0; } Number quotient = null; for (Object entry : inputs) { if (entry instanceof Number) { if (quotient == null) { quotient = (Number) entry; } else if (quotient instanceof BigDecimal) { quotient = ((BigDecimal) quotient).divide(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { quotient = BigDecimal.valueOf(quotient.doubleValue()).divide((BigDecimal) entry); } else { quotient = quotient.doubleValue() / ((Number) entry).doubleValue(); } } else { warnIgnoringValue("Divide", entry); } } return quotient; }
NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number divide(Divide divide, List<Number> inputs) { if (inputs == null) { return 0; } Number quotient = null; for (Object entry : inputs) { if (entry instanceof Number) { if (quotient == null) { quotient = (Number) entry; } else if (quotient instanceof BigDecimal) { quotient = ((BigDecimal) quotient).divide(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { quotient = BigDecimal.valueOf(quotient.doubleValue()).divide((BigDecimal) entry); } else { quotient = quotient.doubleValue() / ((Number) entry).doubleValue(); } } else { warnIgnoringValue("Divide", entry); } } return quotient; } }
NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number divide(Divide divide, List<Number> inputs) { if (inputs == null) { return 0; } Number quotient = null; for (Object entry : inputs) { if (entry instanceof Number) { if (quotient == null) { quotient = (Number) entry; } else if (quotient instanceof BigDecimal) { quotient = ((BigDecimal) quotient).divide(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { quotient = BigDecimal.valueOf(quotient.doubleValue()).divide((BigDecimal) entry); } else { quotient = quotient.doubleValue() / ((Number) entry).doubleValue(); } } else { warnIgnoringValue("Divide", entry); } } return quotient; }  }
NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number divide(Divide divide, List<Number> inputs) { if (inputs == null) { return 0; } Number quotient = null; for (Object entry : inputs) { if (entry instanceof Number) { if (quotient == null) { quotient = (Number) entry; } else if (quotient instanceof BigDecimal) { quotient = ((BigDecimal) quotient).divide(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { quotient = BigDecimal.valueOf(quotient.doubleValue()).divide((BigDecimal) entry); } else { quotient = quotient.doubleValue() / ((Number) entry).doubleValue(); } } else { warnIgnoringValue("Divide", entry); } } return quotient; }  @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs); }
NumberFieldActions implements AtlasFieldAction { @AtlasActionProcessor public static Number divide(Divide divide, List<Number> inputs) { if (inputs == null) { return 0; } Number quotient = null; for (Object entry : inputs) { if (entry instanceof Number) { if (quotient == null) { quotient = (Number) entry; } else if (quotient instanceof BigDecimal) { quotient = ((BigDecimal) quotient).divide(BigDecimal.valueOf(((Number) entry).doubleValue())); } else if (entry instanceof BigDecimal) { quotient = BigDecimal.valueOf(quotient.doubleValue()).divide((BigDecimal) entry); } else { quotient = quotient.doubleValue() / ((Number) entry).doubleValue(); } } else { warnIgnoringValue("Divide", entry); } } return quotient; }  @AtlasActionProcessor static Number absoluteValue(AbsoluteValue action, Number input); @AtlasActionProcessor static Number add(Add action, List<Number> inputs); @AtlasActionProcessor static Number average(Average action, List<Number> inputs); @AtlasActionProcessor static Number ceiling(Ceiling action, Number input); @AtlasActionProcessor static Number convertMassUnit(ConvertMassUnit convertMassUnit, Number input); @AtlasActionProcessor static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input); @AtlasActionProcessor static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input); @AtlasActionProcessor static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input); @AtlasActionProcessor static Number divide(Divide divide, List<Number> inputs); @AtlasActionProcessor static Number floor(Floor floor, Number input); @AtlasActionProcessor static Number maximum(Maximum maximum, List<Number> inputs); @AtlasActionProcessor static Number minimum(Minimum minimum, List<Number> inputs); @AtlasActionProcessor static Number multiply(Multiply multiply, List<Number> inputs); @AtlasActionProcessor static Number round(Round action, Number input); @AtlasActionProcessor static Number subtract(Subtract subtract, List<Number> inputs);  }