当前位置: 首页>>代码示例>>Java>>正文


Java StreamSupport.intStream方法代码示例

本文整理汇总了Java中java.util.stream.StreamSupport.intStream方法的典型用法代码示例。如果您正苦于以下问题:Java StreamSupport.intStream方法的具体用法?Java StreamSupport.intStream怎么用?Java StreamSupport.intStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.stream.StreamSupport的用法示例。


在下文中一共展示了StreamSupport.intStream方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: codePoints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @since 9
 */
@Override
public IntStream codePoints() {
    // Reuse String-based spliterator. This requires a supplier to
    // capture the value and count when the terminal operation is executed
    return StreamSupport.intStream(
            () -> {
                // The combined set of field reads are not atomic and thread
                // safe but bounds checks will ensure no unsafe reads from
                // the byte array
                byte[] val = this.value;
                int count = this.count;
                byte coder = this.coder;
                return coder == LATIN1
                       ? new StringLatin1.CharsSpliterator(val, 0, count, 0)
                       : new StringUTF16.CodePointsSpliterator(val, 0, count, 0);
            },
            Spliterator.ORDERED,
            false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:AbstractStringBuilder.java

示例2: chars

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * 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>The stream binds to this sequence when the terminal stream operation
 * commences (specifically, for mutable sequences the spliterator for the
 * stream is <a href="../util/Spliterator.html#binding"><em>late-binding</em></a>).
 * If the sequence is modified during that operation then 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:CharSequence.java

示例3: chars

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:CharSequence.java

示例4: stream

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns a stream of indices for which this {@code BitSet}
 * contains a bit in the set state. The indices are returned
 * in order, from lowest to highest. The size of the stream
 * is the number of bits in the set state, equal to the value
 * returned by the {@link #cardinality()} method.
 *
 * <p>The bit set must remain constant during the execution of the
 * terminal stream operation.  Otherwise, the result of the terminal
 * stream operation is undefined.
 *
 * @return a stream of integers representing set indices
 * @since 1.8
 */
public IntStream stream() {
    class BitSetIterator implements PrimitiveIterator.OfInt {
        int next = nextSetBit(0);

        @Override
        public boolean hasNext() {
            return next != -1;
        }

        @Override
        public int nextInt() {
            if (next != -1) {
                int ret = next;
                next = nextSetBit(next+1);
                return ret;
            } else {
                throw new NoSuchElementException();
            }
        }
    }

    return StreamSupport.intStream(
            () -> Spliterators.spliterator(
                    new BitSetIterator(), cardinality(),
                    Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED),
            Spliterator.SIZED | Spliterator.SUBSIZED |
                    Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED,
            false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:44,代码来源:BitSet.java

示例5: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns an effectively unlimited stream of pseudorandom {@code
 * int} values, each conforming to the given origin (inclusive) and bound
 * (exclusive).
 *
 * @implNote This method is implemented to be equivalent to {@code
 * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
 *
 * @param randomNumberOrigin the origin (inclusive) of each random value
 * @param randomNumberBound the bound (exclusive) of each random value
 * @return a stream of pseudorandom {@code int} values,
 *         each with the given origin (inclusive) and bound (exclusive)
 * @throws IllegalArgumentException if {@code randomNumberOrigin}
 *         is greater than or equal to {@code randomNumberBound}
 * @since 1.8
 */
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
    if (randomNumberOrigin >= randomNumberBound)
        throw new IllegalArgumentException(BAD_RANGE);
    return StreamSupport.intStream
        (new RandomIntsSpliterator
         (0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
         false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ThreadLocalRandom.java

示例6: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns an effectively unlimited stream of pseudorandom {@code
 * int} values, each conforming to the given origin (inclusive) and bound
 * (exclusive).
 *
 * <p>A pseudorandom {@code int} value is generated as if it's the result of
 * calling the following method with the origin and bound:
 * <pre> {@code
 * int nextInt(int origin, int bound) {
 *   int n = bound - origin;
 *   if (n > 0) {
 *     return nextInt(n) + origin;
 *   }
 *   else {  // range not representable as int
 *     int r;
 *     do {
 *       r = nextInt();
 *     } while (r < origin || r >= bound);
 *     return r;
 *   }
 * }}</pre>
 *
 * @implNote This method is implemented to be equivalent to {@code
 * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
 *
 * @param randomNumberOrigin the origin (inclusive) of each random value
 * @param randomNumberBound the bound (exclusive) of each random value
 * @return a stream of pseudorandom {@code int} values,
 *         each with the given origin (inclusive) and bound (exclusive)
 * @throws IllegalArgumentException if {@code randomNumberOrigin}
 *         is greater than or equal to {@code randomNumberBound}
 * @since 1.8
 */
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
    if (randomNumberOrigin >= randomNumberBound)
        throw new IllegalArgumentException(BadRange);
    return StreamSupport.intStream
            (new RandomIntsSpliterator
                     (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
             false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:Random.java

示例7: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns an effectively unlimited stream of pseudorandom {@code
 * int} values, each conforming to the given origin (inclusive) and bound
 * (exclusive).
 *
 * @implNote This method is implemented to be equivalent to {@code
 * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
 *
 * @param randomNumberOrigin the origin (inclusive) of each random value
 * @param randomNumberBound the bound (exclusive) of each random value
 * @return a stream of pseudorandom {@code int} values,
 *         each with the given origin (inclusive) and bound (exclusive)
 * @throws IllegalArgumentException if {@code randomNumberOrigin}
 *         is greater than or equal to {@code randomNumberBound}
 * @since 1.8
 */
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
    if (randomNumberOrigin >= randomNumberBound)
        throw new IllegalArgumentException(BadRange);
    return StreamSupport.intStream
        (new RandomIntsSpliterator
         (0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
         false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:ThreadLocalRandom.java

示例8: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns an effectively unlimited stream of pseudorandom {@code int}
 * values.
 *
 * <p>A pseudorandom {@code int} value is generated as if it's the result of
 * calling the method {@link #nextInt()}.
 *
 * @implNote This method is implemented to be equivalent to {@code
 * ints(Long.MAX_VALUE)}.
 *
 * @return a stream of pseudorandom {@code int} values
 * @since 1.8
 */
public IntStream ints() {
    return StreamSupport.intStream
            (new RandomIntsSpliterator
                     (this, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0),
             false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:Random.java

示例9: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns an effectively unlimited stream of pseudorandom {@code
 * int} values from this generator and/or one split from it; each value
 * conforms to the given origin (inclusive) and bound (exclusive).
 *
 * @implNote This method is implemented to be equivalent to {@code
 * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
 *
 * @param randomNumberOrigin the origin (inclusive) of each random value
 * @param randomNumberBound the bound (exclusive) of each random value
 * @return a stream of pseudorandom {@code int} values,
 *         each with the given origin (inclusive) and bound (exclusive)
 * @throws IllegalArgumentException if {@code randomNumberOrigin}
 *         is greater than or equal to {@code randomNumberBound}
 */
public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
    if (randomNumberOrigin >= randomNumberBound)
        throw new IllegalArgumentException(BadRange);
    return StreamSupport.intStream
        (new RandomIntsSpliterator
         (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
         false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:SplittableRandom.java

示例10: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns a stream producing the given {@code streamSize} number
 * of pseudorandom {@code int} values, each conforming to the given
 * origin (inclusive) and bound (exclusive).
 *
 * @param streamSize the number of values to generate
 * @param randomNumberOrigin the origin (inclusive) of each random value
 * @param randomNumberBound the bound (exclusive) of each random value
 * @return a stream of pseudorandom {@code int} values,
 *         each with the given origin (inclusive) and bound (exclusive)
 * @throws IllegalArgumentException if {@code streamSize} is
 *         less than zero, or {@code randomNumberOrigin}
 *         is greater than or equal to {@code randomNumberBound}
 * @since 1.8
 */
public IntStream ints(long streamSize, int randomNumberOrigin,
                      int randomNumberBound) {
    if (streamSize < 0L)
        throw new IllegalArgumentException(BadSize);
    if (randomNumberOrigin >= randomNumberBound)
        throw new IllegalArgumentException(BadRange);
    return StreamSupport.intStream
        (new RandomIntsSpliterator
         (0L, streamSize, randomNumberOrigin, randomNumberBound),
         false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:ThreadLocalRandom.java

示例11: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns a stream producing the given {@code streamSize} number
 * of pseudorandom {@code int} values from this generator and/or
 * one split from it.
 *
 * @param streamSize the number of values to generate
 * @return a stream of pseudorandom {@code int} values
 * @throws IllegalArgumentException if {@code streamSize} is
 *         less than zero
 */
public IntStream ints(long streamSize) {
    if (streamSize < 0L)
        throw new IllegalArgumentException(BadSize);
    return StreamSupport.intStream
        (new RandomIntsSpliterator
         (this, 0L, streamSize, Integer.MAX_VALUE, 0),
         false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:SplittableRandom.java

示例12: ints

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns a stream producing the given {@code streamSize} number
 * of pseudorandom {@code int} values from this generator and/or
 * one split from it.
 *
 * @param streamSize the number of values to generate
 * @return a stream of pseudorandom {@code int} values
 * @throws IllegalArgumentException if {@code streamSize} is
 *         less than zero
 */
public IntStream ints(long streamSize) {
    if (streamSize < 0L)
        throw new IllegalArgumentException(BAD_SIZE);
    return StreamSupport.intStream
        (new RandomIntsSpliterator
         (this, 0L, streamSize, Integer.MAX_VALUE, 0),
         false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:SplittableRandom.java

示例13: stream

import java.util.stream.StreamSupport; //导入方法依赖的package包/类
/**
 * Returns a sequential {@link IntStream} with the specified range of the
 * specified array as its source.
 *
 * @param array the array, assumed to be unmodified during use
 * @param startInclusive the first index to cover, inclusive
 * @param endExclusive index immediately past the last index to cover
 * @return an {@code IntStream} for the array range
 * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is
 *         negative, {@code endExclusive} is less than
 *         {@code startInclusive}, or {@code endExclusive} is greater than
 *         the array size
 * @since 1.8
 */
public static IntStream stream(int[] array, int startInclusive, int endExclusive) {
    return StreamSupport.intStream(spliterator(array, startInclusive, endExclusive), false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:Arrays.java


注:本文中的java.util.stream.StreamSupport.intStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。