Exemplo n.º 1
0
 /** Get the snapshot of union find */
 ImmutableMap<ECR, Collection<IRVar>> snapshot() {
   SetMultimap<Partition, IRVar> map = uf.snapshot();
   ImmutableMap.Builder<ECR, Collection<IRVar>> builder = ImmutableMap.builder();
   for (Partition ecr : map.asMap().keySet()) {
     builder.put(findRoot((ECR) ecr), ImmutableSet.copyOf(map.asMap().get(ecr)));
   }
   return builder.build();
 }
Exemplo n.º 2
0
  /**
   * Returns new or cached instances of PBXBuildFiles corresponding to files that may or may not
   * belong to an aggregate reference (see {@link AggregateReferenceType}). Files specified by the
   * {@code paths} argument are grouped into individual PBXBuildFiles using the given {@link
   * AggregateReferenceType}. Files that are standalone are not put in an aggregate reference, but
   * are put in a standalone PBXBuildFile in the returned sequence.
   */
  public Iterable<PBXBuildFile> get(AggregateReferenceType type, Iterable<Path> paths) {
    ImmutableList.Builder<PBXBuildFile> result = new ImmutableList.Builder<>();
    SetMultimap<AggregateKey, Path> keyedPaths = type.aggregates(paths);
    for (Map.Entry<AggregateKey, Collection<Path>> aggregation : keyedPaths.asMap().entrySet()) {
      if (!aggregation.getKey().isStandalone()) {
        ImmutableSet<Path> itemPaths = ImmutableSet.copyOf(aggregation.getValue());
        result.add(
            aggregateBuildFile(
                itemPaths, type.create(aggregation.getKey(), fileReferences(itemPaths))));
      }
    }
    for (Path generalResource : keyedPaths.get(AggregateKey.standalone())) {
      result.add(getStandalone(FileReference.of(generalResource.toString(), SourceTree.GROUP)));
    }

    return result.build();
  }
  private Map<String, Collection<String>> scanValueRequirementBySecType(
      UniqueId portfolioId, ToolContext toolContext) {
    AvailableOutputsProvider availableOutputsProvider = toolContext.getAvaliableOutputsProvider();
    if (availableOutputsProvider == null) {
      throw new OpenGammaRuntimeException("AvailableOutputsProvider missing from ToolContext");
    }
    final SetMultimap<String, String> valueNamesBySecurityType = TreeMultimap.create();

    AvailableOutputs portfolioOutputs =
        availableOutputsProvider.getPortfolioOutputs(portfolioId, null);
    Set<String> securityTypes = portfolioOutputs.getSecurityTypes();
    for (String securityType : securityTypes) {
      Set<AvailableOutput> positionOutputs = portfolioOutputs.getPositionOutputs(securityType);
      for (AvailableOutput availableOutput : positionOutputs) {
        valueNamesBySecurityType.put(securityType, availableOutput.getValueName());
      }
    }
    return valueNamesBySecurityType.asMap();
  }
Exemplo n.º 4
0
  @VisibleForTesting
  static Pair<String, Dimension> generateSvg(
      String configId,
      SetMultimap<Integer, String> moduleDepths,
      Map<String, List<String>> invertedDependencyTree,
      Map<String, Pair<Integer, Integer>> moduleSizes,
      Map<String, List<JsInput>> moduleToInputs) {
    // Calculate the maximum number of modules that should be displayed at the
    // same depth in the SVG.
    int maxModulesPerRow = -1;
    for (Collection<String> modules : moduleDepths.asMap().values()) {
      maxModulesPerRow = Math.max(maxModulesPerRow, modules.size());
    }

    // Create a rectangle for each of the modules in the graph.
    List<String> rects = Lists.newLinkedList();
    Map<String, Point> boxTops = Maps.newHashMap();
    Map<String, Point> boxBottoms = Maps.newHashMap();
    int fullHeight = -1;
    for (Map.Entry<Integer, Collection<String>> entry : moduleDepths.asMap().entrySet()) {
      int depth = entry.getKey();
      int y = Y_OFFSET + depth * (BOX_HEIGHT + Y_BOX_SPACING);
      fullHeight = Math.max(fullHeight, y + BOX_HEIGHT);
      int numModules = entry.getValue().size();
      int blankSpace = (maxModulesPerRow - numModules) * (BOX_WIDTH + X_BOX_SPACING) / 2;
      int x = blankSpace + X_OFFSET;

      for (String module : entry.getValue()) {
        Pair<Integer, Integer> sizes = moduleSizes.get(module);
        String formattedRawSize = formatSize(sizes.getFirst());
        String formattedGzipSize = formatSize(sizes.getSecond());
        int numFiles = moduleToInputs.get(module).size();
        String fileCount = (numFiles == 1) ? "1 file" : numFiles + " files";
        String moduleListUrl = String.format("/list?id=%s&amp;module=%s", configId, module);
        String rect =
            String.format(
                "<rect id='%s' x='%d' y='%d' width='%d' height='%d'/>"
                    + "<text x='%d' y='%d'>%s</text>"
                    + "<text x='%d' y='%d'>%s (%s gzip)</text>"
                    + "<a xlink:href='%s'>"
                    + "<text class='link' x='%d' y='%d'>%s</text>"
                    + "</a>",
                module,
                x,
                y,
                BOX_WIDTH,
                BOX_HEIGHT,
                x + TEXT_X_OFFSET,
                y + TEXT_Y_OFFSET - LINE_HEIGHT,
                module,
                x + TEXT_X_OFFSET,
                y + TEXT_Y_OFFSET,
                formattedRawSize,
                formattedGzipSize,
                moduleListUrl,
                x + TEXT_X_OFFSET,
                y + TEXT_Y_OFFSET + LINE_HEIGHT,
                fileCount);
        rects.add(rect);

        // Add the connection points for boxes.
        int boxMiddle = x + BOX_WIDTH / 2;
        boxTops.put(module, new Point(boxMiddle, y));
        boxBottoms.put(module, new Point(boxMiddle, y + BOX_HEIGHT));

        x += BOX_WIDTH + X_BOX_SPACING;
      }
    }

    // Create lines to connect modules.
    List<String> lines = Lists.newLinkedList();
    for (Map.Entry<String, List<String>> deps : invertedDependencyTree.entrySet()) {
      String module = deps.getKey();
      Point sink = boxBottoms.get(module);
      for (String descendant : deps.getValue()) {
        Point source = boxTops.get(descendant);
        lines.add(
            String.format(
                "<line x1='%d' y1='%d' x2='%d' y2='%d' style='stroke:#006600;'/>",
                source.x, source.y, sink.x, sink.y));
      }
    }

    String svg = Joiner.on("\n").join(rects) + "\n" + Joiner.on("\n").join(lines) + "\n";

    int fullWidth = X_OFFSET + maxModulesPerRow * (BOX_WIDTH + X_BOX_SPACING) - X_BOX_SPACING;
    return Pair.of(svg, new Dimension(fullWidth, fullHeight + 1));
  }