MathIterators { public static Comparator<Double> weakDoubleComparator(double epsilon) { return weakComparator((x, y) -> { if (abs(x - y) < epsilon) { return 0; } else { return x < y ? -1 : 1; } }); } private  MathIterators(); static Comparator<Double> weakDoubleComparator(double epsilon); static UnaryOperator<Double> increment(Double delta); static UnaryOperator<Double> times(Double factor); static InfiniteIterator<Double> random(); static InfiniteIterator<Double> arithmeticSeries(double start, double delta); static InfiniteIterator<Double> geometricSeries(double start, double factor); static ImmutableIterator<Double> exp(); static ImmutableIterator<Double> sin(); static ImmutableIterator<Double> cos(); static ImmutableIterator<Double> add(Iterator<Double> s, double inc); @SuppressWarnings("unchecked") static Iterator<Double> inc(Iterator<Double> s, double inc); static ImmutableIterator<Double> add(Iterator<Double> s, Iterator<Double> t); static ImmutableIterator<Double> multiply(Iterator<Double> s, double factor); static ImmutableIterator<Double> multiply(Iterator<Double> s, Iterator<Double> t); static ImmutableIterator<Double> square(Iterator<Double> t); static InfiniteIterator<Double> inverse(Iterator<Double> t); static ImmutableIterator<Double> divide(Iterator<Double> s, Iterator<Double> t); static UnaryOperator<Double> polynom(Iterator<Double> t, int dim); static UnaryOperator<Double> polynom(Iterator<Double> t); static Iterator<Double> compose(Iterator<Double> t, Iterator<Double> s, int dim); static Iterator<Double> compose(Iterator<Double> t, Iterator<Double> s);  }
@Test public void testWeakDoubleComparator() { Double epsilon = 1e-8; Comparator<Double> cmp = weakDoubleComparator(epsilon); Double a = 3.0; Double b = 3.0 + epsilon * 10; Double c = 3.0 + epsilon; assertTrue(cmp.compare(null, null) == 0); assertTrue(cmp.compare(null, a) == -1); assertTrue(cmp.compare(a, null) == 1); assertSame(cmp.compare(a, b), -1); assertSame(cmp.compare(a, c), 0); }