/** * Evaluate if the specified values indicate that a flush should be * performed. * @param nTuples number of tuples written to the active file * @param tuple the tuple written to the file * @return true if a flush should be performed. */ public boolean evaluate(int nTuples, T tuple) { return (cntTuples > 0 && nTuples > 0 && nTuples % cntTuples == 0) || (tuplePredicate != null && tuplePredicate.test(tuple)); }
/** * Evaluate if the specified values indicate that a cycling of * the active file should be performed. * @param fileSize the number of bytes written to the active file * @param nTuples number of tuples written to the active file * @param tuple the tuple written to the file * @return true if a cycle action should be performed. */ public boolean evaluate(long fileSize, int nTuples, T tuple) { return (this.fileSize > 0 && fileSize > this.fileSize) || (cntTuples > 0 && nTuples > 0 && nTuples % cntTuples == 0) || (tuplePredicate != null && tuplePredicate.test(tuple)); }
@Override public void accept(T tuple) { if (filter.test(tuple)) submit(tuple); }
@Override public void accept(T tuple) { if (filter.test(tuple)) submit(tuple); }
@Override public boolean test(final T t) { final V value = valueFunction.apply(t); boolean passTuple; long now = 0; if (!inBand.test(value)) { outOfBand = true; passTuple = true; } else if (outOfBand) { // When the value returns to being in-band // send the in-band value. outOfBand = false; passTuple = true; } else { passTuple = false; if (period != 0) { now = System.currentTimeMillis(); long sinceLast = unit.convert(now - lastSend, TimeUnit.MILLISECONDS); if (sinceLast > period) passTuple = true; } } if (passTuple && period != 0) lastSend = now == 0 ? System.currentTimeMillis() : now; return passTuple; }
private <T> List<List<T>> buildExpResults(T[] tuples, Predicate<T> cycleIt) { List<List<T>> expResults = new ArrayList<>(); List<T> oneFile = null; for (T tuple : tuples) { if (oneFile==null) { oneFile = new ArrayList<>(); expResults.add(oneFile); } oneFile.add(tuple); if (cycleIt.test(tuple)) oneFile = null; } return expResults; }
private List<String> expectedPersons(Predicate<Person> predicate, List<Person> persons) { List<String> expPersons = new ArrayList<>(); for (Person p : persons) { if (predicate.test(p)) { expPersons.add(p.toString()); } } return expPersons; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void peekAll(Supplier<? extends Peek<?>> supplier, Predicate<Vertex<?, ?, ?>> select) { // Select vertices which satisfy the specified predicate List<Vertex<?, ?, ?>> vertices = new ArrayList<>(); for (Vertex<?, ?, ?> v : getVertices()) { if (select.test(v)) { vertices.add(v); } } // Insert peek oplets on isConnected() output ports for (Vertex<?, ?, ?> v : vertices) { List<? extends Connector<?>> connectors = v.getConnectors(); for (Connector<?> c : connectors) { if (c.isConnected()) { Peek<?> oplet = supplier.get(); c.peek((Peek) oplet); } } } } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void peekAll(Supplier<? extends Peek<?>> supplier, Predicate<Vertex<?, ?, ?>> select) { // Select vertices which satisfy the specified predicate List<Vertex<?, ?, ?>> vertices = new ArrayList<>(); for (Vertex<?, ?, ?> v : getVertices()) { if (select.test(v)) { vertices.add(v); } } // Insert peek oplets on isConnected() output ports for (Vertex<?, ?, ?> v : vertices) { List<? extends Connector<?>> connectors = v.getConnectors(); for (Connector<?> c : connectors) { if (c.isConnected()) { Peek<?> oplet = supplier.get(); c.peek((Peek) oplet); } } } } }
private <T extends Comparable<?>> void testOutsideOf(Range<T> range, T v) { Predicate<T> notPredicate = Ranges.outsideOf(range); assertEquals("outsideOf-"+range+".test("+v+")", !range.test(v), notPredicate.test(v)); }