类java.util.function.DoubleConsumer源码实例Demo

下面列出了怎么用java.util.function.DoubleConsumer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-8   文件: SpinedBufferTest.java
@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);
}
 
源代码2 项目: openjdk-jdk9   文件: DoubleStream.java
/**
 * 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);
}
 
源代码3 项目: jdk8u-jdk   文件: PrimitiveIteratorDefaults.java
public void testDoubleForEachRemainingWithNull() {
    PrimitiveIterator.OfDouble i = new PrimitiveIterator.OfDouble() {
        @Override
        public double nextDouble() {
            return 0;
        }

        @Override
        public boolean hasNext() {
            return false;
        }
    };

    executeAndCatch(() -> i.forEachRemaining((DoubleConsumer) null));
    executeAndCatch(() -> i.forEachRemaining((Consumer<Double>) null));
}
 
源代码4 项目: openjdk-jdk9   文件: WhileOps.java
@Override
public boolean tryAdvance(DoubleConsumer action) {
    if (takeOrDrop) {
        takeOrDrop = false;
        boolean adv;
        boolean dropped = false;
        while ((adv = s.tryAdvance(this)) &&  // If advanced one element
               checkCancelOnCount() &&        // and if not cancelled
               p.test(t)) {                   // and test on element passes
            dropped = true;                   // then drop element
        }

        // Report advanced element, if any
        if (adv) {
            // Cancel all further dropping if one or more elements
            // were previously dropped
            if (dropped)
                cancel.set(true);
            action.accept(t);
        }
        return adv;
    }
    else {
        return s.tryAdvance(action);
    }
}
 
源代码5 项目: TencentKona-8   文件: DoublePipeline.java
@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);
                }
            };
        }
    };
}
 
源代码6 项目: openjdk-jdk8u   文件: PrimitiveIteratorDefaults.java
public void testDoubleForEachRemainingWithNull() {
    PrimitiveIterator.OfDouble i = new PrimitiveIterator.OfDouble() {
        @Override
        public double nextDouble() {
            return 0;
        }

        @Override
        public boolean hasNext() {
            return false;
        }
    };

    executeAndCatch(() -> i.forEachRemaining((DoubleConsumer) null));
    executeAndCatch(() -> i.forEachRemaining((Consumer<Double>) null));
}
 
源代码7 项目: JDKSourceCode1.8   文件: Node.java
@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++) { }
    for (int i = 0; (i < size) && spliterator.tryAdvance((DoubleConsumer) nodeBuilder); i++) { }
    nodeBuilder.end();
    return nodeBuilder.build();
}
 
源代码8 项目: openjdk-8   文件: StreamSpliterators.java
@Override
public void forEachRemaining(DoubleConsumer consumer) {
    if (buffer == null && !finished) {
        Objects.requireNonNull(consumer);
        init();

        ph.wrapAndCopyInto((Sink.OfDouble) consumer::accept, spliterator);
        finished = true;
    }
    else {
        do { } while (tryAdvance(consumer));
    }
}
 
源代码9 项目: jdk8u_jdk   文件: DoublePipeline.java
@Override
public void forEachOrdered(DoubleConsumer consumer) {
    if (!isParallel()) {
        adapt(sourceStageSpliterator()).forEachRemaining(consumer);
    }
    else {
        super.forEachOrdered(consumer);
    }
}
 
源代码10 项目: jdk8u-jdk   文件: PrimitiveIterator.java
/**
 * {@inheritDoc}
 * @implSpec
 * If the action is an instance of {@code DoubleConsumer} then it is
 * cast to {@code DoubleConsumer} and passed to
 * {@link #forEachRemaining}; otherwise the action is adapted to
 * an instance of {@code DoubleConsumer}, by boxing the argument of
 * {@code DoubleConsumer}, and then passed to
 * {@link #forEachRemaining}.
 */
@Override
default void forEachRemaining(Consumer<? super Double> action) {
    if (action instanceof DoubleConsumer) {
        forEachRemaining((DoubleConsumer) action);
    }
    else {
        // The method reference action::accept is never null
        Objects.requireNonNull(action);
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(), "{0} calling PrimitiveIterator.OfDouble.forEachRemainingDouble(action::accept)");
        forEachRemaining((DoubleConsumer) action::accept);
    }
}
 
源代码11 项目: dragonwell8_jdk   文件: Spliterators.java
@Override
public void forEachRemaining(DoubleConsumer action) {
    double[] a; int i, hi; // hoist accesses and checks from loop
    if (action == null)
        throw new NullPointerException();
    if ((a = array).length >= (hi = fence) &&
        (i = index) >= 0 && i < (index = hi)) {
        do { action.accept(a[i]); } while (++i < hi);
    }
}
 
源代码12 项目: openjdk-jdk9   文件: Spliterators.java
@Override
public void forEachRemaining(DoubleConsumer action) {
    double[] a; int i, hi; // hoist accesses and checks from loop
    if (action == null)
        throw new NullPointerException();
    if ((a = array).length >= (hi = fence) &&
        (i = index) >= 0 && i < (index = hi)) {
        do { action.accept(a[i]); } while (++i < hi);
    }
}
 
源代码13 项目: jdk1.8-source-analysis   文件: DoublePipeline.java
@Override
public void forEach(DoubleConsumer consumer) {
    if (!isParallel()) {
        adapt(sourceStageSpliterator()).forEachRemaining(consumer);
    }
    else {
        super.forEach(consumer);
    }
}
 
