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

x33g5p2x  于2022-01-16 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(151)

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

Stream.count介绍

暂无

代码示例

代码示例来源:origin: JanusGraph/janusgraph

public static void assertCount(long expected, Stream stream) {
  org.junit.Assert.assertEquals(expected, stream.count());
}

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

private static int getNullFlagsCount(List<ArgumentProperty> argumentProperties)
{
  return (int) argumentProperties.stream()
      .filter(argumentProperty -> argumentProperty.getNullConvention() == USE_NULL_FLAG)
      .count();
}

代码示例来源:origin: floragunncom/search-guard

public boolean impliesClusterPermissionPermission(String action) {
  return roles.stream()
      .filter(r->r.impliesClusterPermission(action)).count() > 0;
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public void serial_lazy_jdk()
{
  long evens = this.integersJDK.stream().filter(each -> each % 2 == 0).count();
  Assert.assertEquals(SIZE / 2, evens);
}

代码示例来源:origin: kiegroup/optaplanner

public int missingSpeakerPreferredTimeslotTagCount() {
  if (timeslot == null) {
    return 0;
  }
  return (int) speakerList.stream().flatMap(speaker -> speaker.getPreferredTimeslotTagSet().stream())
      .filter(tag -> !timeslot.hasTag(tag)).count();
}

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

@Test
public void testLoadNonExistent() {
  assertEquals(0L, testSubject.readEvents(randomUUID().toString()).asStream().count());
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public void parallel_lazy_jdk()
{
  long evens = this.integersJDK.parallelStream().filter(each -> each % 2 == 0).count();
  Assert.assertEquals(SIZE / 2, evens);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void streamIsEmptyForEmptyValues() {
  MutablePropertyValues pvs = new MutablePropertyValues();
  assertThat(pvs.stream(), notNullValue());
  assertThat(pvs.stream().count(), is(0L));
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Test
public void shouldNotRewindPastStartOfQueueWhenDisplayingHistory() {
  basicReader().historyRecords(Long.MAX_VALUE).execute();
  assertThat(capturedOutput.stream().
      filter(msg -> !msg.startsWith("0x")).count(), is(24L));
}

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

private static boolean hasMixedDistinctAndNonDistincts(AggregationNode aggregation)
{
  long distincts = aggregation.getAggregations()
      .values().stream()
      .map(Aggregation::getCall)
      .filter(FunctionCall::isDistinct)
      .count();
  return distincts > 0 && distincts < aggregation.getAggregations().size();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void streamAlreadyConsumed() {
  AssertSubscriber<Integer> ts = AssertSubscriber.create();
  Stream<Integer> s = source.stream();
  s.count();
  Flux.fromStream(s)
    .subscribe(ts);
  ts.assertNoValues()
   .assertNotComplete()
   .assertError(IllegalStateException.class);
}

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

@Test
public void testNonDeterministic()
{
  MaterializedResult materializedResult = computeActual("SELECT rand() FROM orders LIMIT 10");
  long distinctCount = materializedResult.getMaterializedRows().stream()
      .map(row -> row.getField(0))
      .distinct()
      .count();
  assertTrue(distinctCount >= 8, "rand() must produce different rows");
  materializedResult = computeActual("SELECT apply(1, x -> x + rand()) FROM orders LIMIT 10");
  distinctCount = materializedResult.getMaterializedRows().stream()
      .map(row -> row.getField(0))
      .distinct()
      .count();
  assertTrue(distinctCount >= 8, "rand() must produce different rows");
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public void serial_lazy_jdk()
{
  long evens = this.integersJDK.stream().filter(each -> each % 2 == 0).count();
  Assert.assertEquals(SIZE / 2, evens);
}

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

private static int getBlockPositionCount(List<ArgumentProperty> argumentProperties)
{
  return (int) argumentProperties.stream()
      .filter(argumentProperty -> argumentProperty.getNullConvention() == BLOCK_AND_POSITION)
      .count();
}

代码示例来源:origin: kiegroup/optaplanner

public int prevailingSpeakerUndesiredTimeslotTagCount() {
  if (timeslot == null) {
    return 0;
  }
  return (int) speakerList.stream().flatMap(speaker -> speaker.getUndesiredTimeslotTagSet().stream())
      .filter(tag -> timeslot.hasTag(tag)).count();
}

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void largeTest() throws Exception {
  final int numDoc = 30000;
  final String store = "vertex";
  initialize(store);
  for (int i = 1; i <= numDoc; i++) {
    add(store, "doc" + i, getRandomDocument(), true);
  }
  clopen();
  final long time = System.currentTimeMillis();
  Stream<String> result = tx.queryStream(new IndexQuery(store, And.of(PredicateCondition.of(WEIGHT, Cmp.GREATER_THAN_EQUAL, 0.2), PredicateCondition.of(WEIGHT, Cmp.LESS_THAN, 0.6), PredicateCondition.of(LOCATION, Geo.WITHIN, Geoshape.circle(48.5, 0.5, 1000.00)))));
  final long oldResultSize = result.count();
  System.out.println(oldResultSize + " vs " + (numDoc / 1000 * 2.4622623015));
  System.out.println("Query time on " + numDoc + " docs (ms): " + (System.currentTimeMillis() - time));
  result = tx.queryStream(new IndexQuery(store, And.of(PredicateCondition.of(WEIGHT, Cmp.GREATER_THAN_EQUAL, 0.2), PredicateCondition.of(WEIGHT, Cmp.LESS_THAN, 0.6), PredicateCondition.of(LOCATION, Geo.WITHIN, Geoshape.circle(48.5, 0.5, 1000.00))), numDoc / 1000));
  assertEquals(numDoc / 1000, result.count());
  result = tx.queryStream(new IndexQuery(store, And.of(PredicateCondition.of(WEIGHT, Cmp.GREATER_THAN_EQUAL, 0.2), PredicateCondition.of(WEIGHT, Cmp.LESS_THAN, 0.6), PredicateCondition.of(LOCATION, Geo.WITHIN, Geoshape.circle(48.5, 0.5, 1000.00))), numDoc / 1000 * 100));
  assertEquals(oldResultSize, result.count());
}

代码示例来源:origin: SonarSource/sonarqube

private void checkAtLeastOneActionIsDefined(Set<String> actions) {
 long actionsDefined = actions.stream().filter(action -> !action.equals(COMMENT_KEY)).count();
 checkArgument(actionsDefined > 0, "At least one action must be provided");
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public void parallel_lazy_jdk()
{
  long evens = this.integersJDK.parallelStream().filter(each -> each % 2 == 0).count();
  Assert.assertEquals(SIZE / 2, evens);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void streamIsEmptyForEmptySources() {
  MutablePropertySources sources = new MutablePropertySources();
  assertThat(sources.stream(), notNullValue());
  assertThat(sources.stream().count(), is(0L));
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Test
public void shouldFilterByMultipleExclusionRegex() {
  basicReader().withExclusionRegex(".*bye$").withExclusionRegex(".*ell.*").execute();
  assertThat(capturedOutput.stream().filter(msg -> !msg.startsWith("0x")).count(), is(0L));
}

相关文章