Example usage for com.google.common.collect TreeBasedTable create

List of usage examples for com.google.common.collect TreeBasedTable create

Introduction

In this page you can find the example usage for com.google.common.collect TreeBasedTable create.

Prototype

public static <R extends Comparable, C extends Comparable, V> TreeBasedTable<R, C, V> create() 

Source Link

Document

Creates an empty TreeBasedTable that uses the natural orderings of both row and column 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 www  .j a  v  a2s . 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:de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.StatisticsTableCreator.java

public static Table<String, String, Long> loadTable(InputStream stream) throws IOException {
    Table<String, String, Long> result = TreeBasedTable.create();

    LineIterator lineIterator = IOUtils.lineIterator(stream, "utf-8");
    while (lineIterator.hasNext()) {
        String line = lineIterator.next();

        System.out.println(line);

        String[] split = line.split("\t");
        String language = split[0];
        String license = split[1];
        Long documents = Long.valueOf(split[2]);
        Long tokens = Long.valueOf(split[3]);

        result.put(language, "docs " + license, documents);
        result.put(language, "tokens " + license, tokens);
    }/* ww w.  jav a  2s . co m*/

    return result;
}

From source file:tech.tablesaw.aggregate.CrossTab.java

/**
 * Returns a table containing two-dimensional cross-tabulated counts for each combination of values in
 * {@code column1} and {@code column2}/*  w w  w .j ava 2 s.  co  m*/
 * <p>
 *
 * @param table   The table we're deriving the counts from
 * @param column1 A column in {@code table}
 * @param column2 Another column in {@code table}
 * @return A table containing the cross-tabs
 */
public static Table counts(Table table, CategoricalColumn<?> column1, CategoricalColumn<?> column2) {

    Table t = Table.create("Crosstab Counts: " + column1.name() + " x " + column2.name());
    t.addColumns(column1.type().create(LABEL_COLUMN_NAME));

    Table temp = table.sortOn(column1.name(), column2.name());

    int colIndex1 = table.columnIndex(column1.name());
    int colIndex2 = table.columnIndex(column2.name());

    com.google.common.collect.Table<String, String, Integer> gTable = TreeBasedTable.create();
    String a;
    String b;

    for (int row = 0; row < table.rowCount(); row++) {
        a = temp.column(colIndex1).getString(row);
        b = temp.column(colIndex2).getString(row);
        Integer cellValue = gTable.get(a, b);
        Integer value;
        if (cellValue != null) {
            value = cellValue + 1;
        } else {
            value = 1;
        }
        gTable.put(a, b, value);
    }

    for (String colName : gTable.columnKeySet()) {
        t.addColumns(IntColumn.create(colName));
    }

    t.addColumns(IntColumn.create("total"));

    int[] columnTotals = new int[t.columnCount()];

    for (String rowKey : gTable.rowKeySet()) {
        t.column(0).appendCell(rowKey);

        int rowSum = 0;

        for (String colKey : gTable.columnKeySet()) {
            Integer cellValue = gTable.get(rowKey, colKey);
            if (cellValue != null) {
                int colIdx = t.columnIndex(colKey);
                t.intColumn(colIdx).append(cellValue);
                rowSum += cellValue;
                columnTotals[colIdx] = columnTotals[colIdx] + cellValue;

            } else {
                t.intColumn(colKey).append(0);
            }
        }
        t.intColumn(t.columnCount() - 1).append(rowSum);
    }
    if (t.column(0).type().equals(ColumnType.STRING)) {
        t.column(0).appendCell("Total");
    } else {
        t.column(0).appendCell("");
    }
    int grandTotal = 0;
    for (int i = 1; i < t.columnCount() - 1; i++) {
        t.intColumn(i).append(columnTotals[i]);
        grandTotal = grandTotal + columnTotals[i];
    }
    t.intColumn(t.columnCount() - 1).append(grandTotal);
    return t;
}

From source file:net.osrg.namazu.Analyzer.java

public Analyzer(String storagePath, String classesPath) {
    this.storageDir = new File(storagePath);
    this.classesDir = new File(classesPath);
    this.analysisTable = TreeBasedTable.create();
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.significance.SignificanceMain.java

/**
 * Test significance between all methods in the folder and prints them as a CSV table
 *
 * @param mainFolder         folder//  www . j a  v a2 s.  co  m
 * @param folderResultPrefix prefix of folders to test, i.e. "cv_"
 * @throws IOException
 */
public static void compareMethods(File mainFolder, final String folderResultPrefix) throws IOException {
    File[] cvResults = mainFolder.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() && pathname.getName().startsWith(folderResultPrefix);
        }
    });

    Table<String, String, Boolean> table = TreeBasedTable.create();

    for (int i = 0; i < cvResults.length; i++) {
        for (int j = 0; j < cvResults.length; j++) {
            if (i != j) {
                File one = cvResults[i];
                File two = cvResults[j];
                double pValue = TestSignificanceTwoFiles.compareId2OutcomeFiles(
                        new File(one, TOKEN_LEVEL_PREDICTIONS_CSV), new File(two, TOKEN_LEVEL_PREDICTIONS_CSV),
                        new OutcomeSuccessMapReaderSequenceTokenCSVImpl());

                // order of methods does not matter
                List<String> methods = new ArrayList<>();
                methods.add(one.getName());
                methods.add(two.getName());
                Collections.sort(methods);

                table.put(methods.get(0), methods.get(1), pValue < P_VALUE);

                // and make symmetric matrix
                table.put(methods.get(1), methods.get(0), pValue < P_VALUE);
            }
        }
    }

    System.out.println(tableToCsv(table));
}

From source file:org.hawk.service.emf.EffectiveMetamodelRulesetSerializer.java