源代码14 项目: j2objc   文件: Spliterator.java
/**
         * {@inheritDoc}
         * @implSpec
         * If the action is an instance of {@code DoubleConsumer} then it is
         * cast to {@code DoubleConsumer} and passed to
         * {@link #forEachRemaining(java.util.function.DoubleConsumer)};
         * otherwise the action is adapted to an instance of
         * {@code DoubleConsumer}, by boxing the argument of
         * {@code DoubleConsumer}, and then passed to
         * {@link #forEachRemaining(java.util.function.DoubleConsumer)}.
         */
        @Override
        default void forEachRemaining(Consumer<? super Double> action) {
            if (action instanceof DoubleConsumer) {
                forEachRemaining((DoubleConsumer) action);
            }
            else {
//                if (Tripwire.ENABLED)
//                    Tripwire.trip(getClass(),
//                                  "{0} calling Spliterator.OfDouble.forEachRemaining((DoubleConsumer) action::accept)");
                forEachRemaining((DoubleConsumer) action::accept);
            }
        }
 
源代码15 项目: jdk8u-jdk   文件: Random.java
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);
    }
}
 
源代码16 项目: dragonwell8_jdk   文件: Random.java
public boolean tryAdvance(DoubleConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextDouble(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码17 项目: jdk8u-dev-jdk   文件: StreamSpliterators.java
@Override
public void forEachRemaining(DoubleConsumer consumer) {
    if (buffer == null && !finished) {
        Objects.requireNonNull(consumer);
        init();

        ph.wrapAndCopyInto((Sink.OfDouble) consumer::accept, spliterator);
        finished = true;
    }
    else {
        do { } while (tryAdvance(consumer));
    }
}
 
源代码18 项目: openjdk-8-source   文件: Streams.java
@Override
public boolean tryAdvance(DoubleConsumer action) {
    Objects.requireNonNull(action);

    if (count == -2) {
        action.accept(first);
        count = -1;
        return true;
    }
    else {
        return false;
    }
}
 
源代码19 项目: j2objc   文件: DoubleConsumerTest.java
public void testAndThen_null() throws Exception {
  DoubleConsumer one = s -> {};
  try {
    one.andThen(null);
    fail();
  } catch (NullPointerException expected) {}
}
 
源代码20 项目: jdk8u-dev-jdk   文件: Random.java
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);
    }
}
 
源代码21 项目: openjdk-jdk8u   文件: Spliterator.java
/**
 * {@inheritDoc}
 * @implSpec
 * If the action is an instance of {@code DoubleConsumer} then it is
 * cast to {@code DoubleConsumer} and passed to
 * {@link #forEachRemaining(java.util.function.DoubleConsumer)};
 * otherwise the action is adapted to an instance of
 * {@code DoubleConsumer}, by boxing the argument of
 * {@code DoubleConsumer}, and then passed to
 * {@link #forEachRemaining(java.util.function.DoubleConsumer)}.
 */
@Override
default void forEachRemaining(Consumer<? super Double> action) {
    if (action instanceof DoubleConsumer) {
        forEachRemaining((DoubleConsumer) action);
    }
    else {
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(),
                          "{0} calling Spliterator.OfDouble.forEachRemaining((DoubleConsumer) action::accept)");
        forEachRemaining((DoubleConsumer) action::accept);
    }
}
 
源代码22 项目: Java8CN   文件: DoublePipeline.java
/**
 * Adapt a {@code Sink<Double> to a {@code DoubleConsumer}, ideally simply
 * by casting.
 */
private static DoubleConsumer adapt(Sink<Double> sink) {
    if (sink instanceof DoubleConsumer) {
        return (DoubleConsumer) sink;
    } else {
        if (Tripwire.ENABLED)
            Tripwire.trip(AbstractPipeline.class,
                          "using DoubleStream.adapt(Sink<Double> s)");
        return sink::accept;
    }
}
 
源代码23 项目: openjdk-jdk8u   文件: Streams.java
@Override
public boolean tryAdvance(DoubleConsumer action) {
    Objects.requireNonNull(action);

    if (count == -2) {
        action.accept(first);
        count = -1;
        return true;
    }
    else {
        return false;
    }
}
 
源代码24 项目: jdk8u_jdk   文件: Streams.java
@Override
public boolean tryAdvance(DoubleConsumer action) {
    Objects.requireNonNull(action);

    if (count == -2) {
        action.accept(first);
        count = -1;
        return true;
    }
    else {
        return false;
    }
}
 
源代码25 项目: TencentKona-8   文件: Node.java
@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++) { }
    for (int i = 0; (i < size) && spliterator.tryAdvance((DoubleConsumer) nodeBuilder); i++) { }
    nodeBuilder.end();
    return nodeBuilder.build();
}
 
源代码26 项目: jdk1.8-source-analysis   文件: Random.java
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);
    }
}
 
源代码27 项目: jdk8u60   文件: Node.java
@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++) { }
    for (int i = 0; (i < size) && spliterator.tryAdvance((DoubleConsumer) nodeBuilder); i++) { }
    nodeBuilder.end();
    return nodeBuilder.build();
}
 
源代码28 项目: TencentKona-8   文件: Spliterators.java
@Override
public boolean tryAdvance(DoubleConsumer action) {
    if (action == null) throw new NullPointerException();
    if (it.hasNext()) {
        action.accept(it.nextDouble());
        return true;
    }
    return false;
}
 
源代码29 项目: Bytecoder   文件: Random.java
public boolean tryAdvance(DoubleConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextDouble(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码30 项目: jdk8u-jdk   文件: Random.java
public boolean tryAdvance(DoubleConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextDouble(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
 类所在包
 类方法
 同包方法