java.util.Iterator.forEachRemaining()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(134)

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

Iterator.forEachRemaining介绍

[英]Performs the given action for each remaining element until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.
[中]

代码示例

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

@Override
public void forEachRemaining(Consumer<? super E> action) {
  delegate.forEachRemaining(action);
}

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

void forEachEntry(Consumer<? super Entry<K, V>> action) {
 entryIterator().forEachRemaining(action);
}

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

@Override
public List<Tuple> get() {
  List<Tuple> tuples = new ArrayList<>();
  tuplesIt.get().forEachRemaining(t -> tuples.add(t));
  return tuples;
}

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

public void testForEachRemaining() {
 for (int i = 0; i < expectedElements.size() - 1; i++) {
  List<E> targetElements = new ArrayList<E>();
  Iterator<E> iterator = newTargetIterator();
  for (int j = 0; j < i; j++) {
   targetElements.add(iterator.next());
  }
  iterator.forEachRemaining(targetElements::add);
  if (knownOrder == KnownOrder.KNOWN_ORDER) {
   assertEquals(expectedElements, targetElements);
  } else {
   Helpers.assertEqualIgnoringOrder(expectedElements, targetElements);
  }
 }
}

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

void forEachEntry(Consumer<? super Entry<K, V>> action) {
 entryIterator().forEachRemaining(action);
}

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

private Map<String, JsonNode> parseAsJson(byte[] value) throws IOException {
 JsonNode document = mapper.readValue(value, JsonNode.class);
 //Hive Column names are case insensitive.
 Map<String, JsonNode> documentMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
 document.fields().forEachRemaining(field -> documentMap.put(field.getKey().toLowerCase(), field.getValue()));
 return documentMap;
}

代码示例来源:origin: google/data-transfer-project

public static CloudExtension getCloudExtension() {
 ImmutableList.Builder<CloudExtension> extensionsBuilder = ImmutableList.builder();
 ServiceLoader.load(CloudExtension.class).iterator().forEachRemaining(extensionsBuilder::add);
 ImmutableList<CloudExtension> extensions = extensionsBuilder.build();
 Preconditions.checkState(
   extensions.size() == 1,
   "Exactly one CloudExtension is required, but found " + extensions.size());
 return extensions.get(0);
}

代码示例来源:origin: google/data-transfer-project

public static SettingsExtension getSettingsExtension() {
 ImmutableList.Builder<SettingsExtension> extensionsBuilder = ImmutableList.builder();
 ServiceLoader.load(SettingsExtension.class).iterator().forEachRemaining(extensionsBuilder::add);
 ImmutableList<SettingsExtension> extensions = extensionsBuilder.build();
 Preconditions.checkState(
   extensions.size() == 1,
   "Exactly one SettingsExtension is required, but found " + extensions.size());
 return extensions.get(0);
}

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

@Override
public void verifyDeferredConstraints( NodePropertyAccessor accessor ) throws IndexEntryConflictException, IOException
{
  // If we've seen constraint violation failures in here when updates came in then fail immediately with those
  if ( !failures.isEmpty() )
  {
    Iterator<IndexEntryConflictException> failureIterator = failures.iterator();
    IndexEntryConflictException conflict = failureIterator.next();
    failureIterator.forEachRemaining( conflict::addSuppressed );
    throw conflict;
  }
  // Otherwise consolidate the usual verification
  super.verifyDeferredConstraints( accessor );
}

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

@Override
public Map<String, String> toSingleValueMap() {
  Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
  Iterator<HttpField> iterator = this.headers.iterator();
  iterator.forEachRemaining(field -> {
    if (!singleValueMap.containsKey(field.getName())) {
      singleValueMap.put(field.getName(), field.getValue());
    }
  });
  return singleValueMap;
}

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

private Map<String, String> getLinks() {
  Iterable<ClientRegistration> registrations = getBeanOrNull(ResolvableType.forClassWithGenerics(Iterable.class, ClientRegistration.class));
  if (registrations == null) {
    return Collections.emptyMap();
  }
  Map<String, String> result = new HashMap<>();
  registrations.iterator().forEachRemaining(r -> {
    result.put("/oauth2/authorization/" + r.getRegistrationId(), r.getClientName());
  });
  return result;
}

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

private Geometry lineStringFromEdges(List<Label.Transition> transitions) {
  List<Coordinate> coordinates = new ArrayList<>();
  final Iterator<Label.Transition> iterator = transitions.iterator();
  iterator.next();
  coordinates.addAll(toCoordinateArray(iterator.next().edge.edgeIteratorState.fetchWayGeometry(3)));
  iterator.forEachRemaining(transition -> coordinates.addAll(toCoordinateArray(transition.edge.edgeIteratorState.fetchWayGeometry(2))));
  return geometryFactory.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}

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

private static List<Map<String,Object>> nodeCounts( TokenRead tokens, Read read, Anonymizer anonymizer )
{
  List<Map<String,Object>> nodeCounts = new ArrayList<>();
  Map<String,Object> nodeCount = new HashMap<>();
  nodeCount.put( "count", read.countsForNodeWithoutTxState( -1 ) );
  nodeCounts.add( nodeCount );
  tokens.labelsGetAllTokens().forEachRemaining( t -> {
    long count = read.countsForNodeWithoutTxState( t.id() );
    Map<String,Object> labelCount = new HashMap<>();
    labelCount.put( "label", anonymizer.label( t.name(), t.id() ) );
    labelCount.put( "count", count );
    nodeCounts.add( labelCount );
  } );
  return nodeCounts;
}

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

