コード例 #1
0
ファイル: UISkinBuilder.java プロジェクト: DVisman/Terasology
  private UIStyleFamily buildFamily(String family, UISkin skin) {
    UIStyleFamily baseFamily = skin.getFamily(family);
    UIStyle baseStyle = new UIStyle(skin.getDefaultStyleFor(family));
    if (!family.isEmpty()) {
      UIStyleFragment fragment = baseStyles.get(family);
      fragment.applyTo(baseStyle);
    }

    Set<StyleKey> inheritedStyleKey = Sets.newLinkedHashSet();
    for (Class<? extends UIWidget> widget : baseFamily.getWidgets()) {
      inheritedStyleKey.add(new StyleKey(widget, "", ""));
      for (String part : baseFamily.getPartsFor(widget)) {
        inheritedStyleKey.add(new StyleKey(widget, part, ""));
        for (String mode : baseFamily.getModesFor(widget, part)) {
          inheritedStyleKey.add(new StyleKey(widget, part, mode));
        }
      }
    }

    Map<Class<? extends UIWidget>, Table<String, String, UIStyle>> familyStyles = Maps.newHashMap();
    Map<StyleKey, UIStyleFragment> styleLookup = elementStyles.row(family);
    Map<StyleKey, UIStyleFragment> baseStyleLookup =
        (family.isEmpty()) ? Maps.<StyleKey, UIStyleFragment>newHashMap() : elementStyles.row("");
    for (StyleKey styleKey :
        Sets.union(Sets.union(styleLookup.keySet(), baseStyleKeys), inheritedStyleKey)) {
      UIStyle elementStyle =
          new UIStyle(baseSkin.getStyleFor(family, styleKey.element, styleKey.part, styleKey.mode));
      baseStyles.get("").applyTo(elementStyle);
      baseStyles.get(family).applyTo(elementStyle);
      List<Class<? extends UIWidget>> inheritanceTree =
          ReflectionUtil.getInheritanceTree(styleKey.element, UIWidget.class);
      applyStylesForInheritanceTree(
          inheritanceTree, "", "", elementStyle, styleLookup, baseStyleLookup);

      if (!styleKey.part.isEmpty()) {
        applyStylesForInheritanceTree(
            inheritanceTree, styleKey.part, "", elementStyle, styleLookup, baseStyleLookup);
      }

      if (!styleKey.mode.isEmpty()) {
        applyStylesForInheritanceTree(
            inheritanceTree,
            styleKey.part,
            styleKey.mode,
            elementStyle,
            styleLookup,
            baseStyleLookup);
      }

      Table<String, String, UIStyle> elementTable = familyStyles.get(styleKey.element);
      if (elementTable == null) {
        elementTable = HashBasedTable.create();
        familyStyles.put(styleKey.element, elementTable);
      }
      elementTable.put(styleKey.part, styleKey.mode, elementStyle);
    }
    return new UIStyleFamily(baseStyle, familyStyles);
  }
コード例 #2
0
  public static Map<String, String> match(
      Table<Integer, String, String> table, Map<String, FieldValue> values) {
    Set<Integer> rowKeys = table.rowKeySet();

    rows:
    for (Integer rowKey : rowKeys) {
      Map<String, String> row = table.row(rowKey);

      // A table row contains a certain number of input columns, plus an output column
      if (values.size() < (row.size() - 1)) {
        continue rows;
      }

      Collection<Map.Entry<String, FieldValue>> entries = values.entrySet();
      for (Map.Entry<String, FieldValue> entry : entries) {
        String key = entry.getKey();
        FieldValue value = entry.getValue();

        String rowValue = row.get(key);
        if (rowValue == null) {
          continue rows;
        }

        boolean equals = value.equalsString(rowValue);
        if (!equals) {
          continue rows;
        }
      }

      return row;
    }

    return null;
  }
コード例 #3
0
ファイル: SparseMatrix.java プロジェクト: edcmartin/librec
  /**
   * Construct a sparse matrix
   *
   * @param dataTable data table
   * @param columnStructure column structure
   */
  private void construct(
      Table<Integer, Integer, Double> dataTable, Multimap<Integer, Integer> columnStructure) {
    int nnz = dataTable.size();

    // CRS
    rowPtr = new int[numRows + 1];
    colInd = new int[nnz];
    rowData = new double[nnz];

    int j = 0;
    for (int i = 1; i <= numRows; ++i) {
      Set<Integer> cols = dataTable.row(i - 1).keySet();
      rowPtr[i] = rowPtr[i - 1] + cols.size();

      for (int col : cols) {
        colInd[j++] = col;
        if (col < 0 || col >= numColumns)
          throw new IllegalArgumentException(
              "colInd[" + j + "]=" + col + ", which is not a valid column index");
      }

      Arrays.sort(colInd, rowPtr[i - 1], rowPtr[i]);
    }

    // CCS
    if (columnStructure != null) {
      colPtr = new int[numColumns + 1];
      rowInd = new int[nnz];
      colData = new double[nnz];
      isCCSUsed = true;

      j = 0;
      for (int i = 1; i <= numColumns; ++i) {
        // dataTable.col(i-1) is very time-consuming
        Collection<Integer> rows = columnStructure.get(i - 1);
        colPtr[i] = colPtr[i - 1] + rows.size();

        for (int row : rows) {
          rowInd[j++] = row;
          if (row < 0 || row >= numRows)
            throw new IllegalArgumentException(
                "rowInd[" + j + "]=" + row + ", which is not a valid row index");
        }

        Arrays.sort(rowInd, colPtr[i - 1], colPtr[i]);
      }
    }

    // set data
    for (Cell<Integer, Integer, Double> en : dataTable.cellSet()) {
      int row = en.getRowKey();
      int col = en.getColumnKey();
      double val = en.getValue();

      set(row, col, val);
    }
  }
