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

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

Introduction

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

Prototype

Set<R> rowKeySet();

Source Link

Document

Returns a set of row keys that have one or more values in the table.

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  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:org.opennms.netmgt.measurements.filters.impl.Utils.java

public static TableLimits getRowsWithValues(Table<Long, String, Double> table, String... columnNames) {
    TableLimits limits = new TableLimits();
    for (long k : table.rowKeySet()) {
        for (String columnName : columnNames) {
            Double value = table.get(k, columnName);

            if (value != null && !Double.isNaN(value)) {
                if (limits.firstRowWithValues < 0) {
                    limits.firstRowWithValues = k;
                }//from   ww  w  . j  av a 2 s .  c  o m
                limits.lastRowWithValues = k;
            }
        }
    }

    return limits;
}

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;
        }//from  w w w  . ja v  a 2  s  .co  m

        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:org.opennms.netmgt.jasper.analytics.DataSourceUtils.java

public static Point getRowsWithValues(Table<Integer, String, Double> table, String... columnNames) {
    int firstRowWithValues = -1, lastRowWithValues = -1;
    for (int k : table.rowKeySet()) {
        for (String columnName : columnNames) {
            Double value = table.get(k, columnName);

            if (value != null && !Double.isNaN(value)) {
                if (firstRowWithValues < 0) {
                    firstRowWithValues = k;
                }//  w ww.  j  a  v a 2  s . co m
                lastRowWithValues = k;
            }
        }
    }

    return new Point(firstRowWithValues, lastRowWithValues);
}

From source file:de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.StatisticsTableCreator.java

public static void saveTableToCsv(Table<String, String, Long> table, OutputStream outputStream) {
    PrintWriter pw = new PrintWriter(outputStream);
    pw.write(";");
    for (String columnKey : table.columnKeySet()) {
        pw.printf("%s;", columnKey);
    }/* ww  w.j a  v  a  2 s  .c o m*/
    pw.println();

    for (String rowKey : table.rowKeySet()) {
        pw.printf("%s;", rowKey);
        for (String columnKey : table.columnKeySet()) {
            Long value = table.get(rowKey, columnKey);
            pw.printf("%d;", value != null ? value : 0);
        }
        pw.println();
    }

    IOUtils.closeQuietly(pw);
}

From source file:org.opennms.netmgt.jasper.analytics.DataSourceUtils.java

public static ColumnValuesDataSource toDs(Table<Integer, String, Double> table) {
    String columnNames[] = table.columnKeySet().toArray(new String[0]);
    List<ColumnValues> columnValues = Lists.newLinkedList();
    int numRows = table.rowKeySet().size();

    // Rebuild all of the columns
    for (String columnName : columnNames) {
        if ("Timestamp".equalsIgnoreCase(columnName)) {
            // Always convert the Timestamp column to Date objects
            Object[] values = new Date[numRows];
            for (int i = 0; i < numRows; i++) {
                values[i] = new Date(table.get(i, columnName).longValue());
            }//from  w w  w.j av  a 2s .co  m
            columnValues.add(new ObjectArrayValues(values));
        } else {
            // Leave every other column as doubles
            double[] values = new double[numRows];
            for (int i = 0; i < numRows; i++) {
                Double value = table.get(i, columnName);
                // Convert any nulls to NaNs, avoids NPEs
                if (value != null) {
                    values[i] = value;
                } else {
                    values[i] = Double.NaN;
                }
            }
            columnValues.add(new DoubleArrayValues(values));
        }
    }

    // Join the columns into a data source
    return new ColumnValuesDataSource(columnNames, numRows, columnValues.toArray(new ColumnValues[0]));
}

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

private static List<HistoricalStockValue> getHistoricalStockValues(String symbol, Integer startYear,
        Integer finalYear) {/*from  w ww.j  a v  a2  s . com*/
    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:de.tudarmstadt.ukp.experiments.argumentation.sequence.significance.SignificanceMain.java

/**
 * Prints table to output string as CSV//from   w  w  w.  j  a va2 s  .c o  m
 *
 * @param out   output
 * @param <T>   value type
 * @param table table
 * @throws IOException
 */
public static <T> String tableToCsv(Table<String, String, Boolean> table) throws IOException {
    StringWriter sw = new StringWriter();
    CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);

    List<String> firstRow = new ArrayList<>();
    firstRow.add(" ");
    firstRow.addAll(table.columnKeySet());
    printer.printRecord(firstRow);

    for (String rowKey : table.rowKeySet()) {
        printer.print(rowKey);
        for (String columnKey : table.columnKeySet()) {
            printer.print(table.get(rowKey, columnKey));
        }
        printer.println();
    }

    printer.close();

    return sw.toString();
}

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