static Stream<RetrieveResult> retrieve( Kernel kernel ) throws TransactionFailureException
{
  try ( Transaction tx = kernel.beginTransaction( Transaction.Type.explicit, LoginContext.AUTH_DISABLED ) )
  {
    TokenRead tokens = tx.tokenRead();
    List<String> labels = new ArrayList<>( tokens.labelCount() );
    tokens.labelsGetAllTokens().forEachRemaining( t -> labels.add( t.name() ) );
    List<String> relationshipTypes = new ArrayList<>( tokens.relationshipTypeCount() );
    tokens.relationshipTypesGetAllTokens().forEachRemaining( t -> relationshipTypes.add( t.name() ) );
    List<String> propertyKeys = new ArrayList<>( tokens.propertyKeyCount() );
    tokens.propertyKeyGetAllTokens().forEachRemaining( t -> propertyKeys.add( t.name() ) );
    Map<String,Object> data = new HashMap<>();
    data.put( "labels", labels );
    data.put( "relationshipTypes", relationshipTypes );
    data.put( "propertyKeys", propertyKeys );
    return Stream.of( new RetrieveResult( Sections.TOKENS, data ) );
  }
}

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

@Override
  public void evaluateFinal(BlockBuilder blockBuilder)
  {
    pagesIndex.sort(orderByChannels, orderings);
    Iterator<Page> pagesIterator = pagesIndex.getSortedPages();
    pagesIterator.forEachRemaining(accumulator::addInput);
    accumulator.evaluateFinal(blockBuilder);
  }
}

代码示例来源:origin: org.springframework/spring-web

@Override
public Map<String, String> toSingleValueMap() {
  Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
  Iterator<HttpField> iterator = this.headers.iterator();
  iterator.forEachRemaining(field -> {
    if (!singleValueMap.containsKey(field.getName())) {
      singleValueMap.put(field.getName(), field.getValue());
    }
  });
  return singleValueMap;
}

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

public void setPinotFSFactoryClasses(Configuration pinotFSFactoryClasses) {
 setProperty(PINOT_FS_FACTORY_CLASS_LOCAL, DEFAULT_PINOT_FS_FACTORY_CLASS_LOCAL);
 if (pinotFSFactoryClasses != null) {
  pinotFSFactoryClasses.getKeys()
    .forEachRemaining(key -> setProperty((String) key, pinotFSFactoryClasses.getProperty((String) key)));
 }
}

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

@Override
  public void prepareFinal()
  {
    pagesIndex.sort(orderByChannels, orderings);
    Iterator<Page> pagesIterator = pagesIndex.getSortedPages();
    pagesIterator.forEachRemaining(page -> {
      // The last channel of the page is the group id
      GroupByIdBlock groupIds = new GroupByIdBlock(groupCount, page.getBlock(page.getChannelCount() - 1));
      // We pass group id together with the other input channels to accumulator. Accumulator knows which input channels
      // to use. Since we did not change the order of original input channels, passing the group id is safe.
      accumulator.addInput(groupIds, page);
    });
  }
}

代码示例来源:origin: Graylog2/graylog2-server

private IndexerOverview getIndexerOverview(IndexSet indexSet) throws TooManyAliasesException {
  final String indexSetId = indexSet.getConfig().id();
  final DeflectorSummary deflectorSummary = deflectorResource.deflector(indexSetId);
  final List<IndexRangeSummary> indexRanges = indexRangesResource.list().ranges();
  final JsonNode indexStats = indices.getIndexStats(indexSet);
  final List<String> indexNames = new ArrayList<>();
  indexStats.fieldNames().forEachRemaining(indexNames::add);
  final Map<String, Boolean> areReopened = indices.areReopened(indexNames);
  final Map<String, IndexSummary> indicesSummaries = buildIndexSummaries(deflectorSummary, indexSet, indexRanges, indexStats, areReopened);
  return IndexerOverview.create(deflectorSummary,
      IndexerClusterOverview.create(indexerClusterResource.clusterHealth(), indexerClusterResource.clusterName().name()),
      countResource.total(indexSetId), indicesSummaries);
}

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

@Test
public void testProcessingTimeWithWindow() throws Exception {
  StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
  env.setParallelism(1);
  DataStream<Integer> input = env.fromElements(1, 2);
  Pattern<Integer, ?> pattern = Pattern.<Integer>begin("start").followedByAny("end").within(Time.days(1));
  DataStream<Integer> result = CEP.pattern(input, pattern).select(new PatternSelectFunction<Integer, Integer>() {
    @Override
    public Integer select(Map<String, List<Integer>> pattern) throws Exception {
      return pattern.get("start").get(0) + pattern.get("end").get(0);
    }
  });
  List<Integer> resultList = new ArrayList<>();
  DataStreamUtils.collect(result).forEachRemaining(resultList::add);
  assertEquals(Arrays.asList(3), resultList);
}

相关文章