@SuppressWarnings({"unchecked", "rawtypes"}) @Override public Stream<?> doApply(List<Stream<?>> streamsList) { AtomicInteger ctr = new AtomicInteger(2); Stream<?> unionizedStream = streamsList .stream() .reduce( (lStream, rStream) -> { Stream<?> newStream = Stream.concat(lStream, rStream); int currentStreamIdx = ctr.getAndIncrement(); for (int j = 0; j < checkPointProcedures.size(); j++) { Tuple2<Integer, Object> postProc = checkPointProcedures.get(j); if ((Integer) postProc._1() == currentStreamIdx) { SerFunction f = (SerFunction) postProc._2(); if (f != null) { newStream = (Stream) f.apply(newStream); } } } return newStream; }) .get(); if (this.distinct) { unionizedStream = unionizedStream.distinct(); } return unionizedStream; }
private Stream<PostponingReasons> getPostponingReasonsStream( String sql, boolean doDistinctAfterFirstStream) { final AccumulationContext context = new AccumulationContext(); final LazyResultSetIterator<Pair> iterator = LazyResultSetIterator.<Pair>of( Common.getRsSupplier(jdbcConnector, sql, "streamAllPostponingReasons"), Common.getMappingSqlFunction( rs -> new Pair( sqlDialect.translateFromDb(rs.getObject(1), UtcDay.class), CurrencyUnit.ofNumericCode(rs.getInt(2))), sql, "streamAllPostponingReasons"), sql); Stream<Pair> stream = iterator.stream(); if (doDistinctAfterFirstStream) { stream = stream.distinct(); } return stream .filter( pair -> { if (context.builder == null) { context.builder = ImmutableSet.builder(); context.currentDay = pair.day; context.builder.add(pair.unit); return false; } if (!pair.day.equals(context.currentDay)) { return true; } else { context.builder.add(pair.unit); return false; } }) .map( pair -> { final PostponingReasons postponingReasons = new PostponingReasons(context.currentDay, context.builder.build()); if (iterator.hasNext()) { context.builder = ImmutableSet.builder(); context.currentDay = pair.day; context.builder.add(pair.unit); } return postponingReasons; }); }
public static String appClassName() { try (Stream<String> apps = apps()) { List<String> results = apps.distinct().collect(toList()); if (results.size() > 1) { throw new IllegalStateException( "Multiple candidates " + "implement com.cakemanny.app.App:\n" + String.join("\n", results) + "\nPlease specify one using the prog.className " + "system property"); } else if (results.isEmpty()) { throw new NoSuchElementException( "Unable to find any classes " + "that implement com.cakemanny.app.App on the classpath"); } else { return results.get(0); } } }