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

The following examples show how to use java.util.stream.IntStream#of() . 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
Source Project: rtc2jira   File: Settings.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Collection<Integer> getRtcWorkItemRange() {
  String rangesString = props.getProperty(RTC_WORKITEM_ID_RANGE);
  String[] ranges = rangesString.split(",");
  IntStream intStream = IntStream.of();
  for (String range : ranges) {
    String[] splitted = range.split("\\.\\.");
    int from = Integer.parseInt(splitted[0].trim());
    if (splitted.length == 1) {
      intStream = IntStream.concat(intStream, IntStream.rangeClosed(from, from));
    } else {
      int to = Integer.parseInt(splitted[1].trim());
      intStream = IntStream.concat(intStream, IntStream.rangeClosed(from, to));
    }
  }
  return intStream.boxed().collect(Collectors.toList());
}
 
Example 2
Source Project: Java-Coding-Problems   File: Convertors.java    License: MIT License 5 votes vote down vote up
public static IntStream toStream5(int[] arr) {

        if (arr == null) {
            throw new IllegalArgumentException("Inputs cannot be null");
        }

        return IntStream.of(arr);
    }
 
Example 3
/**
 * 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 4
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 5
@Test
public void join_intstream() {

	IntStream intStream1 = IntStream.of(1, 2);
	IntStream intStream2 = IntStream.of(3, 4);

	IntStream.concat(intStream1, intStream2).forEach(
			e -> System.out.println(e));
}
 
Example 6
@Test
public void sum_unique_values_intstream() {

	IntStream stream1 = IntStream.of(1, 2, 3);
	IntStream stream2 = IntStream.of(1, 2, 3);

	int val = IntStream.concat(stream1, stream2).distinct().sum();

	assertEquals(6, val);

	// or
	IntStream stream3 = IntStream.of(1, 2, 3);
	IntStream stream4 = IntStream.of(1, 2, 3);

	OptionalInt sum2 = IntStream.concat(stream3, stream4).distinct()
			.reduce((a, b) -> a + b);

	assertEquals(6, sum2.getAsInt());
}
 
Example 7
private static IntStream getAvailableSlots(Inventory inventory_1, Direction direction_1) {
    return inventory_1 instanceof SidedInventory ? IntStream.of(((SidedInventory)inventory_1).getInvAvailableSlots(direction_1)) : IntStream.range(0, inventory_1.getInvSize());
}
 
Example 8
@Override
protected IntStream stimulus() {
    return IntStream.of(25, 50, 75);
}
 
Example 9
Source Project: ApprovalTests.Java   File: NumberUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static IntStream toIntStream(int[] numbers)
{
  return IntStream.of(numbers);
}
 
Example 10
@Override
protected IntStream stimulus() {
    return IntStream.of(25, 50, 75);
}
 
Example 11
protected IntStream stimulus() {
    return IntStream.of(75, 100);
}
 
Example 12
private static IntStream sparseRegion() {
  return IntStream.of(createSorted16BitInts(ThreadLocalRandom.current().nextInt(1, 4096)));
}
 
Example 13
static IntStream intProvider() {
    return IntStream.of(0, 1);
}
 
Example 14
@Override
public IntIterator getIidxUidxs(int iidx) {
    return new StreamIntIterator(IntStream.of(18, 20, 100, 101, 102));
}
 
Example 15
private static IntStream denseRegion() {
  return IntStream.of(createSorted16BitInts(ThreadLocalRandom.current().nextInt(4096, 1 << 16)));
}
 
Example 16
Source Project: blog-tutorials   File: StreamsUpdate.java    License: MIT License 3 votes vote down vote up
public static void main(String[] args) {

		final IntStream intStream1 = IntStream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

		System.out.println(
				intStream1.takeWhile(n -> n <= 5).mapToObj(Integer::toString).collect(Collectors.joining(", ")));

		final IntStream intStream2 = IntStream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

		System.out.println(intStream2.dropWhile(n -> n < 5).sum());

		final List<String> names = List.of("Tom", "Paul", "Mike", "Duke", "", "Michelle", "Anna");

		names.stream().takeWhile(s -> !s.isEmpty()).forEach(System.out::println);
	}
 
Example 17
/**
 * 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 18
Source Project: Strata   File: IntArray.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns a stream over the array values.
 *
 * @return a stream over the values in the array
 */
public IntStream stream() {
  return IntStream.of(array);
}
 
Example 19
Source Project: FXyzLib   File: Face3.java    License: GNU General Public License v3.0 votes vote down vote up
public IntStream getFace(int t) { return IntStream.of(p0,t,p1,t,p2,t); } 
Example 20
Source Project: FXyzLib   File: Face3.java    License: GNU General Public License v3.0 votes vote down vote up
public IntStream getFace(int t0, int t1, int t2) { return IntStream.of(p0,t0,p1,t1,p2,t2); }