java.util.stream.IntStream.forEachOrdered()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(231)

本文整理了Java中java.util.stream.IntStream.forEachOrdered()方法的一些代码示例,展示了IntStream.forEachOrdered()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IntStream.forEachOrdered()方法的具体详情如下:
包路径:java.util.stream.IntStream
类名称:IntStream
方法名:forEachOrdered

IntStream.forEachOrdered介绍

[英]Performs an action for each element of this stream, guaranteeing that each element is processed in encounter order for streams that have a defined encounter order.

This is a terminal operation.
[中]对该流的每个元素执行一个操作,确保每个元素都按照具有定义的相遇顺序的流的相遇顺序进行处理。
这是一个terminal operation

代码示例

代码示例来源:origin: speedment/speedment

@Override
  public Void execute() {
    try (final IntStream stream = buildPrevious()) {
      stream.forEachOrdered(consumer);
    }
    
    return null;
  }
}

代码示例来源:origin: speedment/speedment

default void forEachOrdered(IntPipeline pipeline, IntConsumer action) {
  requireNonNull(pipeline);
  requireNonNull(action);
  optimize(pipeline).getAsIntStream().forEachOrdered(action);
}

代码示例来源:origin: ben-manes/caffeine

public double estSkew(int k) {
  SimpleRegression regression = new SimpleRegression();
  int[] idx = { 1 };
  getTopK(k).forEachOrdered(freq -> regression.addData(Math.log(idx[0]++), Math.log(freq)));
  return -regression.getSlope();
 }
}

代码示例来源:origin: speedment/speedment

@Override
public void forEachOrdered(IntConsumer action) {
  finallyClose(() -> stream().forEachOrdered(action));
}

代码示例来源:origin: prestodb/presto

@Override
  public void serialize(IntStream stream, JsonGenerator jgen, SerializerProvider provider) throws IOException {

    try(IntStream is = stream) {
      jgen.writeStartArray();
      
      is.forEachOrdered(value -> {
        try {
          jgen.writeNumber(value);
        } catch (IOException e) {
          throw new WrappedIOException(e);
        }
      });
      
      jgen.writeEndArray();
    } catch (WrappedIOException e) {
      throw e.getCause();
    }
  }
}

代码示例来源:origin: apache/hbase

int numMetaReplicas = conf.getInt(META_REPLICAS_NUM, DEFAULT_META_REPLICA_NUM);
IntStream.range(1, numMetaReplicas)
  .forEachOrdered(i -> builder.put(i, defaultMetaReplicaZNode + "-" + i));
metaReplicaZNodes = builder.build();
rsZNode = joinZNode(baseZNode, conf.get("zookeeper.znode.rs", "rs"));

代码示例来源:origin: real-logic/agrona

@Test
public void shouldForEachOrderedInt()
{
  final List<Integer> expected = new ArrayList<>();
  IntStream.range(0, 20).forEachOrdered(expected::add);
  list.addAll(expected);
  final List<Integer> actual = new ArrayList<>();
  list.forEachOrderedInt(actual::add);
  assertThat(actual, is(expected));
}

代码示例来源:origin: real-logic/agrona

@Test
public void shouldCreateObjectRefArray()
{
  final int count = 20;
  final List<Integer> expected = new ArrayList<>();
  IntStream.range(0, count).forEachOrdered(expected::add);
  list.addAll(expected);
  assertArrayEquals(expected.toArray(), list.toArray());
}

代码示例来源:origin: apache/hbase

@Test
public void testAppend() throws InterruptedException, ExecutionException {
 AsyncTable<?> table = getTable.get();
 int count = 10;
 CountDownLatch latch = new CountDownLatch(count);
 char suffix = ':';
 AtomicLong suffixCount = new AtomicLong(0L);
 IntStream.range(0, count).forEachOrdered(
  i -> table.append(new Append(row).addColumn(FAMILY, QUALIFIER, Bytes.toBytes("" + i + suffix)))
    .thenAccept(r -> {
     suffixCount.addAndGet(Bytes.toString(r.getValue(FAMILY, QUALIFIER)).chars()
       .filter(x -> x == suffix).count());
     latch.countDown();
    }));
 latch.await();
 assertEquals((1 + count) * count / 2, suffixCount.get());
 String value = Bytes.toString(
  table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get().getValue(FAMILY, QUALIFIER));
 int[] actual = Arrays.asList(value.split("" + suffix)).stream().mapToInt(Integer::parseInt)
   .sorted().toArray();
 assertArrayEquals(IntStream.range(0, count).toArray(), actual);
}

代码示例来源:origin: real-logic/agrona

