/** * Returns a sequential ordered {@code IntStreamEx} whose elements are the * specified values casted to int. * * @param elements the elements of the new stream * @return the new stream * @since 0.2.0 */ public static IntStreamEx of(char... elements) { return of(elements, 0, elements.length); }
/** * Returns a sequential ordered {@code IntStreamEx} whose elements are the * specified values casted to int. * * @param elements the elements of the new stream * @return the new stream * @since 0.2.0 */ public static IntStreamEx of(short... elements) { return of(elements, 0, elements.length); }
/** * Returns a sequential ordered {@code IntStreamEx} whose elements are the * specified values casted to int. * * @param elements the elements of the new stream * @return the new stream * @since 0.2.0 */ public static IntStreamEx of(byte... elements) { return of(elements, 0, elements.length); }
/** * Returns a sequential {@code IntStreamEx} containing a single element. * * @param element the single element * @return a singleton sequential stream */ public static IntStreamEx of(int element) { return of(new ConstSpliterator.OfInt(element, 1, true)); }
/** * Returns an empty sequential {@code IntStreamEx}. * * @return an empty sequential stream */ public static IntStreamEx empty() { return of(Spliterators.emptyIntSpliterator()); }
/** * Returns a sequential ordered {@code IntStreamEx} whose elements are the * specified values. * * @param elements the elements of the new stream * @return the new stream */ public static IntStreamEx of(int... elements) { return of(Arrays.spliterator(elements)); }
/** * Returns a sequential {@code IntStreamEx} containing an * {@link OptionalInt} value, if present, otherwise returns an empty * {@code IntStreamEx}. * * @param optional the optional to create a stream of * @return a stream with an {@code OptionalInt} value if present, otherwise * an empty stream * @since 0.1.1 */ public static IntStreamEx of(OptionalInt optional) { return optional.isPresent() ? of(optional.getAsInt()) : empty(); }
/** * Returns the stream which covers all the elements emitted by this * emitter. * * @return the new stream */ default IntStreamEx stream() { return of(spliterator()); } }
/** * Returns a sequential unordered {@code IntStreamEx} of given length which * elements are equal to supplied value. * * @param value the constant value * @param length the length of the stream * @return a new {@code IntStreamEx} * @since 0.1.2 */ public static IntStreamEx constant(int value, long length) { return of(new ConstSpliterator.OfInt(value, length, false)); }
/** * Returns an {@code IntStreamEx} of {@code int} zero-extending the * {@code char} values from the supplied {@link CharSequence}. Any char * which maps to a surrogate code point is passed through uninterpreted. * * <p> * If the sequence is mutated while the stream is being read, the result is * undefined. * * @param seq sequence to read characters from * @return an IntStreamEx of char values from the sequence * @see CharSequence#chars() */ public static IntStreamEx ofChars(CharSequence seq) { return of(VER_SPEC.ofChars(seq)); }
/** * Returns a sequential {@link IntStreamEx} 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 IntStreamEx} 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 0.1.1 * @see Arrays#stream(int[], int, int) */ public static IntStreamEx of(int[] array, int startInclusive, int endExclusive) { return of(Arrays.spliterator(array, startInclusive, endExclusive)); }
/** * Returns a sequential, ordered {@link IntStreamEx} created from given * {@link java.util.PrimitiveIterator.OfInt}. * * <p> * This method is roughly equivalent to * {@code IntStreamEx.of(Spliterators.spliteratorUnknownSize(iterator, ORDERED))} * , but may show better performance for parallel processing. * * <p> * Use this method only if you cannot provide better Stream source. * * @param iterator an iterator to create the stream from. * @return the new stream * @since 0.5.1 */ public static IntStreamEx of(PrimitiveIterator.OfInt iterator) { return of(new UnknownSizeSpliterator.USOfInt(iterator)); }
/** * Returns an {@code IntStreamEx} of code point values from the supplied * {@link CharSequence}. Any surrogate pairs encountered in the sequence are * combined as if by {@linkplain Character#toCodePoint(char, char) * Character.toCodePoint} and the result is passed to the stream. Any other * code units, including ordinary BMP characters, unpaired surrogates, and * undefined code units, are zero-extended to {@code int} values which are * then passed to the stream. * * <p> * If the sequence is mutated while the stream is being read, the result is * undefined. * * @param seq sequence to read code points from * @return an IntStreamEx of Unicode code points from this sequence * @see CharSequence#codePoints() */ public static IntStreamEx ofCodePoints(CharSequence seq) { return of(seq.codePoints()); }
/** * Returns a sequential {@link IntStreamEx} with the specified range of the * specified array as its source. Array values will be casted to int. * * @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 IntStreamEx} 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 0.2.0 */ public static IntStreamEx of(char[] array, int startInclusive, int endExclusive) { rangeCheck(array.length, startInclusive, endExclusive); return of(new RangeBasedSpliterator.OfChar(startInclusive, endExclusive, array)); }
/** * Returns a sequential {@link IntStreamEx} with the specified range of the * specified array as its source. Array values will be casted to int. * * @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 IntStreamEx} 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 0.2.0 */ public static IntStreamEx of(short[] array, int startInclusive, int endExclusive) { rangeCheck(array.length, startInclusive, endExclusive); return of(new RangeBasedSpliterator.OfShort(startInclusive, endExclusive, array)); }
return of(spliterator).onClose(() -> { try { is.close();
/** * Returns a sequential {@code IntStreamEx} containing the results of * applying the given function to the corresponding pairs of values in given * two arrays. * * @param first the first array * @param second the second array * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding array elements. * @return a new {@code IntStreamEx} * @throws IllegalArgumentException if length of the arrays differs. * @since 0.2.1 */ public static IntStreamEx zip(int[] first, int[] second, IntBinaryOperator mapper) { return of(new RangeBasedSpliterator.ZipInt(0, checkLength(first.length, second.length), mapper, first, second)); }
/** * Returns a sequential {@link IntStreamEx} with the specified range of the * specified array as its source. Array values will be casted to int. * * @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 IntStreamEx} 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 0.2.0 */ public static IntStreamEx of(byte[] array, int startInclusive, int endExclusive) { rangeCheck(array.length, startInclusive, endExclusive); return of(new RangeBasedSpliterator.OfByte(startInclusive, endExclusive, array)); }
@SuppressWarnings("null") private static Message generateMessage() { final String key = RandomStringUtils.randomAlphanumeric(RANDOM.nextInt(6) + 5); final String value = IntStreamEx .of(RANDOM, 100, 0, 256) .mapToObj(Integer::toHexString) .map(Messages::pad) .map(String::toUpperCase) .joining(" "); //$NON-NLS-1$ return new Message(key, value, RANDOM.nextLong(), RANDOM.nextInt(3), System.currentTimeMillis()); }
/** * Returns a new stream containing all the elements of the original stream interspersed with * given delimiter. * * <p> * For example, {@code IntStreamEx.of(1, 2, 3).intersperse(4)} will yield a stream containing * five elements: 1, 4, 2, 4, 3. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate operation</a>. * * @param delimiter a delimiter to be inserted between each pair of elements * @return the new stream * @since 0.6.6 */ public IntStreamEx intersperse(int delimiter) { return new IntStreamEx(stream().flatMap(s -> IntStreamEx.of(delimiter, s)).skip(1), context); }