java.util.Collection.forEach()方法的使用及代码示例

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

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

Collection.forEach介绍

暂无

代码示例

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

@Override
public void stop() {
  this.beanCache.values().forEach(SpringContainedBean::destroyIfNecessary);
  this.beanCache.clear();
}

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

public Collection<ServerHolder> getAllServers()
{
 final int historicalSize = historicals.values().stream().mapToInt(Collection::size).sum();
 final int realtimeSize = realtimes.size();
 final List<ServerHolder> allServers = new ArrayList<>(historicalSize + realtimeSize);
 historicals.values().forEach(allServers::addAll);
 allServers.addAll(realtimes);
 return allServers;
}

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

private static Collection<Object> convertFutureToResult(final Collection<Future> futures) {
  List<Object> results = new LinkedList<Object>();
  futures.forEach(future -> {
   try {
    results.add(future.get());
   } catch (Exception e) {
    results.add(e);
   }
  });
  return results;
 }
}

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

public static List<Section> order(Collection<Section> sections, String... orderedNames) {
  Map<String, Section> alphabeticalOrderedMap = new TreeMap<>();
  sections.forEach(section -> alphabeticalOrderedMap.put(section.getName(), section));

  List<Section> result = new ArrayList<>(sections.size());
  stream(orderedNames).forEach(name -> {
   Section section = alphabeticalOrderedMap.remove(name);
   if (section != null) {
    result.add(section);
   }
  });
  result.addAll(alphabeticalOrderedMap.values());
  return result;
 }
}

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

public DefaultAsyncDistributedLog(String name, LogClient client, Serializer serializer) {
 this.name = checkNotNull(name);
 this.client = checkNotNull(client);
 this.serializer = checkNotNull(serializer);
 client.getPartitions().forEach(partition -> {
  DefaultAsyncDistributedLogPartition<E> logPartition = new DefaultAsyncDistributedLogPartition<>(this, partition, serializer);
  partitions.put(partition.partitionId().id(), logPartition);
  sortedPartitions.add(logPartition);
 });
}

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

private List<Entry> buildTree(Map<Long, Entry> procMap) {
 List<Entry> rootEntries = new ArrayList<>();
 procMap.values().forEach(entry -> {
  if (!entry.proc.hasParentId()) {
   rootEntries.add(entry);
  } else {
   Entry parentEntry = procMap.get(entry.proc.getParentId());
   // For a valid procedure this should not be null. We will log the error later if it is null,
   // as it will not be referenced by any root procedures.
   if (parentEntry != null) {
    parentEntry.subProcs.add(entry);
   }
  }
 });
 return rootEntries;
}

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

private Set(Collection<Field> fields) {
  Map<String, Field> all = new LinkedHashMap<>();
  fields.forEach(field -> {
    if (field != null) {
      all.put(field.name(), field);
    }
  });
  this.fieldsByName = Collections.unmodifiableMap(all);
}

代码示例来源:origin: alibaba/canal

private void addConfigToCache(File file, ESSyncConfig config) {
  esAdapter.getEsSyncConfig().put(file.getName(), config);
  SchemaItem schemaItem = SqlParser.parse(config.getEsMapping().getSql());
  config.getEsMapping().setSchemaItem(schemaItem);
  DruidDataSource dataSource = DatasourceConfig.DATA_SOURCES.get(config.getDataSourceKey());
  if (dataSource == null || dataSource.getUrl() == null) {
    throw new RuntimeException("No data source found: " + config.getDataSourceKey());
  }
  Pattern pattern = Pattern.compile(".*:(.*)://.*/(.*)\\?.*$");
  Matcher matcher = pattern.matcher(dataSource.getUrl());
  if (!matcher.find()) {
    throw new RuntimeException("Not found the schema of jdbc-url: " + config.getDataSourceKey());
  }
  String schema = matcher.group(2);
  schemaItem.getAliasTableItems().values().forEach(tableItem -> {
    Map<String, ESSyncConfig> esSyncConfigMap = esAdapter.getDbTableEsSyncConfig()
      .computeIfAbsent(schema + "-" + tableItem.getTableName(), k -> new HashMap<>());
    esSyncConfigMap.put(file.getName(), config);
  });
}

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

