List of usage examples for java.util.function DoubleConsumer accept
void accept(double value);
From source file:Main.java
public static void main(String[] args) { DoubleConsumer d = (x) -> System.out.println(x * x); d.accept(0.23); }
From source file:at.gridtec.lambda4j.consumer.tri.obj.BiObjDoubleConsumer.java
/** * Creates a {@link BiObjDoubleConsumer} which uses the {@code third} parameter of this one as argument for the * given {@link DoubleConsumer}./* w w w . j a v a2s .co m*/ * * @param <T> The type of the first argument to the consumer * @param <U> The type of the second argument to the consumer * @param consumer The consumer which accepts the {@code third} parameter of this one * @return Creates a {@code BiObjDoubleConsumer} which uses the {@code third} parameter of this one as argument for * the given {@code DoubleConsumer}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiObjDoubleConsumer<T, U> onlyThird(@Nonnull final DoubleConsumer consumer) { Objects.requireNonNull(consumer); return (t, u, value) -> consumer.accept(value); }
From source file:io.servicecomb.config.DynamicPropertiesImpl.java
@Override public float getFloatProperty(String propertyName, DoubleConsumer consumer, float defaultValue) { DynamicFloatProperty prop = propertyFactoryInstance().getFloatProperty(propertyName, defaultValue); prop.addCallback(() -> consumer.accept(prop.get())); return prop.get(); }
From source file:io.servicecomb.config.DynamicPropertiesImpl.java
@Override public double getDoubleProperty(String propertyName, DoubleConsumer consumer, double defaultValue) { DynamicDoubleProperty prop = propertyFactoryInstance().getDoubleProperty(propertyName, defaultValue); prop.addCallback(() -> consumer.accept(prop.get())); return prop.get(); }
From source file:de.bund.bfr.math.MultivariateOptimization.java
@Override public Result optimize(int nParameterSpace, int nOptimizations, boolean stopWhenSuccessful, Map<String, Double> minStartValues, Map<String, Double> maxStartValues, int maxIterations, DoubleConsumer progessListener, ExecutionContext exec) throws CanceledExecutionException { if (exec != null) { exec.checkCanceled();/*from ww w .jav a 2s .com*/ } progessListener.accept(0.0); List<ParamRange> ranges = MathUtils.getParamRanges(parameters, minStartValues, maxStartValues, nParameterSpace); ranges.set(parameters.indexOf(sdParam), new ParamRange(1.0, 1, 1.0)); List<StartValues> startValuesList = MathUtils.createStartValuesList(ranges, nOptimizations, values -> optimizerFunction.value(Doubles.toArray(values)), progress -> progessListener.accept(0.5 * progress), exec); Result result = new Result(); AtomicInteger currentIteration = new AtomicInteger(); SimplexOptimizer optimizer = new SimplexOptimizer(new SimpleValueChecker(1e-10, 1e-10) { @Override public boolean converged(int iteration, PointValuePair previous, PointValuePair current) { if (super.converged(iteration, previous, current)) { return true; } return currentIteration.incrementAndGet() >= maxIterations; } }); int count = 0; for (StartValues startValues : startValuesList) { if (exec != null) { exec.checkCanceled(); } progessListener.accept(0.5 * count++ / startValuesList.size() + 0.5); try { PointValuePair optimizerResults = optimizer.optimize(new MaxEval(Integer.MAX_VALUE), new MaxIter(maxIterations), new InitialGuess(Doubles.toArray(startValues.getValues())), new ObjectiveFunction(optimizerFunction), GoalType.MAXIMIZE, new NelderMeadSimplex(parameters.size())); double logLikelihood = optimizerResults.getValue() != null ? optimizerResults.getValue() : Double.NaN; if (result.logLikelihood == null || logLikelihood > result.logLikelihood) { result = getResults(optimizerResults); if (result.logLikelihood == 0.0 || stopWhenSuccessful) { break; } } } catch (TooManyEvaluationsException | TooManyIterationsException | ConvergenceException e) { } } return result; }
From source file:at.gridtec.lambda4j.function.bi.to.ToDoubleBiFunction2.java
/** * Returns a composed {@link BiConsumer2} that fist applies this function to its input, and then consumes the result * using the given {@link DoubleConsumer}. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param consumer The operation which consumes the result from this operation * @return A composed {@code BiConsumer2} that first applies this function to its input, and then consumes the * result using the given {@code DoubleConsumer}. * @throws NullPointerException If given argument is {@code null} */// w w w . ja va 2s .c o m @Nonnull default BiConsumer2<T, U> consume(@Nonnull final DoubleConsumer consumer) { Objects.requireNonNull(consumer); return (t, u) -> consumer.accept(applyAsDouble(t, u)); }
From source file:de.bund.bfr.math.LeastSquaresOptimization.java
@Override public Result optimize(int nParameterSpace, int nOptimizations, boolean stopWhenSuccessful, Map<String, Double> minStartValues, Map<String, Double> maxStartValues, int maxIterations, DoubleConsumer progressListener, ExecutionContext exec) throws CanceledExecutionException { if (exec != null) { exec.checkCanceled();/*www .ja v a2s . c om*/ } progressListener.accept(0.0); List<ParamRange> ranges = MathUtils.getParamRanges(parameters, minStartValues, maxStartValues, nParameterSpace); RealVector targetVector = new ArrayRealVector(Doubles.toArray(targetValues)); List<StartValues> startValuesList = MathUtils.createStartValuesList(ranges, nOptimizations, values -> targetVector .getDistance(new ArrayRealVector(optimizerFunction.value(Doubles.toArray(values)))), progress -> progressListener.accept(0.5 * progress), exec); LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(); Result result = new Result(); AtomicInteger count = new AtomicInteger(0); for (StartValues startValues : startValuesList) { if (exec != null) { exec.checkCanceled(); } progressListener.accept(0.5 * count.get() / startValuesList.size() + 0.5); try { LeastSquaresBuilder builder = createLeastSquaresBuilder(startValues.getValues(), maxIterations); builder.checker((iteration, previous, current) -> { double currentProgress = (double) iteration / (double) maxIterations; if (exec != null) { try { exec.checkCanceled(); } catch (CanceledExecutionException e) { return true; } } progressListener.accept(0.5 * (count.get() + currentProgress) / startValuesList.size() + 0.5); return iteration == maxIterations; }); LeastSquaresOptimizer.Optimum optimizerResults = optimizer.optimize(builder.build()); if (exec != null) { exec.checkCanceled(); } double cost = optimizerResults.getCost(); if (result.sse == null || cost * cost < result.sse) { result = getResults(optimizerResults); if (result.sse == 0.0) { break; } if (result.r2 != null && result.r2 > 0.0 && stopWhenSuccessful) { break; } } } catch (TooManyEvaluationsException | TooManyIterationsException | ConvergenceException e) { } count.incrementAndGet(); } return result; }
From source file:at.gridtec.lambda4j.function.tri.to.ToDoubleTriFunction.java
/** * Returns a composed {@link TriConsumer} that fist applies this function to its input, and then consumes the result * using the given {@link DoubleConsumer}. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param consumer The operation which consumes the result from this operation * @return A composed {@code TriConsumer} that first applies this function to its input, and then consumes the * result using the given {@code DoubleConsumer}. * @throws NullPointerException If given argument is {@code null} *///from www .j a v a 2s .c o m @Nonnull default TriConsumer<T, U, V> consume(@Nonnull final DoubleConsumer consumer) { Objects.requireNonNull(consumer); return (t, u, v) -> consumer.accept(applyAsDouble(t, u, v)); }
From source file:at.gridtec.lambda4j.function.bi.conversion.BiBooleanToDoubleFunction.java
/** * Returns a composed {@link BiBooleanConsumer} that fist applies this function to its input, and then consumes the * result using the given {@link DoubleConsumer}. If evaluation of either operation throws an exception, it is * relayed to the caller of the composed operation. * * @param consumer The operation which consumes the result from this operation * @return A composed {@code BiBooleanConsumer} that first applies this function to its input, and then consumes the * result using the given {@code DoubleConsumer}. * @throws NullPointerException If given argument is {@code null} *//*from ww w . java 2 s . c o m*/ @Nonnull default BiBooleanConsumer consume(@Nonnull final DoubleConsumer consumer) { Objects.requireNonNull(consumer); return (value1, value2) -> consumer.accept(applyAsDouble(value1, value2)); }
From source file:at.gridtec.lambda4j.function.bi.conversion.BiByteToDoubleFunction.java
/** * Returns a composed {@link BiByteConsumer} that fist applies this function to its input, and then consumes the * result using the given {@link DoubleConsumer}. If evaluation of either operation throws an exception, it is * relayed to the caller of the composed operation. * * @param consumer The operation which consumes the result from this operation * @return A composed {@code BiByteConsumer} that first applies this function to its input, and then consumes the * result using the given {@code DoubleConsumer}. * @throws NullPointerException If given argument is {@code null} *//* w ww. ja v a 2 s .c om*/ @Nonnull default BiByteConsumer consume(@Nonnull final DoubleConsumer consumer) { Objects.requireNonNull(consumer); return (value1, value2) -> consumer.accept(applyAsDouble(value1, value2)); }