java.util.function.IntConsumer#accept ( )源码实例Demo

下面列出了java.util.function.IntConsumer#accept ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8-source   文件: Streams.java
@Override
public void forEachRemaining(IntConsumer consumer) {
    Objects.requireNonNull(consumer);

    int i = from;
    final int hUpTo = upTo;
    int hLast = last;
    from = upTo;
    last = 0;
    while (i < hUpTo) {
        consumer.accept(i++);
    }
    if (hLast > 0) {
        // Last element of closed range
        consumer.accept(i);
    }
}
 
源代码2 项目: Bytecoder   文件: IntStream.java
/**
 * Returns an infinite sequential ordered {@code IntStream} 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 IntStream} 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 IntStream}
 */
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
    Objects.requireNonNull(f);
    Spliterator.OfInt spliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE,
           Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
        int prev;
        boolean started;

        @Override
        public boolean tryAdvance(IntConsumer action) {
            Objects.requireNonNull(action);
            int t;
            if (started)
                t = f.applyAsInt(prev);
            else {
                t = seed;
                started = true;
            }
            action.accept(prev = t);
            return true;
        }
    };
    return StreamSupport.intStream(spliterator, false);
}
 
源代码3 项目: constellation   文件: EdgeSpliterator.java
@Override
public boolean tryAdvance(final IntConsumer action) {
    if (position < limit) {
        final int vxId = rg.getEdge(position++);
        action.accept(vxId);
        return true;
    }

    return false;
}
 
源代码4 项目: j2objc   文件: CharBufferSpliterator.java
@Override
public void forEachRemaining(IntConsumer action) {
    if (action == null)
        throw new NullPointerException();
    CharBuffer cb = buffer;
    int i = index;
    int hi = limit;
    index = hi;
    while (i < hi) {
        action.accept(cb.getUnchecked(i++));
    }
}
 
