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

The following examples show how to use java.util.stream.IntStream#builder() . 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: Readline.java    From termd with Apache License 2.0 6 votes vote down vote up
private void refresh(LineBuffer update, int width) {
  LineBuffer copy3 = new LineBuffer();
  IntStream.Builder consumer = IntStream.builder();
  copy3.insert(Helper.toCodePoints(currentPrompt));
  copy3.insert(buffer().toArray());
  copy3.setCursor(currentPrompt.length() + buffer().getCursor());
  LineBuffer copy2 = new LineBuffer();
  copy2.insert(Helper.toCodePoints(currentPrompt));
  copy2.insert(update.toArray());
  copy2.setCursor(currentPrompt.length() + update.getCursor());
  copy3.update(copy2, data -> {
    for (int cp : data) {
      consumer.accept(cp);
    }
  }, width);
  conn.stdoutHandler().accept(consumer.build().toArray());
  buffer.clear();
  buffer.insert(update.toArray());
  buffer.setCursor(update.getCursor());
}
 
Example 2
Source File: TagStringReader.java    From ViaVersion with MIT License 5 votes vote down vote up
private int[] intArray() throws StringTagParseException {
    final IntStream.Builder builder = IntStream.builder();
    while (this.buffer.hasMore()) {
        final Tag value = this.tag();
        if (!(value instanceof IntTag)) {
            throw this.buffer.makeError("All elements of an int array must be ints!");
        }
        builder.add(((IntTag) value).getValue());
        if (this.separatorOrCompleteWith(Tokens.ARRAY_END)) {
            return builder.build().toArray();
        }
    }
    throw this.buffer.makeError("Reached end of document without array close");
}
 
Example 3
Source File: StreamBuilderTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 4
Source File: StreamBuilderTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 5
Source File: IntStreamExTest.java    From streamex with Apache License 2.0 5 votes vote down vote up
@Test
public void testDropWhile() {
    assertArrayEquals(new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, IntStreamEx.range(100).dropWhile(
        i -> i % 10 < 5).limit(10).toArray());
    assertEquals(100, IntStreamEx.range(100).dropWhile(i -> i % 10 < 0).count());
    assertEquals(0, IntStreamEx.range(100).dropWhile(i -> i % 10 < 10).count());
    assertEquals(OptionalInt.of(0), IntStreamEx.range(100).dropWhile(i -> i % 10 < 0).findFirst());
    assertEquals(OptionalInt.empty(), IntStreamEx.range(100).dropWhile(i -> i % 10 < 10).findFirst());

    java.util.Spliterator.OfInt spltr = IntStreamEx.range(100).dropWhile(i -> i % 10 < 1).spliterator();
    assertTrue(spltr.tryAdvance((int x) -> assertEquals(1, x)));
    Builder builder = IntStream.builder();
    spltr.forEachRemaining(builder);
    assertArrayEquals(IntStreamEx.range(2, 100).toArray(), builder.build().toArray());
}
 
Example 6
Source File: EmitterSpliterator.java    From streamex with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(int t) {
    if ((vals += vals < 3 ? 1 : 0) == 2) {
        cons = IntStream.builder();
    }
    cons.accept(t);
}
 
Example 7
Source File: RollingOfIntSpliterator.java    From streams-utils with Apache License 2.0 5 votes vote down vote up
private IntStream buildSubstream() {

		IntStream.Builder subBuilder = IntStream.builder() ;
		for (int i = 0 ; i < grouping ; i++) {
			subBuilder.add(buffer[(i + bufferReadIndex.get()) % buffer.length]) ;
		}
		bufferReadIndex.incrementAndGet() ;
		return subBuilder.build() ;
	}
 
Example 8
Source File: StreamBuilderTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 9
Source File: StreamBuilderTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 10
Source File: StreamBuilderTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 11
Source File: StreamBuilderTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 12
Source File: StreamBuilderTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 13
Source File: StreamBuilderTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 14
Source File: StreamBuilderTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 15
Source File: StreamBuilderTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 16
Source File: TagStringReader.java    From adventure with MIT License 5 votes vote down vote up
private int[] intArray() throws StringTagParseException {
  final IntStream.Builder builder = IntStream.builder();
  while(this.buffer.hasMore()) {
    final BinaryTag value = this.tag();
    if(!(value instanceof IntBinaryTag)) {
      throw this.buffer.makeError("All elements of an int array must be ints!");
    }
    builder.add(((IntBinaryTag) value).intValue());
    if(this.separatorOrCompleteWith(Tokens.ARRAY_END)) {
      return builder.build().toArray();
    }
  }
  throw this.buffer.makeError("Reached end of document without array close");
}
 
Example 17
Source File: StreamBuilderTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 18
Source File: StreamBuilderTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 19
Source File: StreamBuilderTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sizes")
public void testIntAfterBuilding(int size) {
    IntStream.Builder sb = IntStream.builder();
    IntStream.range(0, size).forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
Example 20
Source File: IntColumn.java    From paleo with Apache License 2.0 4 votes vote down vote up
private Builder(IntColumnId id) {
    this.id = id;
    this.valueBuilder = IntStream.builder();
    this.metaDataBuilder = new MetaDataBuilder();
}