@Test
public void shouldFastRemoveUnorderedAtIndex()
{
  final int count = 20;
  IntStream.range(0, count).forEachOrdered(list::addInt);
  assertThat(list.fastUnorderedRemove(10), is(10));
  assertThat(list.size(), is(count - 1));
  assertThat(list.getInt(10), is(19));
}

代码示例来源:origin: real-logic/agrona

@Test
public void shouldRemoveAtIndex()
{
  final int count = 20;
  IntStream.range(0, count).forEachOrdered(list::addInt);
  assertThat(list.remove(10), is(10));
  assertThat(list.size(), is(count - 1));
  assertThat(list.getInt(10), is(11));
}

代码示例来源:origin: real-logic/agrona

@Test
public void shouldAddValueAtIndexWithNearlyFullCapacity()
{
  final int count = IntArrayList.INITIAL_CAPACITY - 1;
  final int value = count + 1;
  IntStream.range(0, count).forEachOrdered(list::addInt);
  list.addInt(0, value);
  assertThat(list.size(), is(count + 1));
  assertThat(list.getInt(0), is(value));
  assertThat(list.getInt(count), is(count - 1));
}

代码示例来源:origin: real-logic/agrona

@Test
public void shouldAddValueAtIndex()
{
  final int count = 20;
  IntStream.range(0, count).forEachOrdered(list::addInt);
  list.addInt(10, 777);
  assertThat(list.size(), is(count + 1));
  assertThat(list.getInt(10), is(777));
  assertThat(list.getInt(count), is(count - 1));
}

代码示例来源:origin: ehcache/ehcache3

IntStream.range(0, 10).forEachOrdered(i -> eventSink.created("k" + i, "v" + i));
IntStream.range(0, 10).forEachOrdered(i -> {
  try {
   assertThat(blockingQueue.take().getEvent().getKey()).isEqualTo("k" + i);

代码示例来源:origin: real-logic/agrona

@Test
public void shouldFastRemoveUnorderedByValue()
{
  final int count = 20;
  IntStream.range(0, count).forEachOrdered((value) -> list.addInt(value * 10));
  assertTrue(list.fastUnorderedRemoveInt(10));
  assertThat(list.size(), is(count - 1));
  assertThat(list.getInt(1), is(190));
}

代码示例来源:origin: real-logic/agrona

@Test
public void shouldIterateEntriesBySpecialisedType()
{
  final Map<Integer, Integer> expected = new HashMap<>();
  final Int2IntHashMap map = new Int2IntHashMap(Integer.MIN_VALUE);
  IntStream.range(1, 10).forEachOrdered((i) ->
  {
    map.put(i, -i);
    expected.put(i, -i);
  });
  final Map<Integer, Integer> actual = new HashMap<>();
  final Int2IntHashMap.EntryIterator iter = map.entrySet().iterator();
  while (iter.hasNext())
  {
    iter.next();
    actual.put(iter.getIntKey(), iter.getIntValue());
  }
  assertEquals(expected, actual);
}

代码示例来源:origin: real-logic/agrona

@Test
public void shouldContainCorrectValues()
{
  final int count = 20;
  IntStream.range(0, count).forEachOrdered(list::addInt);
  for (int i = 0; i < count; i++)
  {
    assertTrue(list.containsInt(i));
  }
  assertFalse(list.containsInt(-1));
  assertFalse(list.containsInt(20));
}

代码示例来源:origin: org.apache.hbase/hbase-client

int numMetaReplicas = conf.getInt(META_REPLICAS_NUM, DEFAULT_META_REPLICA_NUM);
IntStream.range(1, numMetaReplicas)
  .forEachOrdered(i -> builder.put(i, defaultMetaReplicaZNode + "-" + i));
metaReplicaZNodes = builder.build();
rsZNode = joinZNode(baseZNode, conf.get("zookeeper.znode.rs", "rs"));

代码示例来源:origin: stackoverflow.com

try (BufferedReader reader =
  Files.newBufferedReader(Paths.get(filename), Charset.defaultCharset())) {

  IntStream chars = reader.lines().flatMapToInt(String::codePoints);
  chars.forEachOrdered(c -> {
    if ((c >= 0x2639 && c <= 0x263b) ||
      (c >= 0x1f600 && c < 0x1f650) ||
      (c >= 0x1f910 && c < 0x1f930)) {

      processEmoji(c);
    }
  });
}

代码示例来源:origin: org.jline/jline

public synchronized boolean write(CharSequence d) {
  d.codePoints().forEachOrdered(c -> {
    if (!vt100_write(c) && !dumb_write(c) && c <= 0xffff) {
      dumb_echo(c);
    }
  });
  return true;
}

相关文章