forEach ( )源码实例Demo

com.google.common.collect.ImmutableSortedMap#forEach ( )源码实例Demo

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

源代码1 项目: buck   文件: CellMappingsFactory.java
/**
 * 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());
  cellMapping.forEach(
      (name, path) ->
          canonicalNameMap.computeIfAbsent(
              path, ignored -> CanonicalCellName.of(Optional.of(name))));

  return DefaultNewCellPathResolver.of(ImmutableMap.copyOf(canonicalNameMap));
}
 
源代码2 项目: netcdf-java   文件: URLDumpPane.java
private void printHeaders(String title, ImmutableSortedMap<String, ImmutableList<HttpNameValue>> headers) {
  appendLine(title);
  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   文件: NinjaTarget.java
/**
 * 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 (https://ninja-build.org/manual.html#_variable_expansion).
 *
 * <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 =
      ImmutableSortedMap.naturalOrder();
  targetVariables.forEach(
      (key, value) -> variablesBuilder.put(key, ImmutableList.of(Pair.of(0L, value))));
  NinjaScope scopeWithVariables =
      targetScope.createScopeFromExpandedValues(variablesBuilder.build());

  ImmutableSortedMap.Builder<NinjaRuleVariable, NinjaVariableValue> builder =
      ImmutableSortedMap.naturalOrder();

  // 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) {
    builder.put(
        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.
      continue;
    }
    NinjaVariableValue reducedValue =
        scopeWithVariables.getReducedValue(
            targetOffset, entry.getValue(), INPUTS_OUTPUTS_VARIABLES, interner);
    builder.put(type, reducedValue);
  }
  return builder.build();
}
 
源代码4 项目: buck   文件: CellMappingsFactory.java
/** 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()));
  cellMapping.forEach(
      (name, path) ->
          builder.put(Optional.of(name), cellPathResolver.getCanonicalCellName(path.getPath())));
  return DefaultCellNameResolver.of(builder);
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。