private static void promotionTester(final NumericPromotion promoter, final Number... results) { promoter.accept(new EqualityAssertion(results)); }
@Override protected boolean test(final Literal a, final Literal b) { final Object aval = a.getValue(); final Object bval = b.getValue(); // Numbers are a special case, since they can be promoted from Integers and Decimals to Floats and Doubles. if (aval instanceof Number && bval instanceof Number) { final NumericPromotion promoter = new NumericPromotion(); final Number anum = (Number) aval; final Number bnum = (Number) bval; promoter.promote(anum, bnum); final NumericComparisonVisitor visitor = new NumericComparisonVisitor(); promoter.accept(visitor); if (visitor.getComparison() == 0) return true ^ _flip; return false ^ _flip; } if (a.getValue() != null && b.getValue() != null) return (aval.getClass().equals(bval.getClass()) && aval.equals(bval)) ^ _flip; return false; } }
private void testAndSetResult(final Number theResult) { if (_result == null) _result = theResult; else { final NumericComparisonVisitor visitor = new NumericComparisonVisitor(); final NumericPromotion promoter = new NumericPromotion(); promoter.promote(_result, theResult); promoter.accept(visitor); if (visitor.getComparison() == 0) _result = theResult; else _result = null; } }
@Override protected boolean test(final Literal a, final Literal b) { final Object aval = a.getValue(); final Object bval = b.getValue(); // Numbers are a special case, since they can be promoted from Integers and Decimals to Floats and Doubles. if (aval instanceof Number && bval instanceof Number) { final NumericPromotion promoter = new NumericPromotion(); final Number anum = (Number) aval; final Number bnum = (Number) bval; promoter.promote(anum, bnum); final NumericComparisonVisitor visitor = new NumericComparisonVisitor(); promoter.accept(visitor); if (visitor.getComparison() == 0) return true ^ _flip; return false ^ _flip; } if (a.getValue() != null && b.getValue() != null) return (aval.getClass().equals(bval.getClass()) && aval.equals(bval)) ^ _flip; return false; } }
private void testAndSetResult(final Number theResult) { if (_result == null) _result = theResult; else { final NumericComparisonVisitor visitor = new NumericComparisonVisitor(); final NumericPromotion promoter = new NumericPromotion(); promoter.promote(_result, theResult); promoter.accept(visitor); if (visitor.getComparison() == 0) _result = theResult; else _result = null; } }
promoter.accept(visitor);
private static void numeric(final NumericFunction f, final Number expected, final Number... args) { final NumericPromotion promoter = new NumericPromotion(); promoter.promote(args); final FunctionApplicationVisitor visitor = new FunctionApplicationVisitor(f); promoter.accept(visitor); final Number result = visitor.getResult(); if (expected == null) assertNull(result); else { assertNotNull(result); assertTrue(expected + " not equal to " + result, NumberUtils.compare(expected, result) == 0); } if (result != null && expected != null) assertEquals("Wrong numeric type from function.", expected.getClass(), result.getClass()); }
promoter.accept(visitor);