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

The following examples show how to use java.util.stream.IntStream#of() . 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: Settings.java    From rtc2jira with 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 File: Convertors.java    From Java-Coding-Problems with 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
Source File: PluginDefaultGroovyMethods.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * 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 File: ConcatenateStream.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: Tweet.java    From TweetwallFX with 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 6
Source File: RandomisedTestData.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
private static IntStream denseRegion() {
  return IntStream.of(createSorted16BitInts(ThreadLocalRandom.current().nextInt(4096, 1 << 16)));
}
 
Example 7
Source File: SumUniqueValsTwoIntStreams.java    From levelup-java-examples with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: IteratorsAbstractFastPreferenceDataTest.java    From RankSys with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public IntIterator getIidxUidxs(int iidx) {
    return new StreamIntIterator(IntStream.of(18, 20, 100, 101, 102));
}
 
Example 9
Source File: MethodSourcePrimitiveTypesParameterizedTest.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 4 votes vote down vote up
static IntStream intProvider() {
    return IntStream.of(0, 1);
}
 
Example 10
Source File: RandomisedTestData.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
private static IntStream sparseRegion() {
  return IntStream.of(createSorted16BitInts(ThreadLocalRandom.current().nextInt(1, 4096)));
}
 
Example 11
Source File: CalibrateSaturationBase_CalMAN.java    From testing-video with GNU General Public License v3.0 4 votes vote down vote up
protected IntStream stimulus() {
    return IntStream.of(75, 100);
}
 
Example 12
Source File: CalibrateSaturation2160pHLG10_CalMAN.java    From testing-video with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected IntStream stimulus() {
    return IntStream.of(25, 50, 75);
}
 
Example 13
Source File: NumberUtils.java    From ApprovalTests.Java with Apache License 2.0 4 votes vote down vote up
public static IntStream toIntStream(int[] numbers)
{
  return IntStream.of(numbers);
}
 
Example 14
Source File: CalibrateSaturation1080pHLG10_CalMAN.java    From testing-video with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected IntStream stimulus() {
    return IntStream.of(25, 50, 75);
}
 
Example 15
Source File: HopperMinecartEntity_transferItemsOutFeatureMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 16
Source File: OptionalInt.java    From openjdk-jdk9 with GNU General Public License v2.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 17
Source File: StreamsUpdate.java    From blog-tutorials with 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 18
Source File: IntArray.java    From Strata with 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 File: Face3.java    From FXyzLib with 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 File: Face3.java    From FXyzLib with 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); }