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

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

Introduction

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

Prototype

@Nullable
V put(R rowKey, C columnKey, V value);

Source Link

Document

Associates the specified value with the specified keys.

Usage

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

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

    String version = args[0];//from   w w w. jav  a2  s  . co  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 w  w  . ja  v  a  2 s. c  o  m*/
    return t;
}

From source file:i5.las2peer.services.recommender.librec.data.DiagMatrix.java

public static DiagMatrix eye(int n) {
    Table<Integer, Integer, Double> vals = HashBasedTable.create();
    Multimap<Integer, Integer> colMap = HashMultimap.create();
    for (int i = 0; i < n; i++) {
        vals.put(i, i, 1.0);
        colMap.put(i, i);/*from w w w.j a va 2  s  .c  o m*/
    }

    return new DiagMatrix(n, n, vals, colMap);
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.helpers.FinalTableExtractor.java

public static void createCrossEvaluationTables(File mainFolder, final String prefix) throws IOException {
    Map<String, Table<String, String, Double>> domainResults = new TreeMap<>();

    File[] crossDomainFolders = mainFolder.listFiles(new FileFilter() {
        @Override//from  w  w  w.  j a va2  s .  c om
        public boolean accept(File pathname) {
            return pathname.isDirectory() && pathname.getName().startsWith(prefix);
        }
    });

    System.out.println(Arrays.toString(crossDomainFolders));

    for (File crossDomainFolder : crossDomainFolders) {
        // get the target domain
        String[] folderNameSplit = crossDomainFolder.getName().split("_");
        String domain = folderNameSplit[1];
        String featureSet = folderNameSplit[2];

        File resultSummaryFile = new File(crossDomainFolder, "resultSummary.txt");
        for (String line : FileUtils.readLines(resultSummaryFile)) {
            // parse the line with evaluation
            String[] split = line.split("\\s+");
            String argumentComponent = split[0];
            Double value = Double.valueOf(split[1]);

            // create a new table if needed
            if (!domainResults.containsKey(domain)) {
                domainResults.put(domain, TreeBasedTable.<String, String, Double>create());
            }

            // fill the table
            Table<String, String, Double> table = domainResults.get(domain);

            if (includeColumn(argumentComponent)) {
                table.put(featureSet, argumentComponent, value);
            }
        }
    }

    System.out.println(domainResults.keySet());

    for (Map.Entry<String, Table<String, String, Double>> entry : domainResults.entrySet()) {

        System.out.println(entry.getKey());
        System.out.println(tableToCsv(entry.getValue()));
    }
}

From source file:edu.cmu.lti.oaqa.baseqa.passage.rerank.scorers.LuceneInMemoryPassageScorer.java

private static synchronized <T extends Number> void synchronizedPut(Table<String, String, T> table, String uri,
        String conf, T value) {//from   w ww.  j  av a  2 s  . c o  m
    table.put(uri, conf, value);
}

From source file:com.google.devtools.build.lib.packages.License.java

private static Table<DistributionType, LicenseType, Object> createLicenseWarningsSet() {
    Table<DistributionType, LicenseType, Object> result = HashBasedTable.create();
    result.put(DistributionType.CLIENT, LicenseType.RECIPROCAL, MARKER);
    result.put(DistributionType.EMBEDDED, LicenseType.RECIPROCAL, MARKER);
    result.put(DistributionType.CLIENT, LicenseType.NOTICE, MARKER);
    result.put(DistributionType.EMBEDDED, LicenseType.NOTICE, MARKER);
    return ImmutableTable.copyOf(result);
}

From source file:com.google.devtools.build.lib.packages.License.java

private static Table<DistributionType, LicenseType, Object> createLicenseIncompatibilitySet() {
    Table<DistributionType, LicenseType, Object> result = HashBasedTable.create();
    result.put(DistributionType.CLIENT, LicenseType.RESTRICTED, MARKER);
    result.put(DistributionType.EMBEDDED, LicenseType.RESTRICTED, MARKER);
    result.put(DistributionType.INTERNAL, LicenseType.BY_EXCEPTION_ONLY, MARKER);
    result.put(DistributionType.CLIENT, LicenseType.BY_EXCEPTION_ONLY, MARKER);
    result.put(DistributionType.WEB, LicenseType.BY_EXCEPTION_ONLY, MARKER);
    result.put(DistributionType.EMBEDDED, LicenseType.BY_EXCEPTION_ONLY, MARKER);
    return ImmutableTable.copyOf(result);
}

From source file:org.eclipse.osee.orcs.script.dsl.OsFieldEnum.java

public static OsField getField(Family family, String fieldName) {
    if (FAMILY_AND_NAME_TO_FIELDS == null) {
        Table<Family, String, OsField> table = HashBasedTable.create();
        for (OsFieldEnum field : OsFieldEnum.values()) {
            table.put(field.getFamily(), field.getLiteral(), field);
        }/*from w ww . java2  s .com*/
        OsFieldEnum.FAMILY_AND_NAME_TO_FIELDS = table;
    }
    return FAMILY_AND_NAME_TO_FIELDS.get(family, fieldName);
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.DistanceCollectiveAnswerScorer.java

private static <K1, K2> Table<K1, K2, Double> normalize(Table<K1, K2, Double> orig) {
    Table<K1, K2, Double> ret = HashBasedTable.create();
    orig.rowMap().entrySet().forEach(entry -> {
        K1 key1 = entry.getKey();//from   w w  w  .  j a  v  a  2 s .  co m
        double sum = entry.getValue().values().stream().mapToDouble(x -> x).sum();
        entry.getValue().entrySet().forEach(e -> ret.put(key1, e.getKey(), e.getValue() / sum));
    });
    return ret;
}

From source file:org.sonar.api.batch.rule.internal.DefaultRules.java

private static void addToTable(Table<String, String, List<Rule>> table, DefaultRule r) {
    if (r.internalKey() == null) {
        return;/*from   ww w .  ja  v  a 2  s.c  om*/
    }

    List<Rule> ruleList = table.get(r.key().repository(), r.internalKey());

    if (ruleList == null) {
        ruleList = new LinkedList<>();
    }

    ruleList.add(r);
    table.put(r.key().repository(), r.internalKey(), ruleList);
}