本文整理汇总了Java中java.util.function.DoubleConsumer类的典型用法代码示例。如果您正苦于以下问题:Java DoubleConsumer类的具体用法?Java DoubleConsumer怎么用?Java DoubleConsumer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DoubleConsumer类属于java.util.function包,在下文中一共展示了DoubleConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forEachDouble
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Override
public final Array<T> forEachDouble(DoubleConsumer consumer) {
final int length = length();
if (isParallel() && length > 0) {
final int processors = Runtime.getRuntime().availableProcessors();
final int splitThreshold = parallel ? Math.max(length() / processors, 10000) : Integer.MAX_VALUE;
final ForEach action = new ForEach(0, length - 1, splitThreshold, consumer);
ForkJoinPool.commonPool().invoke(action);
} else {
for (int i=0; i<length; ++i) {
final double value = getDouble(i);
consumer.accept(value);
}
}
return this;
}
示例2: autoMatchAll
import java.util.function.DoubleConsumer; //导入依赖的package包/类
public void autoMatchAll(DoubleConsumer progressReceiver) {
if (autoMatchClasses(ClassifierLevel.Initial, absClassAutoMatchThreshold, relClassAutoMatchThreshold, progressReceiver)) {
autoMatchClasses(ClassifierLevel.Initial, absClassAutoMatchThreshold, relClassAutoMatchThreshold, progressReceiver);
}
autoMatchLevel(ClassifierLevel.Intermediate, progressReceiver);
autoMatchLevel(ClassifierLevel.Full, progressReceiver);
autoMatchLevel(ClassifierLevel.Extra, progressReceiver);
boolean matchedAny;
do {
matchedAny = autoMatchMethodArgs(ClassifierLevel.Full, absMethodArgAutoMatchThreshold, relMethodArgAutoMatchThreshold, progressReceiver);
} while (matchedAny);
env.getCache().clear();
}
示例3: peek
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Override
public final DoubleStream peek(DoubleConsumer action) {
Objects.requireNonNull(action);
return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
0) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble<Double>(sink) {
@Override
public void accept(double t) {
action.accept(t);
downstream.accept(t);
}
};
}
};
}
示例4: runInParallel
import java.util.function.DoubleConsumer; //导入依赖的package包/类
private <T, C> void runInParallel(List<T> workSet, Consumer<T> worker, DoubleConsumer progressReceiver) {
if (workSet.isEmpty()) return;
AtomicInteger itemsDone = new AtomicInteger();
int updateRate = Math.max(1, workSet.size() / 200);
workSet.parallelStream().forEach(workItem -> {
worker.accept(workItem);
int cItemsDone = itemsDone.incrementAndGet();
if ((cItemsDone % updateRate) == 0) {
progressReceiver.accept((double) cItemsDone / workSet.size());
}
});
}
示例5: iterate
import java.util.function.DoubleConsumer; //导入依赖的package包/类
/**
* Returns an infinite sequential ordered {@code DoubleStream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code DoubleStream}
* will be the provided {@code seed}. For {@code n > 0}, the element at
* position {@code n}, will be the result of applying the function {@code f}
* to the element at position {@code n - 1}.
*
* <p>The action of applying {@code f} for one element
* <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
* the action of applying {@code f} for subsequent elements. For any given
* element the action may be performed in whatever thread the library
* chooses.
*
* @param seed the initial element
* @param f a function to be applied to the previous element to produce
* a new element
* @return a new sequential {@code DoubleStream}
*/
public static DoubleStream iterate(final double seed, final DoubleUnaryOperator f) {
Objects.requireNonNull(f);
Spliterator.OfDouble spliterator = new Spliterators.AbstractDoubleSpliterator(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
double prev;
boolean started;
@Override
public boolean tryAdvance(DoubleConsumer action) {
Objects.requireNonNull(action);
double t;
if (started)
t = f.applyAsDouble(prev);
else {
t = seed;
started = true;
}
action.accept(prev = t);
return true;
}
};
return StreamSupport.doubleStream(spliterator, false);
}
示例6: testNextGaussianStatistically
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Test(timeOut = 20_000, groups = "non-deterministic") public void testNextGaussianStatistically()
throws SeedException {
final BaseRandom rng = createRng();
final int iterations = 10000;
final SynchronizedDescriptiveStatistics stats = new SynchronizedDescriptiveStatistics();
rng.gaussians(iterations).spliterator().forEachRemaining((DoubleConsumer) stats::addValue);
final double observedSD = stats.getStandardDeviation();
Reporter.log("Expected SD for Gaussians: 1, observed SD: " + observedSD);
assertGreaterOrEqual(observedSD, 0.97);
assertLessOrEqual(observedSD, 1.03);
assertGreaterOrEqual(stats.getMax(), 2.0);
assertLessOrEqual(stats.getMin(), -2.0);
assertGreaterOrEqual(stats.getMean(), -0.1);
assertLessOrEqual(stats.getMean(), 0.1);
final double median = stats.getPercentile(50);
assertGreaterOrEqual(median, -0.1);
assertLessOrEqual(median, 0.1);
}
示例7: tryAdvance
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(DoubleConsumer action) {
boolean test = true;
if (takeOrDrop && // If can take
checkCancelOnCount() && // and if not cancelled
s.tryAdvance(this) && // and if advanced one element
(test = p.test(t))) { // and test on element passes
action.accept(t); // then accept element
return true;
}
else {
// Taking is finished
takeOrDrop = false;
// Cancel all further traversal and splitting operations
// only if test of element failed (short-circuited)
if (!test)
cancel.set(true);
return false;
}
}
示例8: testLongLastSplit
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Test(dataProvider = "DoubleSpinedBuffer", groups = { "serialization-hostile" })
public void testLongLastSplit(double[] array, SpinedBuffer.OfDouble sb) {
Spliterator.OfDouble spliterator = sb.spliterator();
Spliterator.OfDouble split = spliterator.trySplit();
long splitSizes = (split == null) ? 0 : split.getExactSizeIfKnown();
long lastSplitSize = spliterator.getExactSizeIfKnown();
splitSizes += lastSplitSize;
assertEquals(splitSizes, array.length);
List<Double> contentOfLastSplit = new ArrayList<>();
spliterator.forEachRemaining((DoubleConsumer) contentOfLastSplit::add);
assertEquals(contentOfLastSplit.size(), lastSplitSize);
List<Double> end = Arrays.stream(array)
.boxed()
.skip(array.length - lastSplitSize)
.collect(Collectors.toList());
assertEquals(contentOfLastSplit, end);
}
示例9: testDoubleIteration
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Test(dataProvider = "Node.Builder<Double>")
public void testDoubleIteration(List<Double> l, Function<Integer, Node.Builder.OfDouble> m) {
Node.Builder.OfDouble nb = m.apply(l.size());
nb.begin(l.size());
for (Double i : l) {
nb.accept((double) i);
}
nb.end();
Node.OfDouble n = nb.build();
assertEquals(n.count(), l.size());
{
List<Double> _l = new ArrayList<>();
n.forEach((DoubleConsumer) _l::add);
assertContents(_l, l);
}
}
示例10: truncate
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Override
default Node.OfDouble truncate(long from, long to, IntFunction<Double[]> generator) {
if (from == 0 && to == count())
return this;
long size = to - from;
Spliterator.OfDouble spliterator = spliterator();
Node.Builder.OfDouble nodeBuilder = Nodes.doubleBuilder(size);
nodeBuilder.begin(size);
for (int i = 0; i < from && spliterator.tryAdvance((DoubleConsumer) e -> { }); i++) { }
if (to == count()) {
spliterator.forEachRemaining((DoubleConsumer) nodeBuilder);
} else {
for (int i = 0; i < size && spliterator.tryAdvance((DoubleConsumer) nodeBuilder); i++) { }
}
nodeBuilder.end();
return nodeBuilder.build();
}
示例11: testDoubleForEachRemainingWithNull
import java.util.function.DoubleConsumer; //导入依赖的package包/类
public void testDoubleForEachRemainingWithNull() {
PrimitiveIterator.OfDouble i = new PrimitiveIterator.OfDouble() {
@Override
public double nextDouble() {
return 0;
}
@Override
public boolean hasNext() {
return false;
}
};
assertThrowsNPE(() -> i.forEachRemaining((DoubleConsumer) null));
assertThrowsNPE(() -> i.forEachRemaining((Consumer<Double>) null));
}
示例12: animateValue
import java.util.function.DoubleConsumer; //导入依赖的package包/类
private void animateValue(double from,
double to,
Duration duration,
Interpolator interpolator, DoubleConsumer consumer,
EventHandler<ActionEvent> l) {
timeline.stop();
timeline.getKeyFrames().clear();
KeyValue keyValue = new KeyValue(new WritableValue<Double>() {
@Override
public Double getValue() {
return from;
}
@Override
public void setValue(Double value) {
consumer.accept(value);
}
}, to, interpolator == null ? Interpolator.LINEAR : interpolator);
timeline.getKeyFrames().add(new KeyFrame(duration, keyValue));
timeline.setOnFinished(l);
timeline.play();
}
示例13: forEachRemaining
import java.util.function.DoubleConsumer; //导入依赖的package包/类
public void forEachRemaining(DoubleConsumer consumer) {
if (consumer == null) throw new NullPointerException();
long i = index, f = fence;
if (i < f) {
index = f;
Random r = rng;
double o = origin, b = bound;
do {
consumer.accept(r.internalNextDouble(o, b));
} while (++i < f);
}
}
示例14: forEachOrdered
import java.util.function.DoubleConsumer; //导入依赖的package包/类
@Override
public void forEachOrdered(DoubleConsumer consumer) {
if (!isParallel()) {
adapt(sourceStageSpliterator()).forEachRemaining(consumer);
}
else {
super.forEachOrdered(consumer);
}
}
示例15: tryAdvance
import java.util.function.DoubleConsumer; //导入依赖的package包/类
public boolean tryAdvance(DoubleConsumer consumer) {
if (consumer == null) throw new NullPointerException();
long i = index, f = fence;
if (i < f) {
consumer.accept(ThreadLocalRandom.current().internalNextDouble(origin, bound));
index = i + 1;
return true;
}
return false;
}