forEach ( )源码实例Demo ( )源码实例Demo

下面列出了 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: buck   文件:
 * Creates a {@link NewCellPathResolver} from the root cell's path and config. We currently
 * require that all cells appear in the root cell's config.
public static NewCellPathResolver create(AbsPath rootPath, Config rootConfig) {
  // TODO(cjhopman): We should support cells that the root cell doesn't know about. To do that, we
  // should probably continue to compute this mapping first (because that's hardest to get wrong).
  // It would require here that we be able to traverse all the other cells in the build and look
  // at their buckconfigs. We could construct canonical names for newly discovered cells by adding
  // a namespacing of some sort (i.e. secondary#tertiary).
  ImmutableSortedMap<String, AbsPath> cellMapping = getCellMapping(rootPath, rootConfig);

  Map<AbsPath, CanonicalCellName> canonicalNameMap = new LinkedHashMap<>();

  canonicalNameMap.put(rootPath, CanonicalCellName.rootCell());
      (name, path) ->
              path, ignored -> CanonicalCellName.of(Optional.of(name))));

  return DefaultNewCellPathResolver.of(ImmutableMap.copyOf(canonicalNameMap));
源代码2 项目: netcdf-java   文件:
private void printHeaders(String title, ImmutableSortedMap<String, ImmutableList<HttpNameValue>> headers) {
  headers.forEach((key, value) -> {
    Formatter f = new Formatter();
    value.forEach(nv -> {
      if (nv.getValue() == null) {
        f.format("%s ", nv.getName());
      } else {
        f.format("%s=%s ", nv.getName(), nv.getValue());
    appendLine(String.format("  %s: %s", key, f.toString()));
源代码3 项目: bazel   文件:
 * We expand the rule's variables with the following assumptions: Rule variables can refer to
 * target's variables (and file variables). Interdependence between rule variables can happen
 * only for 'command' variable, for now we ignore other possible dependencies between rule
 * variables (seems the only other variable which can meaningfully depend on sibling variables
 * is description, and currently we are ignoring it).
 * <p>Also, for resolving rule's variables we are using scope+offset of target, according to
 * specification (
 * <p>See {@link NinjaRuleVariable} for the list.
private static ImmutableSortedMap<NinjaRuleVariable, NinjaVariableValue> reduceRuleVariables(
    NinjaScope targetScope,
    long targetOffset,
    Map<NinjaRuleVariable, NinjaVariableValue> ruleVariables,
    ImmutableSortedMap<String, String> targetVariables,
    Interner<String> interner) {
  ImmutableSortedMap.Builder<String, List<Pair<Long, String>>> variablesBuilder =
      (key, value) -> variablesBuilder.put(key, ImmutableList.of(Pair.of(0L, value))));
  NinjaScope scopeWithVariables =

  ImmutableSortedMap.Builder<NinjaRuleVariable, NinjaVariableValue> builder =

  // Description is taken from the "build" statement (instead of the referenced rule)
  // if it's available.
  boolean targetHasDescription = false;
  String targetVariable = targetVariables.get("description");
  if (targetVariable != null) {
        NinjaRuleVariable.DESCRIPTION, NinjaVariableValue.createPlainText(targetVariable));
    targetHasDescription = true;

  for (Map.Entry<NinjaRuleVariable, NinjaVariableValue> entry : ruleVariables.entrySet()) {
    NinjaRuleVariable type = entry.getKey();
    if (type.equals(NinjaRuleVariable.DESCRIPTION) && targetHasDescription) {
      // Don't use the rule description, as the target defined a specific description.
    NinjaVariableValue reducedValue =
            targetOffset, entry.getValue(), INPUTS_OUTPUTS_VARIABLES, interner);
    builder.put(type, reducedValue);
源代码4 项目: buck   文件:
/** Creates a {@link CellNameResolver} for a cell. */
public static CellNameResolver createCellNameResolver(
    AbsPath cellPath, Config config, NewCellPathResolver cellPathResolver) {
  ImmutableSortedMap<String, AbsPath> cellMapping = getCellMapping(cellPath, config);

  Map<Optional<String>, CanonicalCellName> builder = new LinkedHashMap<>();
  builder.put(Optional.empty(), cellPathResolver.getCanonicalCellName(cellPath.getPath()));
      (name, path) ->
          builder.put(Optional.of(name), cellPathResolver.getCanonicalCellName(path.getPath())));
  return DefaultCellNameResolver.of(builder);