java.util.stream.IntStream#empty ( )源码实例Demo

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

源代码1 项目: openjdk-jdk9   文件: BitSetStreamTest.java
@DataProvider(name = "cases")
public static Object[][] produceCases() {
    return new Object[][] {
            { "none", IntStream.empty() },
            { "index 0", IntStream.of(0) },
            { "index 255", IntStream.of(255) },
            { "index 0 and 255", IntStream.of(0, 255) },
            { "index Integer.MAX_VALUE", IntStream.of(Integer.MAX_VALUE) },
            { "index Integer.MAX_VALUE - 1", IntStream.of(Integer.MAX_VALUE - 1) },
            { "index 0 and Integer.MAX_VALUE", IntStream.of(0, Integer.MAX_VALUE) },
            { "every bit", IntStream.range(0, 255) },
            { "step 2", IntStream.range(0, 255).map(f -> f * 2) },
            { "step 3", IntStream.range(0, 255).map(f -> f * 3) },
            { "step 5", IntStream.range(0, 255).map(f -> f * 5) },
            { "step 7", IntStream.range(0, 255).map(f -> f * 7) },
            { "1, 10, 100, 1000", IntStream.of(1, 10, 100, 1000) },
            { "25 fibs", IntStream.generate(new Fibs()).limit(25) }
    };
}
 
源代码2 项目: jenetics   文件: Randoms.java
/**
 * Create an {@code IntStream} which creates random indexes within the
 * given range and the index probability.
 *
 * @since 3.0
 *
 * @param random the random engine used for calculating the random
 *        indexes
 * @param start the start index (inclusively)
 * @param end the end index (exclusively)
 * @param p the index selection probability
 * @return an new random index stream
 * @throws IllegalArgumentException if {@code p} is not a
 *         valid probability.
 */
public static IntStream indexes(
	final Random random,
	final int start,
	final int end,
	final double p
) {
	probability(p);
	final int P = Probabilities.toInt(p);

	return equals(p, 0, 1E-20)
		? IntStream.empty()
		: equals(p, 1, 1E-20)
			? IntStream.range(start, end)
			: IntStream.range(start, end)
				.filter(i -> random.nextInt() < P);
}
 
源代码3 项目: gadtry   文件: Streams.java
/**
 * @param start 计数从 start 开始.默认是从 0 开始. 例如range(5)等价于range(0,5)
 * @param stop 计数到 stop 结束,但不包括 stop
 * @param step 步长,默认为1
 * @return IntStream
 */
public static IntStream range(final int start, int stop, int step)
{
    checkState(step != 0, "step must not 0");
    int limit = (stop - start + Math.abs(step) - 1) / step;
    if (limit <= 0) {
        return IntStream.empty();
    }

    PrimitiveIterator.OfInt ofInt = new PrimitiveIterator.OfInt()
    {
        private int next = start;
        private int cnt = 0;

        @Override
        public boolean hasNext()
        {
            return cnt < limit;
        }

        @Override
        public int nextInt()
        {
            int tmp = next;
            next += step;
            cnt++;
            return tmp;
        }
    };
    Spliterator.OfInt a1 = Spliterators.spliterator(ofInt, limit, Spliterator.ORDERED | Spliterator.IMMUTABLE);
    return StreamSupport.intStream(a1, false);
}
 
源代码4 项目: arctic-sea   文件: Streams.java
/**
 * Factory function for creating a {@code Stream} from an array.
 *
 * @param array the array
 * @return the stream
 */
public static IntStream stream(int[] array) {
    if (array == null) {
        return IntStream.empty();
    }
    return Arrays.stream(array);
}
 
源代码5 项目: groovy   文件: PluginDefaultGroovyMethods.java
/**
 * If a value is present in the {@link OptionalInt}, returns an {@link IntStream}
 * with the value as its source or else an empty stream.
 *
 * @since 3.0.0
 */
public static IntStream stream(final OptionalInt self) {
    if (!self.isPresent()) {
        return IntStream.empty();
    }
    return IntStream.of(self.getAsInt());
}
 
