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

x33g5p2x  于2022-01-23 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(106)

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

LongStream.distinct介绍

[英]Returns a stream consisting of the distinct elements of this stream.

This is a stateful intermediate operation.
[中]返回由此流的不同元素组成的流。
这是一个stateful intermediate operation

代码示例

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

public LongDistinctAction() {
  super(s -> s.distinct(), LongStream.class, DISTINCT);
}

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

public static long[] getReplicationBarriers(Result result) {
 return result.getColumnCells(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER)
  .stream().mapToLong(MetaTableAccessor::getReplicationBarrier).sorted().distinct().toArray();
}

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

@Override
public LongStream distinct() {
  return wrap(stream().distinct());
}

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

@Override
  @SuppressWarnings("unchecked")
  public TS build(boolean parallel) {
    final TS built = previous().build(parallel);
    if (built instanceof Stream<?>) {
      return (TS) ((Stream<T>) built).distinct();
    } else if (built instanceof IntStream) {
      return (TS) ((IntStream) built).distinct();
    } else if (built instanceof LongStream) {
      return (TS) ((LongStream) built).distinct();
    } else if (built instanceof DoubleStream) {
      return (TS) ((DoubleStream) built).distinct();
    } else {
      throw new UnsupportedOperationException(
        "Built stream did not match any known stream interface."
      );
    }
  }
}

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

private void expectPermissions(PermissionQuery query, Collection<Integer> expectedUserIds, UserPermissionDto... expectedPermissions) {
 assertThat(underTest.selectUserIdsByQuery(dbSession, query)).containsExactly(expectedUserIds.toArray(new Integer[0]));
 List<UserPermissionDto> currentPermissions = underTest.selectUserPermissionsByQuery(dbSession, query, expectedUserIds);
 assertThat(currentPermissions).hasSize(expectedPermissions.length);
 List<Tuple> expectedPermissionsAsTuple = Arrays.stream(expectedPermissions)
  .map(expectedPermission -> tuple(expectedPermission.getUserId(), expectedPermission.getPermission(), expectedPermission.getComponentId(),
   expectedPermission.getOrganizationUuid()))
  .collect(Collectors.toList());
 assertThat(currentPermissions)
  .extracting(UserPermissionDto::getUserId, UserPermissionDto::getPermission, UserPermissionDto::getComponentId, UserPermissionDto::getOrganizationUuid)
  .containsOnly(expectedPermissionsAsTuple.toArray(new Tuple[0]));
 // test method "countUsers()"
 long distinctUsers = stream(expectedPermissions).mapToLong(UserPermissionDto::getUserId).distinct().count();
 assertThat((long) underTest.countUsersByQuery(dbSession, query)).isEqualTo(distinctUsers);
}

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

@Test(dataProvider = "filterTypes")
public void bloomFilterTest(FilterType filterType) {
 for (int capacity = 2 << 10; capacity < (2 << 22); capacity = capacity << 2) {
  long[] input = new Random().longs(capacity).distinct().toArray();
  List<String[]> rows = new ArrayList<>();
  int expectedInsertions = capacity / 2;
  Membership filter = filterType.create(expectedInsertions, FPP, CONFIG);
  int falsePositives = falsePositives(filter, input);
  double falsePositiveRate = ((double) falsePositives / expectedInsertions);
  assertThat(filterType.toString(), falsePositiveRate, is(lessThan(FPP + 0.01)));
  rows.add(row(filterType, expectedInsertions, falsePositives, falsePositiveRate));
  if (display) {
   printTable(rows);
  }
 }
}

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

public static long[] getReplicationBarriers(Result result) {
 return result.getColumnCells(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER)
  .stream().mapToLong(MetaTableAccessor::getReplicationBarrier).sorted().distinct().toArray();
}

代码示例来源:origin: com.speedment.runtime/runtime-core

public LongDistinctAction() {
  super(s -> s.distinct(), LongStream.class, DISTINCT);
}

代码示例来源:origin: net.dongliu/commons-lang

@Override
public ExLongStream distinct() {
  return ExLongStream.of(stream.distinct());
}

