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

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

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

IntStream.range介绍

[英]Returns a sequential ordered IntStream from startInclusive(inclusive) to endExclusive (exclusive) by an incremental step of 1.
[中]以增量步骤1返回从startInclusive(包含)到endExclusive(独占)的顺序IntStream。

代码示例

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

private String columnDefinitions(List<DataTypeTest.Input<?>> inputs)
  {
    List<String> columnTypeDefinitions = inputs.stream()
        .map(DataTypeTest.Input::getInsertType)
        .collect(toList());
    Stream<String> columnDefinitions = range(0, columnTypeDefinitions.size())
        .mapToObj(i -> format("col_%d %s", i, columnTypeDefinitions.get(i)));
    return Joiner.on(",\n").join(columnDefinitions.iterator());
  }
}

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

protected String formatInvokeError(String text, Object[] args) {
  String formattedArgs = IntStream.range(0, args.length)
      .mapToObj(i -> (args[i] != null ?
          "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" :
          "[" + i + "] [null]"))
      .collect(Collectors.joining(",\n", " ", " "));
  return text + "\n" +
      "Controller [" + getBeanType().getName() + "]\n" +
      "Method [" + getBridgedMethod().toGenericString() + "] " +
      "with argument values:\n" + formattedArgs;
}

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

public NodePartitionMap(List<Node> partitionToNode, ToIntFunction<Split> splitToBucket)
{
  this.partitionToNode = ImmutableList.copyOf(requireNonNull(partitionToNode, "partitionToNode is null"));
  this.bucketToPartition = IntStream.range(0, partitionToNode.size()).toArray();
  this.splitToBucket = requireNonNull(splitToBucket, "splitToBucket is null");
}

代码示例来源:origin: ivan-vasilev/neuralnetworks

@Override
public void getNextTarget(Tensor target)
{
  IntStream stream = IntStream.range(0, currentArrays.size());
  if (properties.getParallelPreprocessing())
  {
    stream = stream.parallel();
  }
  stream.forEach(i -> {
    float[] t = getNextTarget(augmentedToRaw.get(arrayToAugmented.get(currentArrays.get(i))));
    if (t != null)
    {
      System.arraycopy(t, 0, target.getElements(), target.getStartIndex() + i * getTargetDimensions(), t.length);
    }
  });
}

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

public static WorkProcessor<Page> mergeSortedPages(
    List<WorkProcessor<Page>> pageProducers,
    PageWithPositionComparator comparator,
    List<Type> outputTypes,
    AggregatedMemoryContext aggregatedMemoryContext,
    DriverYieldSignal yieldSignal)
{
  return mergeSortedPages(
      pageProducers,
      comparator,
      IntStream.range(0, outputTypes.size()).boxed().collect(toImmutableList()),
      outputTypes,
      (pageBuilder, pageWithPosition) -> pageBuilder.isFull(),
      false,
      aggregatedMemoryContext,
      yieldSignal);
}

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

@Override
protected void print(List<String> warnings)
{
  console.reprintLine("");
  warnings.stream()
      .forEach(console::reprintLine);
  // Remove warnings from previous screen
  range(0, DISPLAYED_WARNINGS - warnings.size())
      .forEach(line -> console.reprintLine(""));
}

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

@Override
public Operator createOperator(DriverContext driverContext)
{
  checkState(!closed, "Factory is already closed");
  LocalExchange localExchange = localExchangeFactory.getLocalExchange(driverContext.getLifespan());
  OperatorContext operatorContext = driverContext.addOperatorContext(operatorId, planNodeId, LocalMergeSourceOperator.class.getSimpleName());
  PageWithPositionComparator comparator = orderingCompiler.compilePageWithPositionComparator(types, sortChannels, orderings);
  List<LocalExchangeSource> sources = IntStream.range(0, localExchange.getBufferCount())
      .boxed()
      .map(index -> localExchange.getNextSource())
      .collect(toImmutableList());
  return new LocalMergeSourceOperator(operatorContext, sources, types, comparator);
}

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