コード例 #4
0
 @Override
 public void store(Measure measure) {
   // Emulate duplicate measure check
   String componentKey = measure.inputComponent().key();
   String metricKey = measure.metric().key();
   if (measuresByComponentAndMetric.contains(componentKey, metricKey)) {
     throw new SonarException("Can not add the same measure twice");
   }
   measuresByComponentAndMetric.row(componentKey).put(metricKey, measure);
 }
コード例 #5
0
ファイル: UISkinBuilder.java プロジェクト: DVisman/Terasology
  private UIStyleFamily buildFamily(String family, UIStyle defaultStyle) {
    UIStyle baseStyle = new UIStyle(defaultStyle);
    if (!family.isEmpty()) {
      UIStyleFragment fragment = baseStyles.get(family);
      fragment.applyTo(baseStyle);
    }

    Map<Class<? extends UIWidget>, Table<String, String, UIStyle>> familyStyles = Maps.newHashMap();
    Map<StyleKey, UIStyleFragment> styleLookup = elementStyles.row(family);
    Map<StyleKey, UIStyleFragment> baseStyleLookup =
        (family.isEmpty()) ? Maps.<StyleKey, UIStyleFragment>newHashMap() : elementStyles.row("");
    for (StyleKey styleKey : Sets.union(styleLookup.keySet(), baseStyleKeys)) {
      UIStyle elementStyle = new UIStyle(baseStyle);
      List<Class<? extends UIWidget>> inheritanceTree =
          ReflectionUtil.getInheritanceTree(styleKey.element, UIWidget.class);
      applyStylesForInheritanceTree(
          inheritanceTree, "", "", elementStyle, styleLookup, baseStyleLookup);

      if (!styleKey.part.isEmpty()) {
        applyStylesForInheritanceTree(
            inheritanceTree, styleKey.part, "", elementStyle, styleLookup, baseStyleLookup);
      }

      if (!styleKey.mode.isEmpty()) {
        applyStylesForInheritanceTree(
            inheritanceTree,
            styleKey.part,
            styleKey.mode,
            elementStyle,
            styleLookup,
            baseStyleLookup);
      }

      Table<String, String, UIStyle> elementTable = familyStyles.get(styleKey.element);
      if (elementTable == null) {
        elementTable = HashBasedTable.create();
        familyStyles.put(styleKey.element, elementTable);
      }
      elementTable.put(styleKey.part, styleKey.mode, elementStyle);
    }
    return new UIStyleFamily(baseStyle, familyStyles);
  }
コード例 #6
0
    @Override
    public Module getLatestModuleVersion(String id) {
      Module latest = null;
      for (Module module : modules.row(id).values()) {
        if (latest == null || latest.getVersion().compareTo(module.getVersion()) < 0) {
          latest = module;
        }
      }

      return latest;
    }
コード例 #7
0
 @Override
 public void store(DefaultCoverage defaultCoverage) {
   String fileKey = defaultCoverage.inputFile().key();
   // Emulate duplicate storage check
   if (coverageByComponentAndType.contains(fileKey, defaultCoverage.type())) {
     throw new UnsupportedOperationException(
         "Trying to save coverage twice for the same file is not supported: "
             + defaultCoverage.inputFile().relativePath());
   }
   coverageByComponentAndType.row(fileKey).put(defaultCoverage.type(), defaultCoverage);
 }
コード例 #8
0
    public List<Vertex> getProductAssociations(Vertex v) {
      Map<Vertex, Edge> adjacent = Maps.newHashMap(graph.row(v));
      adjacent.putAll(graph.column(v));

      return adjacent
          .entrySet()
          .stream()
          .sorted((e1, e2) -> e2.getValue().weight - e1.getValue().weight)
          .map(Map.Entry::getKey)
          .collect(Collectors.toList());
    }
コード例 #9
0
 @Override
 public Module getLatestModuleVersion(String id, Version minVersion, Version maxVersion) {
   Module latestInBounds = null;
   for (Module module : modules.row(id).values()) {
     if (module.getVersion().compareTo(minVersion) >= 0
         && module.getVersion().compareTo(maxVersion) < 0
         && (latestInBounds == null
             || latestInBounds.getVersion().compareTo(module.getVersion()) > 0)) {
       latestInBounds = module;
     }
   }
   return latestInBounds;
 }
