当前位置: 首页>>代码示例>>Java>>正文


Java Table.columnKeySet方法代码示例

本文整理汇总了Java中com.google.common.collect.Table.columnKeySet方法的典型用法代码示例。如果您正苦于以下问题:Java Table.columnKeySet方法的具体用法?Java Table.columnKeySet怎么用?Java Table.columnKeySet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.Table的用法示例。


在下文中一共展示了Table.columnKeySet方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.google.common.collect.Table; //导入方法依赖的package包/类
public static void main(String[] args) {
    String[] names = {"Bob", "Alice", "Andy", "Carol", "Ben"};

    // Table of names
    Table<Character, Integer, String> table = HashBasedTable.create();

    // First letter is a row key, length is a column key
    for (String name : names) {
        table.put(name.charAt(0), name.length(), name);
    }

    // Value corresponding to the given row and column keys
    table.get('A', 5); // -> Alice
    table.get('B', 3); // -> Ben

    // Set of column keys that have one or more values in the table
    table.columnKeySet(); // -> [4, 5, 3]

    // View of all mappings that have the given row key
    table.row('A'); // -> {4=Andy, 5=Alice}

}
 
开发者ID:alxsimo,项目名称:guava-demo,代码行数:23,代码来源:TableSample.java

示例2: formatValues

import com.google.common.collect.Table; //导入方法依赖的package包/类
private static Map<String, Object> formatValues(Calendar time, Table<Calendar, String, Object> tableNO2) {
    Map<String,Object> values = new HashMap<>();
    for(String column : tableNO2.columnKeySet()) {
        if (tableNO2.contains(time,column)) {
            Object value = tableNO2.get(time,column);
            values.put(column,value);
        }
    }
    return values;
}
 
开发者ID:medialab-prado,项目名称:puremadrid,代码行数:11,代码来源:Parser.java

示例3: tableToCsv

import com.google.common.collect.Table; //导入方法依赖的package包/类
/**
 * Converts Guava table to a CSV table
 *
 * @param table                   table
 * @param csvFormat               CSV format
 * @param missingValuePlaceholder print if a value is missing (empty string by default)
 * @param <T>                     object type (string)
 * @return table
 * @throws IOException exception
 */
public static <T> String tableToCsv(Table<String, String, T> table, CSVFormat csvFormat,
        String missingValuePlaceholder)
        throws IOException
{
    StringWriter sw = new StringWriter();
    CSVPrinter printer = new CSVPrinter(sw, csvFormat);

    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()) {
            T value = table.get(rowKey, columnKey);

            if (value == null) {
                printer.print(missingValuePlaceholder);
            }
            else {
                printer.print(value);
            }
        }
        printer.println();
    }

    printer.close();

    return sw.toString();
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:42,代码来源:TableUtils.java

示例4: toTable

import com.google.common.collect.Table; //导入方法依赖的package包/类
@Override
public tech.tablesaw.api.Table toTable() {

    Table<String, String, Integer> sortedTable = sortedTable();

    tech.tablesaw.api.Table t = tech.tablesaw.api.Table.create("Confusion Matrix");
    t.addColumn(new CategoryColumn(""));

    for (String label : sortedTable.rowKeySet()) {
        t.addColumn(new IntColumn(label));
        t.column(0).appendCell("Predicted " + label);
    }

    int n = 0;
    for (String rowLabel : sortedTable.rowKeySet()) {
        int c = 1;
        for (String colLabel : sortedTable.columnKeySet()) {
            Integer value = sortedTable.get(rowLabel, colLabel);
            if (value == null) {
                t.intColumn(c).append(0);
            } else {
                t.intColumn(c).append(value);
                n = n + value;
            }
            c++;
        }
    }
    t.column(0).setName("n = " + n);
    for (int col = 1; col <= sortedTable.columnKeySet().size(); col++) {
        t.column(col).setName("Actual " + t.column(col).name());
    }
    return t;
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:34,代码来源:CategoryConfusionMatrix.java

示例5: processCosts

import com.google.common.collect.Table; //导入方法依赖的package包/类
private static void processCosts(Connection connection, JsonWriter writer)
    throws IOException, SQLException {
  writer.name("costs").beginObject();

  PreparedStatement stmt = connection.prepareStatement(
      "select year, type, sum(cost) from "
      + "(SELECT c.cost, YEAR(DATEADD('SECOND', e.start/ 1000 , DATE '1970-01-01')) as year, "
      + "e.type FROM ENCOUNTER e, CLAIM c where e.id = c.encounter_id) group by year, type "
      + "order by year asc");
  ResultSet rs = stmt.executeQuery();

  Table<Integer, String, BigDecimal> table = HashBasedTable.create();

  int firstYear = 0;
  int lastYear = 0;

  while (rs.next()) {
    int year = rs.getInt(1);
    String type = rs.getString(2);
    BigDecimal total = rs.getBigDecimal(3);

    if (firstYear == 0) {
      firstYear = year;
    }
    lastYear = year;

    table.put(year, type, total);
  }

  writer.name("first_year").value(firstYear);

  for (String encType : table.columnKeySet()) {
    writer.name(encType).beginArray();

    for (int y = firstYear; y <= lastYear; y++) {
      BigDecimal count = table.get(y, encType);
      if (count == null) {
        count = BigDecimal.ZERO;
      }
      writer.value(count);
    }
    writer.endArray(); // encType
  }

  writer.endObject(); // costs
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:47,代码来源:ReportExporter.java

示例6: serialize

import com.google.common.collect.Table; //导入方法依赖的package包/类
@Override
public JsonElement serialize(Table src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject object = new JsonObject();

    //columns
    JsonArray jsonColsArray = new JsonArray();
    jsonColsArray.add("DATE");
    for(Object col:src.columnKeySet()) {
        jsonColsArray.add(col.toString());
    }
    object.add("columns",jsonColsArray);

    //data
    JsonArray jsonRowsArray = new JsonArray();
    Set<Date> rowKeys = src.rowKeySet();

    for(Object rkey: rowKeys){

        JsonArray rowCols = new JsonArray();

        if(rkey instanceof Date)
            rowCols.add(DateUtils.DRONZE_DATE.format(rkey));
        else if(rkey instanceof String)
            rowCols.add(rkey.toString());

        //offset 1 for the date column
        for (int j = 1; j < jsonColsArray.size(); j++) {
            Object o = src.get(rkey, jsonColsArray.get(j).toString().replace("\"",""));
            if(o!=null){
                if (o.getClass() == Integer.class) {
                    rowCols.add((Integer) o);
                }
                else if (o.getClass() == String.class) {
                    rowCols.add(o.toString());
                }
                else if (o.getClass() == Float.class) {
                    rowCols.add((Float)o);
                }
                else if (o.getClass() == Double.class) {
                    rowCols.add((Double)o);
                }
                else if (o.getClass() == BigDecimal.class) {
                    rowCols.add((BigDecimal)o);
                }
                else if (o.getClass() == Date.class) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    rowCols.add(sdf.format(o));
                }
            } else {
                rowCols.add((String)null);
            }

        }
        jsonRowsArray.add(rowCols);

    }

    object.add("data",jsonRowsArray);

    return object;

}
 
开发者ID:claytantor,项目名称:blueweave,代码行数:63,代码来源:GuavaTableSerializer.java


注:本文中的com.google.common.collect.Table.columnKeySet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。