类com.google.common.collect.ArrayTable源码实例Demo

下面列出了怎么用com.google.common.collect.ArrayTable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ipst   文件: FEAMatFileWriter.java
private MLDouble histoDataAsMLDouble(String name, ArrayTable<Integer, String, Float> histoData) {
    int rowsSize = histoData.rowKeySet().size();
    int colsSize = histoData.columnKeySet().size();
    MLDouble mlDouble = new MLDouble(name, new int[] {rowsSize, colsSize});
    int i = 0;
    for (Integer rowKey : histoData.rowKeyList()) {
        int j = 0;
        for (String colkey : histoData.columnKeyList()) {
            Float v = histoData.get(rowKey, colkey);
            mlDouble.set(new Double(v), i, j);
            j++;
        }
        i++;
    }
    return mlDouble;
}
 
源代码2 项目: ipst   文件: Utils.java
public static double[][] histoDataAsDoubleMatrixNew(ArrayTable<Integer, String, Float> hdTable) {
    int rowsSize = hdTable.rowKeySet().size();
    int colsSize = hdTable.columnKeySet().size();
    double[][] matFinal = new double[rowsSize][colsSize];
    int i = 0;
    for (Integer rowKey : hdTable.rowKeyList()) {
        int j = 0;
        for (String colkey : hdTable.columnKeyList()) {
            Float v = hdTable.get(rowKey, colkey);
            matFinal[i][j] = getCleanFloat(v);
            j = j + 1;
        }
        i = i + 1;
    }
    return matFinal;
}
 
源代码3 项目: tutorials   文件: GuavaTableUnitTest.java
@Test
public void givenArrayTable_whenGet_returnsSuccessfully() {
    final List<String> universityRowTable = Lists.newArrayList("Mumbai", "Harvard");
    final List<String> courseColumnTables = Lists.newArrayList("Chemical", "IT", "Electrical");
    final Table<String, String, Integer> universityCourseSeatTable = ArrayTable.create(universityRowTable, courseColumnTables);
    universityCourseSeatTable.put("Mumbai", "Chemical", 120);
    universityCourseSeatTable.put("Mumbai", "IT", 60);
    universityCourseSeatTable.put("Harvard", "Electrical", 60);
    universityCourseSeatTable.put("Harvard", "IT", 120);

    final int seatCount = universityCourseSeatTable.get("Mumbai", "IT");

    assertThat(seatCount).isEqualTo(60);
}
 
源代码4 项目: ipst   文件: ForecastErrorsHistoricalData.java
public ForecastErrorsHistoricalData(List<String> generatorsIds, List<String> loadsIds,
                                    List<StochasticVariable> stochasticVariables,
                                    ArrayTable<Integer, String, Float> forecastsData,
                                    ArrayTable<Integer, String, Float> snapshotsData) {
    this.generatorsIds = generatorsIds;
    this.loadsIds = loadsIds;
    this.stochasticVariables = stochasticVariables;
    this.forecastsData = forecastsData;
    this.snapshotsData = snapshotsData;
}
 
源代码5 项目: ipst   文件: Wp41HistoData.java
public Wp41HistoData(List<String> historicalGensIds,
                     List<String> historicalLoadsIds,
                     List<String> historicalDanglingLinesIds,
                     ArrayTable<Integer, String, Float> hdTable) {
    this.historicalGensIds = historicalGensIds;
    this.historicalLoadsIds = historicalLoadsIds;
    this.historicalDanglingLinesIds = historicalDanglingLinesIds;
    this.hdTable = hdTable;
}
 
源代码6 项目: ipst   文件: DataMiningFacadeHistodb.java
private Wp41HistoData parseData(DataMiningFacadeParams dmParams) throws IOException, InterruptedException {
    int rowCount = histoClient.queryCount(dmParams.getInterval(), HistoDbHorizon.SN);

    Set<HistoDbAttributeId> attributeIds = new LinkedHashSet<>((dmParams.getGensIds().size() +
                                                                dmParams.getLoadsIds().size() +
                                                                dmParams.getDanglingLinesIds().size()) * 2); // gens P, Q loads P, Q danglingLines P0, Q0
    for (String genId : dmParams.getGensIds()) {
        attributeIds.add(new HistoDbNetworkAttributeId(genId, HistoDbAttr.P));
        attributeIds.add(new HistoDbNetworkAttributeId(genId, HistoDbAttr.Q));
    }
    for (String loadId : dmParams.getLoadsIds()) {
        attributeIds.add(new HistoDbNetworkAttributeId(loadId, HistoDbAttr.P));
        attributeIds.add(new HistoDbNetworkAttributeId(loadId, HistoDbAttr.Q));
    }
    for (String dlId : dmParams.getDanglingLinesIds()) {
        attributeIds.add(new HistoDbNetworkAttributeId(dlId, HistoDbAttr.P0));
        attributeIds.add(new HistoDbNetworkAttributeId(dlId, HistoDbAttr.Q0));
    }

    List<Integer> rowIndexes;
    try (IntStream intStream = IntStream.range(0, rowCount)) {
        rowIndexes = intStream.boxed().collect(Collectors.toList());
    }
    List<String> colIndexes = attributeIds.stream().map(Object::toString).collect(Collectors.toList());

    ArrayTable<Integer, String, Float> hdTable = ArrayTable.create(rowIndexes, colIndexes);

    // parse csv generators
    try (InputStream is = histoClient.queryCsv(HistoQueryType.data, attributeIds, dmParams.getInterval(), HistoDbHorizon.SN, false, false)) {
        parseCsv(is, attributeIds, hdTable, rowCount);
    }

    return new Wp41HistoData(dmParams.getGensIds(), dmParams.getLoadsIds(), dmParams.getDanglingLinesIds(), hdTable);
}
 
