Java Code Examples for com.google.common.collect.ArrayTable#create()
The following examples show how to use
com.google.common.collect.ArrayTable#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuavaTableUnitTest.java From tutorials with MIT License | 6 votes |
@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); }
Example 2
Source File: DataMiningFacadeHistodb.java From ipst with Mozilla Public License 2.0 | 5 votes |
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); }
Example 3
Source File: RedisPermissionsRepository.java From fiat with Apache License 2.0 | 5 votes |
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; }
Example 4
Source File: TradeReportFormatterTest.java From Strata with Apache License 2.0 | 5 votes |
@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)); }
Example 5
Source File: TradeReportFormatterTest.java From Strata with Apache License 2.0 | 5 votes |
@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)); }
Example 6
Source File: TradeReportFormatterTest.java From Strata with Apache License 2.0 | 5 votes |
@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)); }
Example 7
Source File: ExpressionUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
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); }