源代码6 项目: TweetwallFX   文件: Tweet.java
public String get() {
    if (entriesToRemove.isEmpty()) {
        return tweet.getText();
    }

    IntStream filteredIndexes = IntStream.empty();
    for (TweetEntry tweetEntry : entriesToRemove) {
        final IntStream nextFilter;

        if (tweetEntry.getStart() == tweetEntry.getEnd()) {
            nextFilter = IntStream.of(tweetEntry.getStart());
        } else {
            nextFilter = IntStream.range(tweetEntry.getStart(), tweetEntry.getEnd());
        }

        filteredIndexes = IntStream.concat(filteredIndexes, nextFilter);
    }

    final Set<Integer> indexesToFilterOut = filteredIndexes.boxed().collect(toCollection(TreeSet::new));
    final int[] chars = tweet.getText().chars().toArray();
    final int[] filteredChars = IntStream.range(0, chars.length)
            .filter(i -> !indexesToFilterOut.contains(i))
            .map(i -> chars[i])
            .toArray();

    return new String(filteredChars, 0, filteredChars.length)
            .replaceAll("  *", " ")
            .trim();
}
 
源代码7 项目: hol-streams   文件: Unit1MyCreate.java
@Override
public IntStream newIntStreamOfOneToSeven() {
    return IntStream.empty();
}
 
源代码8 项目: hol-streams   文件: Unit1MyCreate.java
@Override
public IntStream from(String s) {
    return IntStream.empty();
}
 
源代码9 项目: hol-streams   文件: Unit1MyCreate.java
@Override
public IntStream infiniteAlternating() {
    return IntStream.empty();
}
 
源代码10 项目: hol-streams   文件: Unit1MyCreate.java
@Override
public IntStream infiniteRandomInts(Random rnd) {
    return IntStream.empty();
}
 
源代码11 项目: hol-streams   文件: Unit2MyIntermediate.java
@Override
public IntStream lengthOfWords(Stream<String> stream) {
    return IntStream.empty();
}
 
源代码12 项目: hol-streams   文件: Unit2MyIntermediate.java
@Override
public IntStream increasingSawtooth() {
    return IntStream.empty();
}
 
源代码13 项目: consulo   文件: TroveUtil.java
@Nonnull
public static IntStream stream(@Nonnull TIntArrayList list) {
  if (list.isEmpty()) return IntStream.empty();
  return IntStream.range(0, list.size()).map(list::get);
}
 
源代码14 项目: Bytecoder   文件: OptionalInt.java
/**
 * If a value is present, returns a sequential {@link IntStream} containing
 * only that value, otherwise returns an empty {@code IntStream}.
 *
 * @apiNote
 * This method can be used to transform a {@code Stream} of optional
 * integers to an {@code IntStream} of present integers:
 * <pre>{@code
 *     Stream<OptionalInt> os = ..
 *     IntStream s = os.flatMapToInt(OptionalInt::stream)
 * }</pre>
 *
 * @return the optional value as an {@code IntStream}
 * @since 9
 */
public IntStream stream() {
    if (isPresent) {
        return IntStream.of(value);
    } else {
        return IntStream.empty();
    }
}
 
源代码15 项目: openjdk-jdk9   文件: OptionalInt.java
/**
 * If a value is present, returns a sequential {@link IntStream} containing
 * only that value, otherwise returns an empty {@code IntStream}.
 *
 * @apiNote
 * This method can be used to transform a {@code Stream} of optional
 * integers to an {@code IntStream} of present integers:
 * <pre>{@code
 *     Stream<OptionalInt> os = ..
 *     IntStream s = os.flatMapToInt(OptionalInt::stream)
 * }</pre>
 *
 * @return the optional value as an {@code IntStream}
 * @since 9
 */
public IntStream stream() {
    if (isPresent) {
        return IntStream.of(value);
    } else {
        return IntStream.empty();
    }
}
 
源代码16 项目: levelup-java-examples   文件: IntStreamExample.java
@Test
public void intstream_empty() {

	IntStream emptyStream = IntStream.empty();

	assertEquals(0, emptyStream.count());
}