/** Convert the {@link SymbolLoader} data, to a map of {@link FieldInitializer}. */
private static Map<ResourceType, List<FieldInitializer>> getInitializers(
        Table<String, String, SymbolEntry> symbols, Table<String, String, SymbolEntry> values) {
    Map<ResourceType, List<FieldInitializer>> initializers = new EnumMap<>(ResourceType.class);
    for (String typeName : symbols.rowKeySet()) {
        ResourceType resourceType = ResourceType.getEnum(typeName);
        Preconditions.checkNotNull(resourceType);
        initializers.put(resourceType, getInitializers(typeName, symbols, values));
    }/*from   w w  w .  ja v  a2 s .  c o  m*/
    return initializers;
}

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

/**
 * export excel//from  ww  w  .  ja  v  a 2s.c o m
 * 
 * @param sheetName sheet name
 * @param table table
 * @return Workbook
*/
@SuppressWarnings("PMD.ShortVariable")
private static Workbook exportExcel(String sheetName, Table<Integer, String, String> table) {
    Set<Integer> tableRows = table.rowKeySet();
    Set<String> tableColumns = table.columnKeySet();
    // excel
    Workbook wb = new HSSFWorkbook();

    // sheet??
    Sheet sheet = wb.createSheet(sheetName);
    // ???n?
    /*for (int i = 0; i < keys.length; i++) {
    sheet.setColumnWidth((short) i, (short) (35.7 * 150));
    }*/

    // 
    Row row = sheet.createRow((short) 0);

    // ???
    CellStyle cs = wb.createCellStyle();
    CellStyle cs2 = wb.createCellStyle();

    // ?
    Font f1 = wb.createFont();
    Font f2 = wb.createFont();

    // ????
    f1.setFontHeightInPoints((short) 10);
    f1.setColor(IndexedColors.BLACK.getIndex());
    f1.setBold(true);

    // ??
    f2.setFontHeightInPoints((short) 10);
    f2.setColor(IndexedColors.BLACK.getIndex());

    // Font f3=wb.createFont();
    // f3.setFontHeightInPoints((short) 10);
    // f3.setColor(IndexedColors.RED.getIndex());

    // ?????
    cs.setFont(f1);
    cs.setBorderLeft(BorderStyle.THIN);
    cs.setBorderRight(BorderStyle.THIN);
    cs.setBorderTop(BorderStyle.THIN);
    cs.setBorderBottom(BorderStyle.THIN);
    cs.setAlignment(HorizontalAlignment.CENTER);

    // ???
    cs2.setFont(f2);
    cs2.setBorderLeft(BorderStyle.THIN);
    cs2.setBorderRight(BorderStyle.THIN);
    cs2.setBorderTop(BorderStyle.THIN);
    cs2.setBorderBottom(BorderStyle.THIN);
    cs2.setAlignment(HorizontalAlignment.CENTER);
    // ??
    int i = 0;
    for (String tableColumn : tableColumns) {
        Cell cell = row.createCell(i);
        cell.setCellValue(tableColumn);
        cell.setCellStyle(cs);
        i++;
    }
    // ??
    for (Integer tableRow : tableRows) {
        // Row ,Cell  , Row  Cell 0
        // sheet
        checkArgument(tableRow > 0, "Row index must be greater than zero!");
        Row row1 = sheet.createRow(tableRow);
        // row
        Map<String, String> item = table.row(tableRow);
        int j = 0;
        for (Map.Entry<String, String> entry : item.entrySet()) {
            //            for(String v:item.keySet()){
            //                System.out.println(tableRow + "-" + v + "-" + item.get(v));
            Cell cell = row1.createCell(j);
            cell.setCellValue(entry.getValue());
            cell.setCellStyle(cs2);
            j++;
        }
    }
    return wb;
}