protected <T> Flux<T> doInsertAll(Collection<? extends T> listToSave, MongoWriter<Object> writer) {
  Map<String, List<T>> elementsByCollection = new HashMap<>();
  listToSave.forEach(element -> {
    MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(element.getClass());
    String collection = entity.getCollection();
    List<T> collectionElements = elementsByCollection.computeIfAbsent(collection, k -> new ArrayList<>());
    collectionElements.add(element);
  });
  return Flux.fromIterable(elementsByCollection.keySet())
      .flatMap(collectionName -> doInsertBatch(collectionName, elementsByCollection.get(collectionName), writer));
}

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

public Map<String, Element> getAllParentElmts() {
    Map<String, Element> result = new HashMap<>();

    this.parentElmts.values()
      .forEach(elmt ->
        elmt.subGrps.forEach(
          subElmt -> result.put(subElmt.name, subElmt)));

    result.putAll(this.parentElmts);

    return result;
  }
}

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

private void checkOrphan(Map<Long, Entry> procMap) {
 procMap.values().forEach(entry -> {
  LOG.error("Orphan procedure: {}", entry);
  corruptedProcs.add(new ProtoAndProc(entry.proc));
 });
}

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

private Map<Class, ManagedCommand> createCommandsByType() {
    Map<Class, ManagedCommand> map = new HashMap<>((int) (commands.size() / 0.75));
    commands.values().forEach(mc -> map.put(mc.getCommand().getClass(), mc));
    return map;
  }
}

代码示例来源:origin: alibaba/canal

public void sync(Dml dml) {
  if (dml == null) {
    return;
  }
  String destination = StringUtils.trimToEmpty(dml.getDestination());
  String database = dml.getDatabase();
  String table = dml.getTable();
  Map<String, MappingConfig> configMap = mappingConfigCache.get(destination + "." + database + "." + table);
  if (configMap != null) {
    configMap.values().forEach(config -> hbaseSyncService.sync(config, dml));
  }
}

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

public Set<String> getAllTiers()
 {
  ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();

  druidNodeDiscovery.getAllNodes().forEach(
    node -> builder.add(((LookupNodeService) node.getServices()
                           .get(LookupNodeService.DISCOVERY_SERVICE_KEY)).getLookupTier())
  );

  return builder.build();
 }
}

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

private ModifyableTableDescriptor(final TableName name, final Collection<ColumnFamilyDescriptor> families,
    Map<Bytes, Bytes> values) {
 this.name = name;
 families.forEach(c -> this.families.put(c.getName(), ColumnFamilyDescriptorBuilder.copy(c)));
 this.values.putAll(values);
 this.values.put(IS_META_KEY,
  new Bytes(Bytes.toBytes(Boolean.toString(name.equals(TableName.META_TABLE_NAME)))));
}

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

public PrimaryBackupPartitionGroup(PrimaryBackupPartitionGroupConfig config) {
 this.config = config;
 this.name = checkNotNull(config.getName());
 buildPartitions(config).forEach(p -> {
  this.partitions.put(p.id(), p);
  this.sortedPartitionIds.add(p.id());
 });
 Collections.sort(sortedPartitionIds);
}

代码示例来源:origin: twosigma/beakerx

public void setValues(Collection<String> values) {
 values.forEach(item -> {
  CheckBoxWidget checkbox = new CheckBoxWidget(item);
  checkboxes.add(checkbox);
 });
}

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

void close() {
  if (activeBuckets != null) {
    activeBuckets.values().forEach(Bucket::disposePartFile);
  }
}

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

public DefaultConfigService(Collection<PrimitiveConfig> defaultConfigs, Collection<PrimitiveConfig> configs) {
 defaultConfigs.forEach(config -> this.defaultConfigs.put(((PrimitiveType) config.getType()).name(), config));
 configs.forEach(config -> this.configs.put(config.getName(), config));
}

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

public Map<String, Element> getAllChildElmts() {
  Map<String, Element> result = new HashMap<>();
  this.childElmts.values()
    .forEach(elmt ->
      elmt.subGrps.forEach(
        subElmt -> result.put(subElmt.name, subElmt)));
  result.putAll(this.childElmts);
  return result;
}

相关文章