/** * Returns a new predicate that negates the result of this predicate. * * @return the predicate, "NOT this" */ public default ObjDoublePredicate<T> negate() { return (obj, value) -> !test(obj, value); }
/** * Returns a new predicate that returns true if both predicates return true. * <p> * The second predicate is only invoked if the first returns true. * * @param other the second predicate * @return the combined predicate, "this AND that" * @throws NullPointerException if the other predicate is null */ public default ObjDoublePredicate<T> and(ObjDoublePredicate<? super T> other) { Objects.requireNonNull(other); return (obj, value) -> test(obj, value) && other.test(obj, value); }
/** * Returns a new predicate that returns true if either predicates returns true. * <p> * The second predicate is only invoked if the first returns false. * * @param other the second predicate * @return the combined predicate, "this OR that" * @throws NullPointerException if the other predicate is null */ public default ObjDoublePredicate<T> or(ObjDoublePredicate<? super T> other) { Objects.requireNonNull(other); return (obj, value) -> test(obj, value) || other.test(obj, value); }
public void test_and() { ObjDoublePredicate<String> fn1 = (a, b) -> b > 3; ObjDoublePredicate<String> fn2 = (a, b) -> a.length() > 3; ObjDoublePredicate<String> and = fn1.and(fn2); assertEquals(fn1.test("a", 2.3d), false); assertEquals(fn1.test("a", 3.2d), true); assertEquals(fn2.test("a", 3.2d), false); assertEquals(fn2.test("abcd", 3.2d), true); assertEquals(and.test("a", 2.3d), false); assertEquals(and.test("a", 3.2d), false); assertEquals(and.test("abcd", 2.3d), false); assertEquals(and.test("abcd", 3.2d), true); }
public void test_or() { ObjDoublePredicate<String> fn1 = (a, b) -> b > 3; ObjDoublePredicate<String> fn2 = (a, b) -> a.length() > 3; ObjDoublePredicate<String> or = fn1.or(fn2); assertEquals(fn1.test("a", 2.3d), false); assertEquals(fn1.test("a", 3.2d), true); assertEquals(fn2.test("a", 3.2d), false); assertEquals(fn2.test("abcd", 3.2d), true); assertEquals(or.test("a", 2.3d), false); assertEquals(or.test("a", 3.2d), true); assertEquals(or.test("abcd", 2.3d), true); assertEquals(or.test("abcd", 3.2d), true); }
public void test_negate() { ObjDoublePredicate<String> fn1 = (a, b) -> b > 3; ObjDoublePredicate<String> negate = fn1.negate(); assertEquals(fn1.test("a", 2.3d), false); assertEquals(fn1.test("a", 3.2d), true); assertEquals(negate.test("a", 2.3d), true); assertEquals(negate.test("a", 3.2d), false); }
@Override public LocalDateDoubleTimeSeries filter(ObjDoublePredicate<LocalDate> predicate) { ArgChecker.notNull(predicate, "predicate"); // build up result in arrays keeping track of count of retained dates LocalDate[] resDates = new LocalDate[size()]; double[] resValues = new double[size()]; int resCount = 0; for (int i = 0; i < size(); i++) { if (predicate.test(dates[i], values[i])) { resDates[resCount] = dates[i]; resValues[resCount] = values[i]; resCount++; } } return createUnsafe(Arrays.copyOf(resDates, resCount), Arrays.copyOf(resValues, resCount)); }
@Override public LocalDateDoubleTimeSeries filter(ObjDoublePredicate<LocalDate> predicate) { Stream<LocalDateDoublePoint> filteredPoints = stream().filter(pt -> predicate.test(pt.getDate(), pt.getValue())); // As we may have changed the density of the series by filtering // go via the builder to get the best implementation return new LocalDateDoubleTimeSeriesBuilder(filteredPoints).build(); }
/** * Partition the time-series into a pair of distinct series using a predicate. * <p> * Points in the time-series which match the predicate will be put into the first series, * whilst those points which do not match will be put into the second. * * @param predicate predicate used to test the points in the time-series * @return a {@code Pair} containing two time-series. The first is a series * made of all the points in this series which match the predicate. The * second is a series made of the points which do not match. */ public default Pair<LocalDateDoubleTimeSeries, LocalDateDoubleTimeSeries> partition( ObjDoublePredicate<LocalDate> predicate) { Map<Boolean, LocalDateDoubleTimeSeries> partitioned = stream() .collect( partitioningBy( pt -> predicate.test(pt.getDate(), pt.getValue()), LocalDateDoubleTimeSeries.collector())); return Pair.of(partitioned.get(true), partitioned.get(false)); }