Example usage for com.google.common.collect Table row

List of usage examples for com.google.common.collect Table row

Introduction

In this page you can find the example usage for com.google.common.collect Table row.

Prototype

Map<C, V> row(R rowKey);

Source Link

Document

Returns a view of all mappings that have the given row key.

Usage

From source file:org.sonarsource.sonarlint.core.extractor.Main.java

public static void main(String[] args) throws MalformedURLException {

    String version = args[0];// w w  w . j  a v a  2s .  c o  m

    List<Path> pluginPaths = new ArrayList<>();
    for (int i = 1; i < args.length; i++) {
        pluginPaths.add(Paths.get(args[i]));
    }

    StandaloneGlobalConfiguration.Builder builder = StandaloneGlobalConfiguration.builder()
            .setLogOutput(new LogOutput() {
                @Override
                public void log(String formattedMessage, Level level) {
                    // Ignore
                }
            });

    for (Path path : pluginPaths) {
        builder.addPlugin(path.toUri().toURL());
    }
    StandaloneSonarLintEngineImpl client = new StandaloneSonarLintEngineImpl(builder.build());
    client.start();

    Table<String, String, RuleDetails> rulesByKeyAndLanguage = TreeBasedTable.create();
    for (String ruleKeyStr : ((StandaloneGlobalContainer) client.getGlobalContainer()).getActiveRuleKeys()) {
        RuleDetails ruleDetails = client.getRuleDetails(ruleKeyStr);
        RuleKey ruleKey = RuleKey.parse(ruleKeyStr);
        rulesByKeyAndLanguage.put(ruleKey.rule(), ruleDetails.getLanguage(), ruleDetails);
    }

    try {
        System.out.print("{");
        System.out.print("\"version\": \"");
        System.out.print(version);
        System.out.print("\",");

        System.out.print("\"rules\": [");
        boolean first = true;
        for (String ruleKey : rulesByKeyAndLanguage.rowKeySet()) {
            if (!first) {
                System.out.print(",");
            }
            first = false;
            System.out.print("{");
            System.out.print("\"key\": \"");
            System.out.print(ruleKey);
            System.out.print("\",");
            System.out.print("\"title\": \"");
            System.out
                    .print(escapeJson(rulesByKeyAndLanguage.row(ruleKey).values().iterator().next().getName()));
            System.out.print("\",");

            Set<String> mergedTags = new HashSet<>();
            for (RuleDetails rule : rulesByKeyAndLanguage.row(ruleKey).values()) {
                mergedTags.addAll(Arrays.asList(rule.getTags()));
            }
            writeTags(mergedTags);
            System.out.print(",");

            System.out.print("\"implementations\": [");

            boolean firstLang = true;
            for (Map.Entry<String, RuleDetails> detailPerLanguage : rulesByKeyAndLanguage.row(ruleKey)
                    .entrySet()) {
                if (!firstLang) {
                    System.out.print(",");
                }
                firstLang = false;
                RuleDetails ruleDetails = detailPerLanguage.getValue();
                System.out.print("{");
                System.out.print("\"key\": \"");
                System.out.print(ruleDetails.getKey());
                System.out.print("\",");
                System.out.print("\"language\": \"");
                System.out.print(languageLabel(detailPerLanguage.getKey()));
                System.out.print("\",");
                System.out.print("\"title\": \"");
                System.out.print(escapeJson(ruleDetails.getName()));
                System.out.print("\",");
                System.out.print("\"description\": \"");
                System.out.print(escapeJson(ruleDetails.getHtmlDescription()));
                System.out.print("\",");
                System.out.print("\"severity\": \"");
                System.out.print(StringUtils.capitalize(ruleDetails.getSeverity().toLowerCase()));
                System.out.print("\",");
                String[] tags = ruleDetails.getTags();
                writeTags(Arrays.asList(tags));
                System.out.print("}");
            }
            System.out.print("]");
            System.out.print("}");
        }
        System.out.print("]");
        System.out.print("}");
    } finally {
        client.stop();
    }

}

From source file:helpers.SimpleTestSample.java