代码示例来源:origin: se.ugli.ugli-commons/ugli-commons

@Override
public LongStream distinct() {
  return new LongResourceStream(stream.distinct(), closeOnTerminalOperation, resources);
}

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

private boolean shouldMerge(Set<Actor> actors) {
  return actors.size() > 1 && (actors.stream().anyMatch(a -> a.user.userId == 0)
      || actors.stream().mapToLong(a -> a.user.userId).distinct().count() > 1);
}

代码示例来源:origin: io.fd.hc2vpp.lisp/lisp2vpp

@Nonnull
@Override
public List<NativeForwardPathsTableKey> getAllIds(@Nonnull final InstanceIdentifier<NativeForwardPathsTable> id,
                         @Nonnull final ReadContext context) throws ReadFailedException {
  return Stream.concat(v4FibsStream(id, context), v6FibsStream(id, context))
      .mapToLong(UnsignedInts::toLong)
      .distinct()
      .mapToObj(NativeForwardPathsTableKey::new)
      .collect(Collectors.toList());
}

代码示例来源:origin: one.util/streamex

@Override
public LongStreamEx distinct() {
  return new LongStreamEx(stream().distinct(), context);
}

代码示例来源:origin: com.speedment.runtime/runtime-core

@Override
public LongStream distinct() {
  return wrap(stream().distinct());
}

代码示例来源:origin: dmart28/reveno

public LinkViewSet(long[] ids, Class<V> viewType) {
  super(LongStream.of(ids).distinct().toArray(), viewType);
}

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

public List<Point> getRandomPoints(int num) {
  long count=allValues().count();

  assert count > num;

  return new Random().longs(0, count)
    .distinct()
    .limit(num)
    .mapToObj(i -> allValues().skip(i).findFirst().get())
    .collect(Collectors.toList());
}

代码示例来源:origin: MER-C/wiki-java

.distinct()
.filter(id -> id >= 0)
.sorted()

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

public LongStream allValuesAsLong() {
  return LongStream.concat(LongStream.concat(
   LongStream.range(2384, 2413).map(x -> x     <<32 | 3072),
   LongStream.range(3072, 3084).map(y -> 2413L <<32 | y)
  ),
  //...
   LongStream.range(2386, 2415).map(x -> x     <<32 | 3135)
  );
}
public List<Point> getRandomPoints(int num) {
  long count=allValuesAsLong().count();

  assert count > num;

  return new Random().longs(0, count)
    .distinct()
    .limit(num)
    .mapToObj(i -> allValuesAsLong().skip(i)
      .mapToObj(l -> new Point((int)(l>>>32), (int)(l&(1L<<32)-1)))
      .findFirst().get())
    .collect(Collectors.toList());
}

代码示例来源:origin: io.fd.hc2vpp.lisp/lisp2vpp

@Override
public void readCurrentAttributes(@Nonnull final InstanceIdentifier<NativeForwardPathsTable> id,
                 @Nonnull final NativeForwardPathsTableBuilder builder,
                 @Nonnull final ReadContext ctx)
    throws ReadFailedException {
  final Long tableId = id.firstKeyOf(NativeForwardPathsTable.class).getTableId();
  final OptionalLong optionalTable = Stream.concat(v4FibsStream(id, ctx), v6FibsStream(id, ctx))
      .mapToLong(UnsignedInts::toLong)
      .distinct()
      .filter(tblId -> tblId == tableId)
      .findAny();
  if (optionalTable.isPresent()) {
    final long existingTableId = optionalTable.getAsLong();
    builder.setTableId(existingTableId);
    builder.withKey(new NativeForwardPathsTableKey(existingTableId));
  }
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

@Test
  void nextModSeqShouldGenerateUniqueValuesWhenParallelCalls() {
    int nbEntries = 100;
    long nbValues = LongStream.range(0, nbEntries)
      .parallel()
      .map(Throwing.longUnaryOperator(x -> modSeqProvider.nextModSeq(null, mailbox)))
      .distinct()
      .count();
    assertThat(nbValues).isEqualTo(nbEntries);
  }
}

相关文章

微信公众号

最新文章

更多