Refine search
/** * Return the last modified time for all log files in a worker's log dir. * Using stream rather than File.listFiles is to avoid large mem usage * when a directory has too many files. */ private long lastModifiedTimeWorkerLogdir(File logDir) { long dirModified = logDir.lastModified(); DirectoryStream<Path> dirStream; try { dirStream = directoryCleaner.getStreamForDirectory(logDir); } catch (IOException e) { return dirModified; } if (dirStream == null) { return dirModified; } try { return StreamSupport.stream(dirStream.spliterator(), false) .reduce(dirModified, (maximum, path) -> { long curr = path.toFile().lastModified(); return curr > maximum ? curr : maximum; }, BinaryOperator.maxBy(Long::compareTo)); } catch (Exception ex) { LOG.error(ex.getMessage(), ex); return dirModified; } finally { IOUtils.closeQuietly(dirStream); } }
public static <A> Collector<CompletableFuture<A>, ?, CompletableFuture<Optional<A>>> reducing(BinaryOperator<A> reducer) { return toFuture( Optional::empty, (left, maybeRight) -> maybeRight.isPresent() ? maybeRight.map(right -> reducer.apply(right, left)) : Optional.of(left), (maybeLeft, maybeRight) -> maybeLeft.isPresent() ? maybeLeft.flatMap(left -> maybeRight.map(right -> reducer.apply(left, right))) : maybeRight); }
private TileEntity getClosest(Set<TileSignature> tiles, BlockPos pos, boolean remoteCheck, int limit) { return tiles.stream() .filter(ts -> ts.isRemote() == remoteCheck) .map(TileSignature::getTile) .filter(t -> !t.isInvalid()) .filter(t -> t.getPos().distanceSq(pos) <= limit * limit) .reduce(BinaryOperator.minBy(Comparator.comparing(t -> t.getPos().distanceSq(pos), Double::compare))) .orElse(null); }
@Override public Optional<T> reduce(BinaryOperator<T> accumulator) { Future<T> future = Future.future(); Object[] current = {null}; forEach(e -> current[0] = current[0] != null ? accumulator.apply((T) current[0], e) : e, this.defaultErrorHandler, () -> future.complete((T) current[0])); return Optional.ofNullable(future.get().fold(s->s, e->{throw ExceptionSoftener.throwSoftenedException(e);})); }
void merge(V value, BinaryOperator<V> mergeFunction) { checkNotNull(value, "value"); this.value = checkNotNull(mergeFunction.apply(this.value, value), "mergeFunction.apply"); } }
@Property public void defaultMethods( BinaryOperator<Integer> first, Function<? super Integer, ? extends Date> second, int firstArg, int secondArg) { Integer intermediate = first.apply(firstArg, secondArg); Date ultimate = second.apply(intermediate); assertEquals(ultimate, first.andThen(second).apply(firstArg, secondArg)); } }
default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){ return foldLeft(BinaryOperator.minBy(new Comparator<T>() { @Override public int compare(T o1, T o2) { return comparator.compare(function.apply(o1),function.apply(o2)); } })); } default Option<T> mode(){
public static <A> Collector<CompletableFuture<A>, ?, CompletableFuture<Optional<A>>> reducing(BinaryOperator<A> reducer) { return toFuture( Optional::empty, (left, maybeRight) -> maybeRight.isPresent() ? maybeRight.map(right -> reducer.apply(right, left)) : Optional.of(left), (maybeLeft, maybeRight) -> maybeLeft.isPresent() ? maybeLeft.flatMap(left -> maybeRight.map(right -> reducer.apply(left, right))) : maybeRight); }
@Override public Optional<T> reduce(BinaryOperator<T> accumulator) { Future<T> future = Future.future(); Object[] current = {null}; forEach(e -> current[0] = current[0] != null ? accumulator.apply((T) current[0], e) : e, this.defaultErrorHandler, () -> future.complete((T) current[0])); return Optional.ofNullable(future.get().fold(s->s, e->{throw ExceptionSoftener.throwSoftenedException(e);})); }
@Override public boolean test(T t) { if (!initialized) { result = t; initialized = true; } else { result = accumulator.apply(result, t); } return true; } }
default <U extends Comparable<? super U>> Option<T> minBy(Function<? super T, ? extends U> function, Comparator<? super U> comparator){ return foldLeft(BinaryOperator.minBy(new Comparator<T>() { @Override public int compare(T o1, T o2) { return comparator.compare(function.apply(o1),function.apply(o2)); } })); } default Option<T> mode(){