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

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

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

IntStream.boxed介绍

[英]Returns a Stream consisting of the elements of this stream, each boxed to an Integer.

This is an intermediate operation.
[中]返回由此流的元素组成的流,每个元素都被装箱为整数。
这是一个intermediate operation

代码示例

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

private List<Integer> rangeList(int endExclusive)
{
  return IntStream.range(0, endExclusive)
      .boxed()
      .collect(toImmutableList());
}

代码示例来源:origin: shekhargulati/99-problems

public static List<Integer> range(int start, int end) {
    return IntStream.rangeClosed(start, end).boxed().collect(toList());
  }
}

代码示例来源:origin: spotify/helios

public PortAllocator(final int start, final int end) {
 this.potentialPorts = IntStream.range(start, end)
   .boxed()
   .collect(Collectors.toList());
 Collections.shuffle(this.potentialPorts);
}

代码示例来源:origin: org.infinispan/infinispan-core

private void testIntOperation(Supplier<Integer> intSupplier, Cache<Integer, String> cache) {
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 assertEquals((range - 1) * (range / 2), intSupplier.get().intValue());
}

代码示例来源:origin: shekhargulati/99-problems

public static List<Integer> primeNumbers(IntStream range) {
  return range.filter(P31::isPrime).boxed().collect(Collectors.toList());
}

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

private Optional<ScmInfo> generateScmInfoForAllFile(Component file) {
 if (file.getFileAttributes().getLines() == 0) {
  return Optional.empty();
 }
 Set<Integer> newOrChangedLines = IntStream.rangeClosed(1, file.getFileAttributes().getLines()).boxed().collect(Collectors.toSet());
 return Optional.of(GeneratedScmInfo.create(analysisMetadata.getAnalysisDate(), newOrChangedLines));
}

代码示例来源:origin: confluentinc/ksql

private static boolean checkParamsMatch(final List<FunctionParameter> functionArgTypes,
                    final List<Schema> suppliedParamTypes) {
 if (functionArgTypes.size() != suppliedParamTypes.size()) {
  return false;
 }
 return IntStream.range(0, suppliedParamTypes.size())
   .boxed()
   .allMatch(idx -> functionArgTypes.get(idx).matches(suppliedParamTypes.get(idx)));
}

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

/**
 * Creates list of trees.
 *
 * @param treesQueue Trees queue.
 * @return List of trees.
 */
protected ArrayList<TreeRoot> initTrees(Queue<TreeNode> treesQueue) {
  assert featuresPerTree > 0;
  ArrayList<TreeRoot> roots = new ArrayList<>();
  List<Integer> allFeatureIds = IntStream.range(0, meta.size()).boxed().collect(Collectors.toList());
  for (TreeNode node : treesQueue) {
    Collections.shuffle(allFeatureIds, random);
    Set<Integer> featuresSubspace = allFeatureIds.stream()
      .limit(featuresPerTree).collect(Collectors.toSet());
    roots.add(new TreeRoot(node, featuresSubspace));
  }
  return roots;
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testKeyFilter() {
   Cache<Integer, String> cache = getCache(0);
   int range = 12;
   // First populate the cache with a bunch of values
   IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));

   assertEquals(range, cache.size());
   CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();

   Set<Integer> keys = IntStream.of(2, 5, 8, 3, 1, range + 2).boxed().collect(Collectors.toSet());
   assertEquals(keys.size() - 1, createStream(entrySet).filterKeys(keys).count());
  }
}

代码示例来源:origin: cbeust/testng

public static List<Integer> asList(int... ints) {
  return Arrays.stream(ints).boxed().collect(Collectors.toList());
 }
}

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

private List<Integer> rangeList(int endExclusive)
{
  return IntStream.range(0, endExclusive)
      .boxed()
      .collect(toImmutableList());
}

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

@Test
public void testArrayShuffle()
{
  List<Integer> expected = IntStream.rangeClosed(1, 500).boxed().collect(toList());
  Set<List<Integer>> distinctResults = new HashSet<>();
  distinctResults.add(expected);
  for (int i = 0; i < 3; i++) {
    MaterializedResult results = computeActual(format("SELECT shuffle(ARRAY %s) FROM orders LIMIT 10", expected));
    List<MaterializedRow> rows = results.getMaterializedRows();
    assertEquals(rows.size(), 10);
    for (MaterializedRow row : rows) {
      List<Integer> actual = (List<Integer>) row.getField(0);
      // check if the result is a correct permutation
      assertEqualsIgnoreOrder(actual, expected);
      distinctResults.add(actual);
    }
  }
  assertTrue(distinctResults.size() >= 24, "shuffle must produce at least 24 distinct results");
}

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

private static ScmInfo convertToScmInfo(ScannerReport.Changesets changesets) {
 return new ScmInfoImpl(IntStream.rangeClosed(1, changesets.getChangesetIndexByLineCount())
  .boxed()
  .collect(Collectors.toMap(x -> x, new LineIndexToChangeset(changesets), MoreCollectors.mergeNotSupportedMerger(), LinkedHashMap::new)));
}

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

@Override
protected Stream<String> getQueryResourcePaths()
{
  return IntStream.range(1, 100)
      .boxed()
      .flatMap(i -> {
        String queryId = format("q%02d", i);
        if (i == 14 || i == 23 || i == 24 || i == 39) {
          return Stream.of(queryId + "_1", queryId + "_2");
        }
        return Stream.of(queryId);
      })
      .map(queryId -> format("/sql/presto/tpcds/%s.sql", queryId));
}

代码示例来源:origin: oracle/helidon

@Override
public ConfigValue<List<Config>> asNodeList() throws ConfigMappingException {
  return ConfigValues.create(this,
                () -> Optional.of(
                    IntStream.range(0, node().size())
                        .boxed()
                        .map(index -> get(Integer.toString(index)))
                        .collect(Collectors.toList())),
                Config::asNodeList);
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testObjMin() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 assertEquals(Integer.valueOf(0),
    createStream(entrySet).min((e1, e2) -> Integer.compare(e1.getKey(), e2.getKey())).get().getKey());
}

代码示例来源:origin: CalebFenton/simplify

private List<Integer> getValidAddresses() {
  return IntStream.of(manipulator.getAddresses()).boxed().filter(this::canConstantizeAddress)
          .collect(Collectors.toList());
}

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

private static List<Integer> rangeList(int endExclusive)
{
  return IntStream.range(0, endExclusive)
      .boxed()
      .collect(toImmutableList());
}

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

@Test
public void testAllArities()
{
  for (int arity = MIN_ARITY; arity <= MAX_ARITY; arity++) {
    String[] arguments = IntStream.rangeClosed(1, arity)
        .mapToObj(index -> "ARRAY[" + index + "]")
        .toArray(String[]::new);
    Type[] types = IntStream.rangeClosed(1, arity)
        .mapToObj(index -> INTEGER)
        .toArray(Type[]::new);
    assertFunction(
        format("zip(%s)", join(", ", list(arguments))),
        zipReturnType(types),
        list(IntStream.rangeClosed(1, arity).boxed().collect(toList())));
  }
}

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

public ScmInfoRepositoryRule setScmInfo(int fileRef, Changeset... changesetList) {
 Map<Integer, Changeset> changeset = IntStream.rangeClosed(1, changesetList.length).boxed().collect(Collectors.toMap(x -> x, x -> changesetList[x - 1]));
 scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changeset));
 return this;
}

相关文章

微信公众号

最新文章

更多