Java Code Examples for java.util.stream.IntStream#empty()

The following examples show how to use java.util.stream.IntStream#empty() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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) }
    };
}
 
Example 2
Source Project: jenetics   File: Randoms.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source Project: gadtry   File: Streams.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example 4
Source Project: arctic-sea   File: Streams.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
/**
 * 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());
}
 
Example 6
Source Project: TweetwallFX   File: Tweet.java    License: MIT License 5 votes vote down vote up
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();
}
 
Example 7
Source Project: hol-streams   File: Unit1MyCreate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IntStream newIntStreamOfOneToSeven() {
    return IntStream.empty();
}
 
Example 8
Source Project: hol-streams   File: Unit1MyCreate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IntStream from(String s) {
    return IntStream.empty();
}
 
Example 9
Source Project: hol-streams   File: Unit1MyCreate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IntStream infiniteAlternating() {
    return IntStream.empty();
}
 
Example 10
Source Project: hol-streams   File: Unit1MyCreate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IntStream infiniteRandomInts(Random rnd) {
    return IntStream.empty();
}
 
Example 11
Source Project: hol-streams   File: Unit2MyIntermediate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IntStream lengthOfWords(Stream<String> stream) {
    return IntStream.empty();
}
 
Example 12
Source Project: hol-streams   File: Unit2MyIntermediate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IntStream increasingSawtooth() {
    return IntStream.empty();
}
 
Example 13
Source Project: consulo   File: TroveUtil.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public static IntStream stream(@Nonnull TIntArrayList list) {
  if (list.isEmpty()) return IntStream.empty();
  return IntStream.range(0, list.size()).map(list::get);
}
 
Example 14
Source Project: Bytecoder   File: OptionalInt.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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();
    }
}
 
Example 15
/**
 * 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();
    }
}
 
Example 16
@Test
public void intstream_empty() {

	IntStream emptyStream = IntStream.empty();

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