List of utility methods to do Stream Operation
Stream | findStreamAmongst(Class find Stream Amongst return instances.stream().filter(clazz::isInstance).map(clazz::cast);
|
T | firstValue(Stream first Value return stream.findAny().get();
|
Stream | flatOptionals(Stream flat Optionals return list.filter(Optional::isPresent).map(opt -> opt.get());
|
Map | flattenFeatureStreamToMap( Stream extends Map.Entry Convert a flatten nested stream(feature family, stream(feature name. Map<String, Map<String, Double>> outputFeatureMap = new HashMap<>(); stream.forEach(inputFamilyEntry -> { String familyName = inputFamilyEntry.getKey(); Map<String, Double> outputFeatureFamily = outputFeatureMap.get(familyName); if (outputFeatureFamily == null) { outputFeatureFamily = new HashMap<>(); outputFeatureMap.put(familyName, outputFeatureFamily); final Map<String, Double> finalFeatures = outputFeatureFamily; inputFamilyEntry.getValue().forEach(feature -> finalFeatures.put(feature.getKey(), feature.getValue())); }); return outputFeatureMap; |
int | gcd(IntStream numbers) Calculate the greatest commom divisor of all numbers in the int stream return numbers.reduce(0, (x, y) -> gcd(x, y));
|
IntStream | getOSIllegalCharacterStream(String path) get OS Illegal Character Stream return path.chars().filter(c -> c < '\u0020' || WINDOWS_RESERVED_CHARS.indexOf(c) != -1 || reserverdCharacters.indexOf(c) != -1); |
Stream | getStream(Iterable Get a sequential Stream from an Iterable . return StreamSupport.stream(iterable.spliterator(), false);
|
Stream | getStringStreamFromArray(String... ids) Returns a stream of strings from a string array return Stream.of(ids);
|
LongStream | infiniteParallelStream() Creates an infinite parallel long stream. return iterate(1L, l -> l + 1).parallel();
|
Stream | interleave(Stream interleave List<T9> ar = a.collect(Collectors.toList()); List<T9> br = b.collect(Collectors.toList()); ArrayList<T9> r = new ArrayList<>(ar.size() + br.size()); for (int i = 0; i < Math.max(ar.size(), br.size()); i++) { if (i < ar.size()) r.add(ar.get(i)); if (i < br.size()) r.add(br.get(i)); ... |