源代码5 项目: Bytecoder   文件: SplittableRandom.java
public boolean tryAdvance(IntConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextInt(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码6 项目: TencentKona-8   文件: SplittableRandom.java
public void forEachRemaining(IntConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        index = f;
        SplittableRandom r = rng;
        int o = origin, b = bound;
        do {
            consumer.accept(r.internalNextInt(o, b));
        } while (++i < f);
    }
}
 
源代码7 项目: Java8CN   文件: CharSequence.java
/**
 * Returns a stream of {@code int} zero-extending the {@code char} values
 * from this sequence.  Any char which maps to a <a
 * href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
 * point</a> is passed through uninterpreted.
 *
 * <p>If the sequence is mutated while the stream is being read, the
 * result is undefined.
 *
 * @return an IntStream of char values from this sequence
 * @since 1.8
 */
public default IntStream chars() {
    class CharIterator implements PrimitiveIterator.OfInt {
        int cur = 0;

        public boolean hasNext() {
            return cur < length();
        }

        public int nextInt() {
            if (hasNext()) {
                return charAt(cur++);
            } else {
                throw new NoSuchElementException();
            }
        }

        @Override
        public void forEachRemaining(IntConsumer block) {
            for (; cur < length(); cur++) {
                block.accept(charAt(cur));
            }
        }
    }

    return StreamSupport.intStream(() ->
            Spliterators.spliterator(
                    new CharIterator(),
                    length(),
                    Spliterator.ORDERED),
            Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED,
            false);
}
 
源代码8 项目: Java8CN   文件: SpinedBuffer.java
@Override
protected void arrayForEach(int[] array,
                            int from, int to,
                            IntConsumer consumer) {
    for (int i = from; i < to; i++)
        consumer.accept(array[i]);
}
 
源代码9 项目: jdk8u_jdk   文件: CharBufferSpliterator.java
@Override
public boolean tryAdvance(IntConsumer action) {
    if (action == null)
        throw new NullPointerException();
    if (index >= 0 && index < limit) {
        action.accept(buffer.getUnchecked(index++));
        return true;
    }
    return false;
}
 
源代码10 项目: j2objc   文件: Streams.java
@Override
public void forEachRemaining(IntConsumer action) {
    Objects.requireNonNull(action);

    if (count == -2) {
        action.accept(first);
        count = -1;
    }
}
 
源代码11 项目: hottub   文件: Random.java
public boolean tryAdvance(IntConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextInt(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码12 项目: jdk8u60   文件: StreamSpliterators.java
@Override
public boolean tryAdvance(IntConsumer consumer) {
    Objects.requireNonNull(consumer);
    boolean hasNext = doAdvance();
    if (hasNext)
        consumer.accept(buffer.get(nextToConsume));
    return hasNext;
}
 
源代码13 项目: dragonwell8_jdk   文件: StreamSpliterators.java
@Override
public boolean tryAdvance(IntConsumer consumer) {
    Objects.requireNonNull(consumer);
    boolean hasNext = doAdvance();
    if (hasNext)
        consumer.accept(buffer.get(nextToConsume));
    return hasNext;
}
 
源代码14 项目: jdk8u-jdk   文件: Streams.java
@Override
public boolean tryAdvance(IntConsumer action) {
    Objects.requireNonNull(action);

    if (count == -2) {
        action.accept(first);
        count = -1;
        return true;
    }
    else {
        return false;
    }
}
 
源代码15 项目: hottub   文件: CharSequence.java
/**
 * Returns a stream of {@code int} zero-extending the {@code char} values
 * from this sequence.  Any char which maps to a <a
 * href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
 * point</a> is passed through uninterpreted.
 *
 * <p>If the sequence is mutated while the stream is being read, the
 * result is undefined.
 *
 * @return an IntStream of char values from this sequence
 * @since 1.8
 */
public default IntStream chars() {
    class CharIterator implements PrimitiveIterator.OfInt {
        int cur = 0;

        public boolean hasNext() {
            return cur < length();
        }

        public int nextInt() {
            if (hasNext()) {
                return charAt(cur++);
            } else {
                throw new NoSuchElementException();
            }
        }

        @Override
        public void forEachRemaining(IntConsumer block) {
            for (; cur < length(); cur++) {
                block.accept(charAt(cur));
            }
        }
    }

    return StreamSupport.intStream(() ->
            Spliterators.spliterator(
                    new CharIterator(),
                    length(),
                    Spliterator.ORDERED),
            Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED,
            false);
}
 
源代码16 项目: jdk8u60   文件: Nodes.java
@Override
public void forEach(IntConsumer consumer) {
    for (int i = 0; i < curSize; i++) {
        consumer.accept(array[i]);
    }
}
 
源代码17 项目: jdk8u-jdk   文件: StreamSpliterators.java
@Override
public void forEach(IntConsumer action, long fence) {
    for (int i = 0; i < fence; i++) {
        action.accept(array[i]);
    }
}
 
源代码18 项目: openjdk-jdk8u-backup   文件: StreamSpliterators.java
@Override
protected void acceptConsumed(IntConsumer action) {
    action.accept(tmpValue);
}
 
源代码19 项目: openjdk-jdk8u   文件: PrimitiveIterator.java
/**
 * Performs the given action for each remaining element until all elements
 * have been processed or the action throws an exception.  Actions are
 * performed in the order of iteration, if that order is specified.
 * Exceptions thrown by the action are relayed to the caller.
 *
 * @implSpec
 * <p>The default implementation behaves as if:
 * <pre>{@code
 *     while (hasNext())
 *         action.accept(nextInt());
 * }</pre>
 *
 * @param action The action to be performed for each element
 * @throws NullPointerException if the specified action is null
 */
default void forEachRemaining(IntConsumer action) {
    Objects.requireNonNull(action);
    while (hasNext())
        action.accept(nextInt());
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: PrimitiveIterator.java
/**
 * Performs the given action for each remaining element until all elements
 * have been processed or the action throws an exception.  Actions are
 * performed in the order of iteration, if that order is specified.
 * Exceptions thrown by the action are relayed to the caller.
 *
 * @implSpec
 * <p>The default implementation behaves as if:
 * <pre>{@code
 *     while (hasNext())
 *         action.accept(nextInt());
 * }</pre>
 *
 * @param action The action to be performed for each element
 * @throws NullPointerException if the specified action is null
 */
default void forEachRemaining(IntConsumer action) {
    Objects.requireNonNull(action);
    while (hasNext())
        action.accept(nextInt());
}
 
 同类方法