源代码7 项目: ipst   文件: Utils.java
public static double[][] histoDataAsDoubleMatrix(ArrayTable<Integer, String, Float> hdTable) {

        int rowsSize = hdTable.rowKeySet().size();
        int colsSize = hdTable.columnKeySet().size();
        double[][] matFinal = new double[rowsSize][colsSize];
        for (int i = 0; i < rowsSize; i++) {
            for (int j = 0; j < colsSize; j++) {
                Float v = hdTable.get(i, j);
                matFinal[i][j] = getCleanFloat(v);
            }
        }
        return matFinal;
    }
 
源代码8 项目: fiat   文件: RedisPermissionsRepository.java
private Table<String, ResourceType, Response<Map<String, String>>> getAllFromRedis(
    Set<String> userIds) {
  if (userIds.size() == 0) {
    return HashBasedTable.create();
  }

  try {
    final Table<String, ResourceType, Response<Map<String, String>>> responseTable =
        ArrayTable.create(
            userIds,
            new ArrayIterator<>(
                resources.stream().map(Resource::getResourceType).toArray(ResourceType[]::new)));
    for (List<String> userIdSubset : Lists.partition(new ArrayList<>(userIds), 10)) {
      redisClientDelegate.withMultiKeyPipeline(
          p -> {
            for (String userId : userIdSubset) {
              resources.stream()
                  .map(Resource::getResourceType)
                  .forEach(
                      r -> {
                        responseTable.put(userId, r, p.hgetAll(userKey(userId, r)));
                      });
            }
            p.sync();
          });
    }
    return responseTable;
  } catch (Exception e) {
    log.error("Storage exception reading all entries.", e);
  }
  return null;
}
 
源代码9 项目: Strata   文件: TradeReportFormatterTest.java
@Test
public void getColumnTypes() {
  ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(INDICES, INDICES);
  table.put(0, 0, Result.success(1));
  table.put(0, 1, Result.success("abc"));
  table.put(1, 0, Result.success(2));
  table.put(1, 1, Result.success("def"));

  List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
  assertThat(columnTypes).isEqualTo(ImmutableList.of(Integer.class, String.class));
}
 
源代码10 项目: Strata   文件: TradeReportFormatterTest.java
@Test
public void getColumnTypesWithSomeFailures() {
  ImmutableList<Integer> indices = ImmutableList.of(0, 1);
  ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(indices, indices);
  table.put(0, 0, Result.failure(FailureReason.ERROR, "fail"));
  table.put(0, 1, Result.failure(FailureReason.ERROR, "fail"));
  table.put(1, 0, Result.success(2));
  table.put(1, 1, Result.success("def"));

  List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
  assertThat(columnTypes).isEqualTo(ImmutableList.of(Integer.class, String.class));
}
 
源代码11 项目: Strata   文件: TradeReportFormatterTest.java
@Test
public void getColumnTypesWithAllFailures() {
  ImmutableList<Integer> indices = ImmutableList.of(0, 1);
  ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(indices, indices);
  table.put(0, 0, Result.failure(FailureReason.ERROR, "fail"));
  table.put(0, 1, Result.failure(FailureReason.ERROR, "fail"));
  table.put(1, 0, Result.failure(FailureReason.ERROR, "fail"));
  table.put(1, 1, Result.failure(FailureReason.ERROR, "fail"));

  List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
  assertThat(columnTypes).isEqualTo(ImmutableList.of(Object.class, Object.class));
}
 
源代码12 项目: Strata   文件: TradeReportFormatterTest.java
private TradeReport report(ArrayTable<Integer, Integer, Result<?>> table) {
  return TradeReport.builder()
      .columns(
          TradeReportColumn.builder().header("col0").build(),
          TradeReportColumn.builder().header("col1").build())
      .data(table)
      .valuationDate(LocalDate.now(ZoneOffset.UTC))
      .runInstant(Instant.now())
      .build();
}
 
源代码13 项目: jpmml-evaluator   文件: ExpressionUtilTest.java
static
InlineTable createInlineTable(List<List<String>> rows, List<String> columns){
	List<Integer> rowKeys = new ArrayList<>();

	for(int i = 0; i < rows.size(); i++){
		rowKeys.add(i + 1);
	}

	Table<Integer, String, String> table = ArrayTable.create(rowKeys, columns);

	for(int i = 0; i < rows.size(); i++){
		List<String> row = rows.get(i);

		for(int j = 0; j < columns.size(); j++){
			String column = columns.get(j);
			String value = row.get(j);

			if(value == null){
				continue;
			}

			table.put(rowKeys.get(i), column, value);
		}
	}

	return InlineTableUtil.format(table);
}
 
源代码14 项目: ipst   文件: ForecastErrorsHistoricalData.java
public ArrayTable<Integer, String, Float> getForecastsData() {
    return forecastsData;
}
 
源代码15 项目: ipst   文件: ForecastErrorsHistoricalData.java
public ArrayTable<Integer, String, Float> getSnapshotsData() {
    return snapshotsData;
}
 
源代码16 项目: ipst   文件: Wp41HistoData.java
public ArrayTable<Integer, String, Float> getHdTable() {
    return hdTable;
}
 
 同包方法