public EffectiveMetamodelRuleset load(Properties props) {
    final Map<Integer, String> incMetamodels = new TreeMap<>();
    final Table<Integer, Integer, String> incTypeTable = TreeBasedTable.create();
    final Table<Integer, Integer, ImmutableSet<String>> incSlotTable = TreeBasedTable.create();

    final Map<Integer, String> excMetamodels = new TreeMap<>();
    final Table<Integer, Integer, String> excTypeTable = TreeBasedTable.create();
    final Table<Integer, Integer, ImmutableSet<String>> excSlotTable = TreeBasedTable.create();

    for (String propName : props.stringPropertyNames()) {
        if (propName.startsWith(propertyPrefix)) {
            final String raw = propName.substring(propertyPrefix.length());
            boolean isIncludes;
            String unprefixed;/*from w  ww .ja va  2  s  .co m*/
            if (raw.startsWith(INCLUDES_SUFFIX)) {
                isIncludes = true;
                unprefixed = raw.substring(INCLUDES_SUFFIX.length());
            } else if (raw.startsWith(EXCLUDES_SUFFIX)) {
                isIncludes = false;
                unprefixed = raw.substring(EXCLUDES_SUFFIX.length());
            } else {
                continue;
            }
            final String[] parts = unprefixed.split("[" + SEPARATOR + "]");

            final String propValue = props.getProperty(propName).trim();
            int iMetamodel, iType;
            switch (parts.length) {
            case 1: // prefix0 -> URI of the first metamodel
                iMetamodel = Integer.valueOf(parts[0]);
                String mmURI = propValue;
                if (isIncludes) {
                    incMetamodels.put(iMetamodel, mmURI);
                } else {
                    excMetamodels.put(iMetamodel, mmURI);
                }
                break;
            case 2: // prefix0.0 -> name of the first type of the first metamodel
                iMetamodel = Integer.valueOf(parts[0]);
                iType = Integer.valueOf(parts[1]);
                String type = propValue;
                if (isIncludes) {
                    incTypeTable.put(iMetamodel, iType, type);
                } else {
                    excTypeTable.put(iMetamodel, iType, type);
                }
                break;
            case 3: // prefix0.0.slots -> comma-separated slots for the first type of first metamodel (if not all)
                iMetamodel = Integer.valueOf(parts[0]);
                iType = Integer.valueOf(parts[1]);
                ImmutableSet<String> slots;
                if (propValue.length() > 0) {
                    slots = ImmutableSet.copyOf(propValue.split("[" + SEPARATOR + "]"));
                } else {
                    slots = ImmutableSet.of();
                }
                if (isIncludes) {
                    incSlotTable.put(iMetamodel, iType, slots);
                } else {
                    excSlotTable.put(iMetamodel, iType, slots);
                }
                break;
            default:
                throw new IllegalArgumentException(String
                        .format("Property %s should only have 1-3 parts, but has %d", propName, parts.length));
            }
        }
    }

    final EffectiveMetamodelRuleset ruleset = new EffectiveMetamodelRuleset();

    for (final Cell<Integer, Integer, ImmutableSet<String>> mmEntry : incSlotTable.cellSet()) {
        final String mmURI = incMetamodels.get(mmEntry.getRowKey());
        final String typeName = incTypeTable.get(mmEntry.getRowKey(), mmEntry.getColumnKey());
        final ImmutableSet<String> slots = mmEntry.getValue();

        if (EffectiveMetamodelRuleset.WILDCARD.equals(typeName)) {
            ruleset.include(mmURI);
        } else if (slots.contains(EffectiveMetamodelRuleset.WILDCARD)) {
            ruleset.include(mmURI, typeName);
        } else {
            ruleset.include(mmURI, typeName, slots);
        }
    }

    for (final Cell<Integer, Integer, ImmutableSet<String>> mmEntry : excSlotTable.cellSet()) {
        final String mmURI = excMetamodels.get(mmEntry.getRowKey());
        final String typeName = excTypeTable.get(mmEntry.getRowKey(), mmEntry.getColumnKey());
        final ImmutableSet<String> slots = mmEntry.getValue();

        if (EffectiveMetamodelRuleset.WILDCARD.equals(typeName)) {
            ruleset.exclude(mmURI);
        } else if (slots.contains(EffectiveMetamodelRuleset.WILDCARD)) {
            ruleset.exclude(mmURI, typeName);
        } else {
            ruleset.exclude(mmURI, typeName, slots);
        }
    }

    return ruleset;
}

From source file:com.dangdang.ddframe.rdb.sharding.jdbc.GeneratedKeysResultSet.java

public GeneratedKeysResultSet() {
    valueTable = TreeBasedTable.create();
    columnNameToIndexMap = new HashMap<>();
    statement = null;
    isClosed = true;
}

From source file:com.lukke100.sbdi.TileMap.java

public TileMap(int xSize, int ySize) {
    tileMap = new Tile[xSize][ySize];
    this.xSize = xSize;
    this.ySize = ySize;
    markedAct = new TreeMap<Integer, Execute>();
    markedMove = new TreeMap<Integer, MapEntity>();
    allEntities = new TreeMap<Integer, Entity>();
    voids = TreeBasedTable.create();
    populate();//from w w  w  .j  ava  2s  .  c  om
}

From source file:Model.Environment.Environment.java

/**
 * Constructor/*from   w w  w. ja va  2s.co  m*/
 */
public Environment() {
    this.map = TreeBasedTable.create();
    this.vehicles = new ArrayList<>();
    this.infrastructures = new ArrayList<>();
}

From source file:reflex.value.ReflexSparseMatrixValue.java

public ReflexSparseMatrixValue(int dimension) {
    table = TreeBasedTable.create();
    rowOrder = new ArrayList<ReflexValue>();
    colOrder = new ArrayList<ReflexValue>();
}