Java Code Examples for java.util.stream.IntStream#empty()
The following examples show how to use
java.util.stream.IntStream#empty() .
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
Source File: BitSetStreamTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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 File: Randoms.java From jenetics with Apache License 2.0 | 6 votes |
/** * 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 File: Streams.java From gadtry with Apache License 2.0 | 5 votes |
/** * @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 File: Streams.java From arctic-sea with Apache License 2.0 | 5 votes |
/** * 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
Source File: PluginDefaultGroovyMethods.java From groovy with Apache License 2.0 | 5 votes |
/** * 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 File: Tweet.java From TweetwallFX with MIT License | 5 votes |
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 File: Unit1MyCreate.java From hol-streams with Apache License 2.0 | 4 votes |
@Override public IntStream newIntStreamOfOneToSeven() { return IntStream.empty(); }
Example 8
Source File: Unit1MyCreate.java From hol-streams with Apache License 2.0 | 4 votes |
@Override public IntStream from(String s) { return IntStream.empty(); }
Example 9
Source File: Unit1MyCreate.java From hol-streams with Apache License 2.0 | 4 votes |
@Override public IntStream infiniteAlternating() { return IntStream.empty(); }
Example 10
Source File: Unit1MyCreate.java From hol-streams with Apache License 2.0 | 4 votes |
@Override public IntStream infiniteRandomInts(Random rnd) { return IntStream.empty(); }
Example 11
Source File: Unit2MyIntermediate.java From hol-streams with Apache License 2.0 | 4 votes |
@Override public IntStream lengthOfWords(Stream<String> stream) { return IntStream.empty(); }
Example 12
Source File: Unit2MyIntermediate.java From hol-streams with Apache License 2.0 | 4 votes |
@Override public IntStream increasingSawtooth() { return IntStream.empty(); }
Example 13
Source File: TroveUtil.java From consulo with Apache License 2.0 | 4 votes |
@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 File: OptionalInt.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * 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
Source File: OptionalInt.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * 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
Source File: IntStreamExample.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void intstream_empty() { IntStream emptyStream = IntStream.empty(); assertEquals(0, emptyStream.count()); }