public static Table getTable(int randomRows) {
    Table<Integer, String, Object> t = HashBasedTable.create();
    t.put(0, "A1", 1);
    t.put(1, "A1", 3);
    t.row(0).put("A2", 5);
    t.put(0, "A3", 12);
    Random r = new Random();
    for (int i = 2; i < randomRows; i++) {
        t.put(i, "A1", r.nextInt(500));
        t.put(i, "A2", r.nextInt(255));
    }// w ww. j av a 2  s .com
    return t;
}

From source file:org.jpmml.evaluator.InlineTableUtil.java

static public 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;
        }/*w w  w.  ja  va 2 s  . c om*/

        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;
}

From source file:com.google.devtools.build.android.resources.RClassGenerator.java

private static List<FieldInitializer> getInitializers(String typeName,
        Table<String, String, SymbolEntry> symbols, Table<String, String, SymbolEntry> values) {
    Map<String, SymbolEntry> rowMap = symbols.row(typeName);
    Set<String> symbolSet = rowMap.keySet();
    List<String> symbolList = new ArrayList<>(symbolSet);
    Collections.sort(symbolList);
    List<FieldInitializer> initializers = new ArrayList<>();
    for (String symbolName : symbolList) {
        // get the matching SymbolEntry from the values Table.
        SymbolEntry value = values.get(typeName, symbolName);
        if (value != null) {
            if (value.getType().equals("int")) {
                initializers.add(IntFieldInitializer.of(value.getName(), value.getValue()));
            } else {
                Preconditions.checkArgument(value.getType().equals("int[]"));
                initializers.add(IntArrayFieldInitializer.of(value.getName(), value.getValue()));
            }//from  w w w .j av a 2  s  .  c  om
        } else {
            // Value may be missing if resource overriding eliminates resources at the binary
            // level, which were originally present at the library level.
            logger.fine(String.format("Skipping R.%s.%s -- value not known in binary's R.txt", typeName,
                    symbolName));
        }
    }
    return initializers;
}

From source file:com.android.tools.idea.uibuilder.property.NlProperties.java

private static void setUpDesignProperties(@NotNull Table<String, String, NlPropertyItem> properties) {
    List<String> designProperties = new ArrayList<>(properties.row(TOOLS_URI).keySet());
    for (String propertyName : designProperties) {
        NlPropertyItem item = properties.get(AUTO_URI, propertyName);
        if (item == null) {
            item = properties.get(ANDROID_URI, propertyName);
        }//from w w  w .jav a 2s. co  m
        if (item != null) {
            NlPropertyItem designItem = item.getDesignTimeProperty();
            properties.put(TOOLS_URI, propertyName, designItem);
        }
    }
}

From source file:com.android.tools.idea.uibuilder.property.PropertyTestCase.java

@NotNull
protected static Map<String, NlProperty> getPropertyMap(@NotNull List<NlComponent> components) {
    if (components.isEmpty()) {
        return Collections.emptyMap();
    }//  w  w  w  .j a v  a 2 s .  c om
    Table<String, String, NlPropertyItem> properties = getPropertyTable(components);
    Map<String, NlProperty> propertiesByName = new HashMap<>();
    for (NlProperty property : properties.row(ANDROID_URI).values()) {
        propertiesByName.put(property.getName(), property);
    }
    for (NlProperty property : properties.row(AUTO_URI).values()) {
        propertiesByName.put(property.getName(), property);
    }
    for (NlProperty property : properties.row("").values()) {
        propertiesByName.put(property.getName(), property);
    }
    // Add access to known design properties
    NlDesignProperties designProperties = new NlDesignProperties();
    for (NlProperty property : designProperties.getKnownProperties(components)) {
        propertiesByName.putIfAbsent(property.getName(), property);
    }
    return propertiesByName;
}

From source file:org.pau.assetmanager.viewmodel.stocks.HistoricalStocksValuesDownloader.java