コード例 #10
0
ファイル: GameData.java プロジェクト: Kobata/FML
  public static void dumpRegistry(File minecraftDir) {
    if (customItemStacks == null) {
      return;
    }
    if (Boolean.valueOf(System.getProperty("fml.dumpRegistry", "false")).booleanValue()) {
      ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
      for (String modId : customItemStacks.rowKeySet()) {
        builder.putAll(modId, customItemStacks.row(modId).keySet());
      }

      File f = new File(minecraftDir, "itemStackRegistry.csv");
      MapJoiner mapJoiner = Joiner.on("\n").withKeyValueSeparator(",");
      try {
        Files.write(mapJoiner.join(builder.build().entries()), f, Charsets.UTF_8);
        FMLLog.log(Level.INFO, "Dumped item registry data to %s", f.getAbsolutePath());
      } catch (IOException e) {
        FMLLog.log(Level.ERROR, e, "Failed to write registry data to %s", f.getAbsolutePath());
      }
    }
  }
コード例 #11
0
  /**
   * Builds a pretty print from the statistics gathered.
   *
   * @return
   */
  private String getStatString() {
    StringBuilder builder = new StringBuilder();

    builder.append(
        String.format(
            "Served %d addresses and %d resources\n",
            statsTable.rowKeySet().size(), statsTable.cellSet().size()));
    builder.append("_\n");
    // iterate over every row (addresses)
    for (String address : statsTable.rowKeySet()) {
      builder.append(String.format("|- %s\n", address));
      builder.append("|\t _\n");
      // iterate over every column for a specific address
      for (String resource : statsTable.row(address).keySet()) {
        builder.append(String.format("|\t |- %s: \n", resource));

        // get the statistics
        StatHelper statHelper = statsTable.get(address, resource);
        builder.append(
            String.format("|\t |------ total requests: %d\n", statHelper.getTotalCount()));
        builder.append(
            String.format("|\t |------ total cached replies: %d\n", statHelper.getCachedCount()));
        // builder.append(String.format("|\t |------ last period (%d sec) requests: %d\n",
        // PERIOD_SECONDS, statHelper.getLastPeriodCount()));
        // builder.append(String.format("|\t |------ last period (%d sec) avg delay (nanosec):
        // %d\n",
        // PERIOD_SECONDS, statHelper.getLastPeriodAvgDelay()));
        builder.append("|\t |\n");
      }
      builder.append("|\t  ̄\n");
      builder.append("|\n");
    }
    builder.append(" ̄\n");

    return builder.length() == 0
        ? "The proxy has not received any request, yet."
        : builder.toString();
  }
コード例 #12
0
  static BuildConfiguration setupTransitions(
      BuildConfiguration targetConfiguration,
      BuildConfiguration dataConfiguration,
      BuildConfiguration hostConfiguration,
      ListMultimap<SplitTransition<?>, BuildConfiguration> splitTransitionsTable) {
    Set<BuildConfiguration> allConfigurations = new LinkedHashSet<>();
    allConfigurations.add(targetConfiguration);
    allConfigurations.add(dataConfiguration);
    allConfigurations.add(hostConfiguration);
    allConfigurations.addAll(splitTransitionsTable.values());

    Table<BuildConfiguration, Transition, ConfigurationHolder> transitionBuilder =
        HashBasedTable.create();
    for (BuildConfiguration from : allConfigurations) {
      for (ConfigurationTransition transition : ConfigurationTransition.values()) {
        BuildConfiguration to;
        if (transition == ConfigurationTransition.HOST) {
          to = hostConfiguration;
        } else if (transition == ConfigurationTransition.DATA && from == targetConfiguration) {
          to = dataConfiguration;
        } else {
          to = from;
        }
        transitionBuilder.put(from, transition, new ConfigurationHolder(to));
      }
    }

    // TODO(bazel-team): This makes LIPO totally not work. Just a band-aid until we get around to
    // implementing a way for the C++ rules to contribute this transition to the configuration
    // collection.
    for (BuildConfiguration config : allConfigurations) {
      transitionBuilder.put(config, CppTransition.LIPO_COLLECTOR, new ConfigurationHolder(config));
      transitionBuilder.put(
          config,
          CppTransition.TARGET_CONFIG_FOR_LIPO,
          new ConfigurationHolder(config.isHostConfiguration() ? null : config));
    }

    for (BuildConfiguration config : allConfigurations) {
      Transitions outgoingTransitions =
          new BazelTransitions(
              config,
              transitionBuilder.row(config),
              // Split transitions must not have their own split transitions because then they
              // would be applied twice due to a quirk in DependencyResolver. See the comment in
              // DependencyResolver.resolveLateBoundAttributes().
              splitTransitionsTable.values().contains(config)
                  ? ImmutableListMultimap.<SplitTransition<?>, BuildConfiguration>of()
                  : splitTransitionsTable);
      // We allow host configurations to be shared between target configurations. In that case, the
      // transitions may already be set.
      // TODO(bazel-team): Check that the transitions are identical, or even better, change the
      // code to set the host configuration transitions before we even create the target
      // configuration.
      if (config.isHostConfiguration() && config.getTransitions() != null) {
        continue;
      }
      config.setConfigurationTransitions(outgoingTransitions);
    }

    return targetConfiguration;
  }