private static List<Type> toTypes(Map<Symbol, Integer> layout, LocalExecutionPlanContext context)
{
  // verify layout covers all values
  int channelCount = layout.values().stream().mapToInt(Integer::intValue).max().orElse(-1) + 1;
  checkArgument(
      layout.size() == channelCount && ImmutableSet.copyOf(layout.values()).containsAll(ContiguousSet.create(closedOpen(0, channelCount), integers())),
      "Layout does not have a symbol for every output channel: %s", layout);
  Map<Integer, Symbol> channelLayout = ImmutableBiMap.copyOf(layout).inverse();
  return range(0, channelCount)
      .mapToObj(channelLayout::get)
      .map(context.getTypes()::get)
      .collect(toImmutableList());
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testFetch() {
 stream.pause();
 assertFalse(stream.emit(IntStream.range(0, 17).boxed()));
 for (int i = 1;i < 17;i++) {
  stream.fetch(1);
  assertEquals(IntStream.range(0, i).boxed().collect(Collectors.toList()), emitted);
  assertEquals(0, drained);
 }
 stream.fetch(1);
 assertEquals(IntStream.range(0, 17).boxed().collect(Collectors.toList()), emitted);
 assertEquals(1, drained);
}

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

public void checkPlanIsDeterministic(Session session, String sql)
{
  IntStream.range(1, MINIMUM_SUBSEQUENT_SAME_PLANS)
      .mapToObj(attempt -> getPlanText(session, sql))
      .map(planEquivalenceFunction)
      .reduce((previous, current) -> {
        assertEquals(previous, current);
        return current;
      });
}

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

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

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

public static void repeatChar(AttributedStringBuilder sb, char c, int count) {
  IntStream.range(0, count).forEach(i -> sb.append(c));
}

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

private static void doParallelCacheOp(int count, IntConsumer consumer) {
 IntStream.range(0, count).parallel().forEach(consumer);
}

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

@Test
public void testAscending()
{
  test(IntStream.range(0, INPUT_SIZE),
      IntStream.range(0, INPUT_SIZE).mapToObj(key -> Integer.toString(key * 2)),
      MAX_ELEMENTS_COMPARATOR,
      IntStream.range(INPUT_SIZE - OUTPUT_SIZE, INPUT_SIZE).mapToObj(key -> Integer.toString(key * 2)).iterator());
  test(IntStream.range(0, INPUT_SIZE),
      IntStream.range(0, INPUT_SIZE).mapToObj(key -> Integer.toString(key * 2)),
      MIN_ELEMENTS_COMPARATOR,
      IntStream.range(0, OUTPUT_SIZE).map(x -> OUTPUT_SIZE - 1 - x).mapToObj(key -> Integer.toString(key * 2)).iterator());
}

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

@Override
public TestTable setupTestTable(List<DataTypeTest.Input<?>> inputs)
{
  List<String> columnValues = inputs.stream()
      .map(this::literalInExplicitCast)
      .collect(toList());
  Stream<String> columnValuesWithNames = range(0, columnValues.size())
      .mapToObj(i -> format("%s col_%d", columnValues.get(i), i));
  String selectBody = Joiner.on(",\n").join(columnValuesWithNames.iterator());
  String ddlTemplate = "CREATE TABLE {TABLE_NAME} AS SELECT\n" + selectBody;
  return new TestTable(sqlExecutor, tableNamePrefix, ddlTemplate);
}

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

/**
 * Computes the bitwise union of the input bitmaps
 * @param bitmaps the input bitmaps
 * @return the union of the bitmaps
 */
public static MutableRoaringBitmap or(ImmutableRoaringBitmap... bitmaps) {
 SortedMap<Short, List<MappeableContainer>> grouped = groupByKey(bitmaps);
 short[] keys = new short[grouped.size()];
 MappeableContainer[] values = new MappeableContainer[grouped.size()];
 List<List<MappeableContainer>> slices = new ArrayList<>(grouped.size());
 int i = 0;
 for (Map.Entry<Short, List<MappeableContainer>> slice : grouped.entrySet()) {
  keys[i++] = slice.getKey();
  slices.add(slice.getValue());
 }
 IntStream.range(0, i)
     .parallel()
     .forEach(position -> values[position] = or(slices.get(position)));
 return new MutableRoaringBitmap(new MutableRoaringArray(keys, values, i));
}

代码示例来源:origin: apache/incubator-druid

private void initializeRankOfDictionaryIds()
{
 final int dictionarySize = dictionary.size();
 rankOfDictionaryIds = IntStream.range(0, dictionarySize).toArray();
 IntArrays.quickSort(
   rankOfDictionaryIds,
   (i1, i2) -> Comparators.<String>naturalNullsFirst().compare(dictionary.get(i1), dictionary.get(i2))
 );
 IntArrayUtils.inverse(rankOfDictionaryIds);
}

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

public GroupByHashPageIndexer(List<? extends Type> hashTypes, JoinCompiler joinCompiler)
{
  this(GroupByHash.createGroupByHash(
      hashTypes,
      IntStream.range(0, hashTypes.size()).toArray(),
      Optional.empty(),
      20,
      false,
      joinCompiler,
      NOOP));
}

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

/**
 * Rows with same hash value are guaranteed to be in the same result page.
 */
public WorkProcessor<Page> merge(List<Type> keyTypes, List<Type> allTypes, List<WorkProcessor<Page>> channels, DriverYieldSignal driverYieldSignal)
{
  InterpretedHashGenerator hashGenerator = createHashGenerator(keyTypes);
  return mergeSortedPages(
      channels,
      createHashPageWithPositionComparator(hashGenerator),
      IntStream.range(0, allTypes.size()).boxed().collect(toImmutableList()),
      allTypes,
      keepSameHashValuesWithinSinglePage(hashGenerator),
      true,
      memoryContext,
      driverYieldSignal);
}

相关文章