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

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

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

IntStream.distinct介绍

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

This is a stateful intermediate operation.
[中]

代码示例

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

public IntDistinctAction() {
  super(s -> s.distinct(), IntStream.class, DISTINCT);
}

代码示例来源:origin: biezhi/30-seconds-of-java8

/**
 * Returns all the distinct values of an array.
 *
 * @param elements ints
 * @return distinct values
 */
public static int[] distinctValuesOfArray(int[] elements) {
  return Arrays.stream(elements).distinct().toArray();
}

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

private int[] propertyKeyIds()
{
  return populations.stream().flatMapToInt( this::propertyKeyIds ).distinct().toArray();
}

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

private static void assertValidDescriptor( SchemaDescriptor descriptor, SchemaKernelException.OperationContext context )
    throws RepeatedPropertyInCompositeSchemaException
{
  int numUnique = Arrays.stream( descriptor.getPropertyIds() ).distinct().toArray().length;
  if ( numUnique != descriptor.getPropertyIds().length )
  {
    throw new RepeatedPropertyInCompositeSchemaException( descriptor, context );
  }
}

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

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

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

public static long countUniqueCharacters(String input) {
  return input.chars()
      .distinct()
      .count();
}

代码示例来源: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: prestodb/presto

.distinct()
.count() == 1);

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

.distinct()
.limit(numberOfUsers)
.toArray();

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

for ( int i = 0; i < nodeCount; i++ )
  Label[] nodeLabels = rng.ints( rng.nextInt( labels.length ), 0, labels.length ).distinct().mapToObj( x -> labels[x] ).toArray( Label[]::new );
  Node node = db.createNode( nodeLabels );
  Stream.of( propertyKeys ).forEach( p -> node.setProperty( p, rng.nextBoolean() ? p : randomValues.nextValue().asObject() ) );
  nodes.add( node );
  int localRelCount = Math.min( nodes.size(), 5 );
  rng.ints( localRelCount, 0, localRelCount ).distinct().mapToObj(
      x -> node.createRelationshipTo( nodes.get( x ), relTypes[rng.nextInt( relTypes.length )] ) ).forEach(
      r -> Stream.of( propertyKeys ).forEach( p -> r.setProperty( p, rng.nextBoolean() ? p : randomValues.nextValue().asObject() ) ) );

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

/**
 * Test with large user attributes on random nodes.
 * Also tests that big messages (more than 1MB) properly separated and processed by zk.
 *
 * @throws Exception If failed.
 */
@Test
public void testLargeUserAttribute3() throws Exception {
  Set<Integer> idxs = ThreadLocalRandom.current()
    .ints(0, 10)
    .distinct()
    .limit(3)
    .boxed()
    .collect(Collectors.toSet());
  for (int i = 0; i < 10; i++) {
    info("Iteration: " + i);
    if (idxs.contains(i))
      initLargeAttribute();
    else
      userAttrs = null;
    helper.clientMode(i > 5);
    startGrid(i);
  }
  waitForTopology(10);
}

代码示例来源:origin: shekhargulati/30-seconds-of-java

/**
 * Returns all the distinct values of an array.
 *
 * @param elements ints
 * @return distinct values
 */
public static int[] distinctValuesOfArray(int[] elements) {
  return Arrays.stream(elements).distinct().toArray();
}

代码示例来源:origin: google/bundletool

public CsvFormatter build() {
  CsvFormatter result = autoBuild();
  ImmutableList.Builder<ImmutableList<String>> allRows = ImmutableList.builder();
  result.getHeader().ifPresent(allRows::add);
  allRows.addAll(result.getRows());
  checkState(
    allRows.build().stream().mapToInt(Collection::size).distinct().count() <= 1,
    "All rows must have the same size.");
  return result;
 }
}

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

final int[] ints = new Random().ints(1, 50).distinct().limit(6).toArray();

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

ThreadLocalRandom.current().ints(0, 100).distinct().limit(5).forEach(System.out::println);

代码示例来源:origin: palantir/atlasdb

public Set<Cell> getCellsRequest(int numberOfCellsToRequest) {
  Preconditions.checkState(getNumRows() >= numberOfCellsToRequest,
      "Unable to request %s rows from a table that only has %s rows.",
      numberOfCellsToRequest, getNumRows());
  return getRandom()
      .ints(0, getNumRows())
      .distinct()
      .limit(numberOfCellsToRequest)
      .mapToObj(ConsecutiveNarrowTable::cell)
      .collect(Collectors.toSet());
}

代码示例来源:origin: BruceEckel/OnJava8-Examples

public Stream<Pair> stream() {
  return rand.ints(100, 1000).distinct()
   .mapToObj(i -> new Pair(capChars.next(), i));
 }
}

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

new Random().ints(0, 50)
     .distinct()
     .limit(5)
     .parallel()
     .forEach(d -> System.out.println("s: " + d));

代码示例来源:origin: numenta/htm.java

/**
 * Converts a Set of {@link Cell}s to {@link Column} indexes.
 * 
 * @param cells             the list of cells to convert
 * @param cellsPerColumn    the defined number of cells per column  
 * 
 * @return  the column indexes of the specified cells.
 */
public static int[] cellsAsColumnIndices(Set<Cell> cells, int cellsPerColumn) {
  return cells.stream().mapToInt(c -> c.getIndex())
        .sorted().map(cellIdx -> cellIdx / cellsPerColumn).distinct().toArray();
}

代码示例来源:origin: org.neo4j/neo4j-kernel

private static void assertValidDescriptor( SchemaDescriptor descriptor, SchemaKernelException.OperationContext context )
    throws RepeatedPropertyInCompositeSchemaException
{
  int numUnique = Arrays.stream( descriptor.getPropertyIds() ).distinct().toArray().length;
  if ( numUnique != descriptor.getPropertyIds().length )
  {
    throw new RepeatedPropertyInCompositeSchemaException( descriptor, context );
  }
}

相关文章

微信公众号

最新文章

更多