private static List<HistoricalStockValue> getHistoricalStockValues(String symbol, Integer startYear,
        Integer finalYear) {//from w w  w  .j av a 2s  . co m
    List<HistoricalStockValue> historicalStockValues = new LinkedList<HistoricalStockValue>();
    Table<Integer, Integer, Double> yearToMonthToValueTable = getYearToMonthToValueTable(symbol, startYear,
            finalYear);
    for (Integer currentYear : yearToMonthToValueTable.rowKeySet()) {
        Map<Integer, Double> monthToValue = yearToMonthToValueTable.row(currentYear);
        for (Integer currentMonth : monthToValue.keySet()) {
            Double value = monthToValue.get(currentMonth);
            HistoricalStockValue historicalStockValue = new HistoricalStockValue();
            historicalStockValue.setCollectionDate(new Date());
            historicalStockValue.setMonth(currentMonth);
            historicalStockValue.setYear(currentYear);
            historicalStockValue.setSymbol(symbol);
            historicalStockValue.setNumericalValue(Math.round(value * 100.0));
            historicalStockValues.add(historicalStockValue);
        }
    }
    return historicalStockValues;
}

From source file:com.android.tools.idea.uibuilder.property.NlPropertiesPanel.java

@NotNull
private static List<NlPropertyItem> extractPropertiesForTable(
        @NotNull Table<String, String, NlPropertyItem> properties) {
    Map<String, NlPropertyItem> androidProperties = properties.row(SdkConstants.ANDROID_URI);
    Map<String, NlPropertyItem> autoProperties = properties.row(SdkConstants.AUTO_URI);
    Map<String, NlPropertyItem> designProperties = properties.row(TOOLS_URI);
    Map<String, NlPropertyItem> bareProperties = properties.row("");

    // Include all auto (app) properties and all android properties that are not also auto properties.
    List<NlPropertyItem> result = new ArrayList<>(properties.size());
    result.addAll(autoProperties.values());
    for (Map.Entry<String, NlPropertyItem> entry : androidProperties.entrySet()) {
        if (!autoProperties.containsKey(entry.getKey())) {
            result.add(entry.getValue());
        }//  w  ww . ja v a 2  s .  com
    }
    result.addAll(designProperties.values());
    result.addAll(bareProperties.values());
    return result;
}

From source file:com.zxy.commons.poi.excel.ExcelUtils.java

/**
 * table?multimap/*from   www .  java  2 s .c om*/
 * 
 * @param table table
 * @return multimap
*/
public static Multimap<String, String> table2map(Table<Integer, String, String> table) {
    Multimap<String, String> multimap = LinkedHashMultimap.create();

    Set<Integer> rowNames = table.rowKeySet();
    // Set<String> columnNames = table.columnKeySet();

    for (Integer rowName : rowNames) {
        Map<String, String> items = table.row(rowName);
        for (Map.Entry<String, String> entry : items.entrySet()) {
            String columnName = entry.getKey();
            String value = entry.getValue();
            multimap.put(columnName, value);
        }
    }
    return multimap;
}

From source file:com.android.tools.idea.uibuilder.property.NlProperties.java

private static Table<String, String, NlPropertyItem> combine(
        @NotNull Table<String, String, NlPropertyItem> properties,
        @Nullable Table<String, String, NlPropertyItem> combinedProperties) {
    if (combinedProperties == null) {
        return properties;
    }//w ww .jav  a 2s.c  om
    List<String> namespaces = new ArrayList<>(combinedProperties.rowKeySet());
    List<String> propertiesToRemove = new ArrayList<>();
    for (String namespace : namespaces) {
        propertiesToRemove.clear();
        for (Map.Entry<String, NlPropertyItem> entry : combinedProperties.row(namespace).entrySet()) {
            NlPropertyItem other = properties.get(namespace, entry.getKey());
            if (!entry.getValue().sameDefinition(other)) {
                propertiesToRemove.add(entry.getKey());
            }
        }
        for (String propertyName : propertiesToRemove) {
            combinedProperties.remove(namespace, propertyName);
        }
    }
    // Never include the ID attribute when looking at multiple components:
    combinedProperties.remove(ANDROID_URI, ATTR_ID);
    return combinedProperties;
}