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

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

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

LongStream.sorted介绍

[英]Returns a stream consisting of the elements of this stream in sorted order.

This is a stateful intermediate operation.
[中]返回由该流的元素按排序顺序组成的流。
这是一个stateful intermediate operation

代码示例

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

public LongSortedAction() {
  super(s -> s.sorted(), LongStream.class, SORTED);
}

代码示例来源: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 sorted() {
  return wrap(stream().sorted());
}

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

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

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

private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs)
{
  // aggregate level
  assertAggregation(function,
      QDIGEST_EQUALITY,
      "test multiple positions",
      page,
      getExpectedValueLongs(maxError, inputs));
  // test scalars
  List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
  SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
  assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}

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

@Test
void shouldDeduplicateWithRandomArrays()
{
  int arrayLength = 5000;
  int iterations = 10;
  for ( int i = 0; i < iterations; i++ )
  {
    long[] array = ThreadLocalRandom.current().longs( arrayLength, 0, arrayLength ).sorted().toArray();
    long[] dedupedActual = PrimitiveLongCollections.deduplicate( array );
    TreeSet<Long> set = new TreeSet<>();
    for ( long value : array )
    {
      set.add( value );
    }
    long[] dedupedExpected = new long[set.size()];
    Iterator<Long> itr = set.iterator();
    for ( int j = 0; j < dedupedExpected.length; j++ )
    {
      assertTrue( itr.hasNext() );
      dedupedExpected[j] = itr.next();
    }
    assertArrayEquals( dedupedExpected, dedupedActual );
  }
}

代码示例来源: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 LongSortedAction() {
  super(s -> s.sorted(), LongStream.class, SORTED);
}

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

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

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

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

代码示例来源:origin: apache/jackrabbit-oak

@Override
public long getOldestCheckpointCreationTimestamp() {
  return StreamSupport.stream(store.checkpoints().spliterator(), false)
      .map(store::allCheckpointInfo)
      .map(i -> i.get(CHECKPOINT_METADATA + "created"))
      .mapToLong(l -> l == null ? 0 : Long.valueOf(l))
      .sorted()
      .findFirst()
      .orElse(0);
}

代码示例来源:origin: automatictester/lightning

public long firstTransactionTimestamp() {
  return entries.stream()
      .mapToLong(e -> Long.parseLong(e[TRANSACTION_TIMESTAMP.getColumn()]))
      .sorted()
      .limit(1)
      .findFirst()
      .getAsLong();
}

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

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

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

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

代码示例来源:origin: com.simiacryptus/mindseye-test

/**
 * Shuffle int stream.
 *
 * @param stream the stream
 * @return the int stream
 */
public static IntStream shuffle(@Nonnull IntStream stream) {
 // http://primes.utm.edu/lists/small/10000.txt
 long coprimeA = 41387;
 long coprimeB = 9967;
 long ringSize = coprimeA * coprimeB - 1;
 @Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize;
 @Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize);
 @Nonnull IntUnaryOperator conditions = x -> {
  assert x < ringSize;
  assert x >= 0;
  return x;
 };
 return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv);
}

代码示例来源:origin: com.simiacryptus/mindseye

/**
 * Shuffle int stream.
 *
 * @param stream the stream
 * @return the int stream
 */
public static IntStream shuffle(@Nonnull IntStream stream) {
 // http://primes.utm.edu/lists/small/10000.txt
 long coprimeA = 41387;
 long coprimeB = 9967;
 long ringSize = coprimeA * coprimeB - 1;
 @Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize;
 @Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize);
 @Nonnull IntUnaryOperator conditions = x -> {
  assert x < ringSize;
  assert x >= 0;
  return x;
 };
 return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv);
}

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

/**
 * Returns a stream consisting of the elements of this stream in reverse
 * sorted order. The elements are compared for equality according to
 * {@link java.lang.Double#compare(double, double)}.
 *
 * <p>
 * This is a stateful intermediate operation.
 *
 * @return the new stream
 * @since 0.0.8
 */
public DoubleStreamEx reverseSorted() {
  return new DoubleStreamEx(stream().mapToLong(d -> {
    long l = Double.doubleToRawLongBits(d);
    return l ^ (((l >>> 63) - 1) | Long.MIN_VALUE);
  }).sorted().mapToDouble(l -> Double.longBitsToDouble(l ^ ((-(l >>> 63)) | Long.MIN_VALUE))), context);
}

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

/**
 * Returns a stream consisting of the elements of this stream in reverse
 * sorted order.
 *
 * <p>
 * This is a stateful intermediate operation.
 *
 * @return the new stream
 * @since 0.0.8
 */
public LongStreamEx reverseSorted() {
  LongUnaryOperator inv = x -> ~x;
  return new LongStreamEx(stream().map(inv).sorted().map(inv), context);
}

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

private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs)
{
  // aggregate level
  assertAggregation(function,
      QDIGEST_EQUALITY,
      "test multiple positions",
      page,
      getExpectedValueLongs(maxError, inputs));
  // test scalars
  List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
  SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
  assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}

代码示例来源:origin: io.prestosql/presto-main

private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs)
{
  // aggregate level
  assertAggregation(function,
      QDIGEST_EQUALITY,
      "test multiple positions",
      page,
      getExpectedValueLongs(maxError, inputs));
  // test scalars
  List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
  SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
  assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}

相关文章

微信公众号

最新文章

更多