/** * Returns an object-valued {@link StreamEx} consisting of the elements of * given array corresponding to the indices which appear in this stream. * * <p> * This is an intermediate operation. * * @param <U> the element type of the new stream * @param array the array to take the elements from * @return the new stream * @since 0.1.2 */ public <U> StreamEx<U> elements(U[] array) { return mapToObj(idx -> array[idx]); }
/** * Returns an object-valued {@link StreamEx} consisting of the elements of * given {@link List} corresponding to the indices which appear in this * stream. * * <p> * The list elements are accessed using {@link List#get(int)}, so the list * should provide fast random access. The list is assumed to be unmodifiable * during the stream operations. * * <p> * This is an intermediate operation. * * @param <U> the element type of the new stream * @param list the list to take the elements from * @return the new stream * @since 0.1.2 */ public <U> StreamEx<U> elements(List<U> list) { return mapToObj(list::get); }
/** * Returns a sequential {@code StreamEx} which elements are elements of * given array in descending order. * * @param <T> the type of stream elements * @param array array to get the elements from * @return the new stream */ public static <T> StreamEx<T> ofReversed(T[] array) { int size = array.length; return IntStreamEx.ofIndices(array).mapToObj(idx -> array[size - idx - 1]); }
/** * Returns a sequential {@code StreamEx} which elements are elements of * given list in descending order. * * <p> * The list elements are accessed using {@link List#get(int)}, so the list * should provide fast random access. The list is assumed to be unmodifiable * during the stream operations. * * @param <T> the type of stream elements * @param list list to get the elements from * @return the new stream */ public static <T> StreamEx<T> ofReversed(List<? extends T> list) { int size = list.size(); return IntStreamEx.ofIndices(list).mapToObj(idx -> list.get(size - idx - 1)); }
@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()); }
return of(""); if (regex.isEmpty()) { return IntStreamEx.ofChars(str).mapToObj(ch -> new String(new char[] { (char) ch }));