Java Code Examples for com.google.common.collect.Tables

The following are top voted examples for showing how to use com.google.common.collect.Tables. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: cc-analysis   File: AnalysisTestHelper.java   View source code 5 votes vote down vote up
public static void printResultOfTokenStream(PrintStream out, TokenStream ts) throws IOException {
	CharTermAttribute termAttr = ts.getAttribute(CharTermAttribute.class);
	TypeAttribute typeAttr = ts.getAttribute(TypeAttribute.class);
	OffsetAttribute offAttr = ts.getAttribute(OffsetAttribute.class);
	PositionIncrementAttribute posIncAttr = ts.getAttribute(PositionIncrementAttribute.class);
	PositionLengthAttribute posLenAttr = ts.getAttribute(PositionLengthAttribute.class);
	ts.reset();
	Table<String, String, String> contentTable = Tables.newCustomTable(new LinkedHashMap<String, Map<String, String>>(),
			new Supplier<Map<String, String>>() {
				@Override
				public Map<String, String> get() {
					return Maps.newLinkedHashMap();
				}
			});
	int lineNo = 1;
	int pos = 0;
	while (ts.incrementToken()) {
		String lineId = lineNo + ".";
		contentTable.put(lineId, "term", termAttr.toString());
		contentTable.put(lineId, "type", typeAttr.type());
		contentTable.put(lineId, "startOffset", offAttr.startOffset() + "");
		contentTable.put(lineId, "endOffset", offAttr.endOffset() + "");
		contentTable.put(lineId, "posInc", posIncAttr.getPositionIncrement() + "");
		contentTable.put(lineId, "posLen", posLenAttr.getPositionLength() + "");
		pos += posIncAttr.getPositionIncrement();
		contentTable.put(lineId, "pos", pos + "");

		lineNo++;
	}
	printTable(out, contentTable);
}
 
Example 2
Project: gerrit   File: ChangeNotesParser.java   View source code 5 votes vote down vote up
private ChangeNotesState buildState() {
  return ChangeNotesState.create(
      tip.copy(),
      id,
      new Change.Key(changeId),
      createdOn,
      lastUpdatedOn,
      ownerId,
      branch,
      buildCurrentPatchSetId(),
      subject,
      topic,
      originalSubject,
      submissionId,
      assignee != null ? assignee.orElse(null) : null,
      status,
      Sets.newLinkedHashSet(Lists.reverse(pastAssignees)),
      hashtags,
      patchSets,
      buildApprovals(),
      ReviewerSet.fromTable(Tables.transpose(reviewers)),
      ReviewerByEmailSet.fromTable(Tables.transpose(reviewersByEmail)),
      pendingReviewers,
      pendingReviewersByEmail,
      allPastReviewers,
      buildReviewerUpdates(),
      submitRecords,
      buildAllMessages(),
      buildMessagesByPatchSet(),
      comments,
      readOnlyUntil,
      isPrivate,
      workInProgress,
      hasReviewStarted,
      revertOf);
}
 
Example 3
Project: gerrit   File: ChangeNotesParser.java   View source code 5 votes vote down vote up
private void parseWorkInProgress(ChangeNotesCommit commit) throws ConfigInvalidException {
  String raw = parseOneFooter(commit, FOOTER_WORK_IN_PROGRESS);
  if (raw == null) {
    // No change to WIP state in this revision.
    previousWorkInProgressFooter = null;
    return;
  } else if (Boolean.TRUE.toString().equalsIgnoreCase(raw)) {
    // This revision moves the change into WIP.
    previousWorkInProgressFooter = true;
    if (workInProgress == null) {
      // Because this is the first time workInProgress is being set, we know
      // that this change's current state is WIP. All the reviewer updates
      // we've seen so far are pending, so take a snapshot of the reviewers
      // and reviewersByEmail tables.
      pendingReviewers =
          ReviewerSet.fromTable(Tables.transpose(ImmutableTable.copyOf(reviewers)));
      pendingReviewersByEmail =
          ReviewerByEmailSet.fromTable(Tables.transpose(ImmutableTable.copyOf(reviewersByEmail)));
      workInProgress = true;
    }
    return;
  } else if (Boolean.FALSE.toString().equalsIgnoreCase(raw)) {
    previousWorkInProgressFooter = false;
    hasReviewStarted = true;
    if (workInProgress == null) {
      workInProgress = false;
    }
    return;
  }
  throw invalidFooter(FOOTER_WORK_IN_PROGRESS, raw);
}
 
Example 4
Project: db-table   File: TableCellMapper.java   View source code 5 votes vote down vote up
@Override
public Table.Cell<R, C, V> map(int index, ResultSet r, StatementContext ctx) throws SQLException {
    return Tables.immutableCell(
            rowMapper.map(index, r, ctx),
            columnMapper.map(index, r, ctx),
            valueMapper.map(index, r, ctx)
    );
}
 
Example 5
Project: RuneCraftery   File: GameData.java   View source code 5 votes vote down vote up
public static void buildModObjectTable()
{
    if (modObjectTable != null)
    {
        throw new IllegalStateException("Illegal call to buildModObjectTable!");
    }

    Map<Integer, Cell<String, String, Integer>> map = Maps.transformValues(idMap, new Function<ItemData,Cell<String,String,Integer>>() {
        public Cell<String,String,Integer> apply(ItemData data)
        {
            if ("Minecraft".equals(data.getModId()) || !data.isOveridden())
            {
                return null;
            }
            return Tables.immutableCell(data.getModId(), data.getItemType(), data.getItemId());
        }
    });

    Builder<String, String, Integer> tBuilder = ImmutableTable.builder();
    for (Cell<String, String, Integer> c : map.values())
    {
        if (c!=null)
        {
            tBuilder.put(c);
        }
    }
    modObjectTable = tBuilder.build();
}
 
Example 6
Project: RuneCraftery   File: GameData.java   View source code 5 votes vote down vote up
public static void buildModObjectTable()
{
    if (modObjectTable != null)
    {
        throw new IllegalStateException("Illegal call to buildModObjectTable!");
    }

    Map<Integer, Cell<String, String, Integer>> map = Maps.transformValues(idMap, new Function<ItemData,Cell<String,String,Integer>>() {
        public Cell<String,String,Integer> apply(ItemData data)
        {
            if ("Minecraft".equals(data.getModId()) || !data.isOveridden())
            {
                return null;
            }
            return Tables.immutableCell(data.getModId(), data.getItemType(), data.getItemId());
        }
    });

    Builder<String, String, Integer> tBuilder = ImmutableTable.builder();
    for (Cell<String, String, Integer> c : map.values())
    {
        if (c!=null)
        {
            tBuilder.put(c);
        }
    }
    modObjectTable = tBuilder.build();
}
 
Example 7
Project: BetterNutritionMod   File: GameData.java   View source code 5 votes vote down vote up
public static void buildModObjectTable()
{
    if (modObjectTable != null)
    {
        throw new IllegalStateException("Illegal call to buildModObjectTable!");
    }

    Map<Integer, Cell<String, String, Integer>> map = Maps.transformValues(idMap, new Function<ItemData,Cell<String,String,Integer>>() {
        public Cell<String,String,Integer> apply(ItemData data)
        {
            if ("Minecraft".equals(data.getModId()) || !data.isOveridden())
            {
                return null;
            }
            return Tables.immutableCell(data.getModId(), data.getItemType(), data.getItemId());
        }
    });

    Builder<String, String, Integer> tBuilder = ImmutableTable.builder();
    for (Cell<String, String, Integer> c : map.values())
    {
        if (c!=null)
        {
            tBuilder.put(c);
        }
    }
    modObjectTable = tBuilder.build();
}
 
Example 8
Project: LD-FusionTool   File: LDFusionToolCRUtils.java   View source code 5 votes vote down vote up
/**
 * Creates a new HashMap backed {@link Table}.
 */
public static <R, C, V> Table<R, C, V> newHashTable() {
    return Tables.newCustomTable(
            new HashMap<R, Map<C, V>>(),
            new Supplier<Map<C, V>>() {
                @Override
                public Map<C, V> get() {
                    return new HashMap<>();
                }
            }
    );
}
 
Example 9
Project: azure-table   File: CellSetMutableView.java   View source code 5 votes vote down vote up
@Override
public Table.Cell<Bytes, Bytes, Bytes> apply(AzureEntity input) {
    return Tables.immutableCell(
            decode(input.getPartitionKey()),
            decode(input.getRowKey()),
            decode(input.getValue()));
}
 
Example 10
Project: azure-table   File: CellSetMutableViewTest.java   View source code 5 votes vote down vote up
@Test
public void contains_delegates_to_table() {
    Object o1 = new Object();
    Object o2 = new Object();
    Table.Cell<Object, Object, Object> cell = Tables.immutableCell(o1, o2, new Object());
    when(baseAzureTable.contains(o1, o2)).thenReturn(true);

    assertThat(set.contains(cell), is(equalTo(true)));
}
 
Example 11
Project: incubator-provisionr   File: ImageTable.java   View source code 5 votes vote down vote up
static Iterable<Table.Cell<String, String, String>> combineHeadersWithLinePartsAsTableCells(
    int index, Iterable<String> headers, Iterable<String> lineParts
) {
    final String rowKey = "" + index;
    return transform(zip(headers, lineParts),
        new Function<Map.Entry<String, String>, Table.Cell<String, String, String>>() {
            @Override
            public Table.Cell<String, String, String> apply(Map.Entry<String, String> entry) {
                checkNotNull(entry, "entry is null");
                return Tables.immutableCell(rowKey, entry.getKey(), entry.getValue());
            }
        });
}
 
Example 12
Project: incubator-provisionr   File: ImageTableTest.java   View source code 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testCombineHeadersWithLinePartsAsTableCells() {
    final ImmutableList<String> headers = ImmutableList.of("a", "b");
    final ImmutableList<String> lineParts = ImmutableList.of("1", "2");

    Iterable<Table.Cell<String, String, String>> cells =
        ImageTable.combineHeadersWithLinePartsAsTableCells(0, headers, lineParts);

    assertThat(cells).contains(Tables.immutableCell("0", "a", "1"));
}
 
Example 13
Project: yammer-collections   File: TransformingTable.java   View source code 5 votes vote down vote up
@Override
public Cell<R1, C1, V1> apply(Cell<R, C, V> input) {
    return Tables.immutableCell(
            toRowFunction.apply(input.getRowKey()),
            toColumnFunction.apply(input.getColumnKey()),
            toValueFunction.apply(input.getValue())
    );
}
 
Example 14
Project: yammer-collections   File: TransformingTable.java   View source code 5 votes vote down vote up
@Override
public Cell<R, C, V> apply(Cell<R1, C1, V1> input) {
    return Tables.immutableCell(
            fromRowFunction.apply(input.getRowKey()),
            fromColumnFunction.apply(input.getColumnKey()),
            fromValueFunction.apply(input.getValue())
    );
}
 
Example 15
Project: yammer-collections   File: TransformingTableTest.java   View source code 5 votes vote down vote up
public void cellSet_delegates_to_backing_table() {
    Set<Table.Cell<String, String, String>> cellSet = Collections.singleton(Tables.immutableCell(STRING_ROW_KEY_1, STRING_COLUMN_KEY_1, STRING_VALUE_1));
    when(backingTableMock.cellSet()).thenReturn(cellSet);

    Table.Cell<Float, Long, Integer> expectedCell = Tables.immutableCell(ROW_KEY_1, COLUMN_KEY_1, VALUE_1);

    //noinspection unchecked
    assertThat(transformingTable.cellSet(), containsInAnyOrder(expectedCell));
}
 
Example 16
Project: ProjectAres   File: TableView.java   View source code 4 votes vote down vote up
@Override
public Set<Cell<R, C, V>> cellSet() {
    return new AbstractSet<Cell<R, C, V>>() {
        @Override
        public int size() {
            return TableView.this.size();
        }

        @Override
        public boolean isEmpty() {
            return TableView.this.isEmpty();
        }

        @Override
        public boolean contains(Object o) {
            if(!(o instanceof Cell)) return false;
            final Cell cell = (Cell) o;
            return Objects.equals(get(cell.getRowKey(), cell.getColumnKey()), cell.getValue());
        }

        @Override
        public Stream<Cell<R, C, V>> stream() {
            return map.entrySet()
                      .stream()
                      .flatMap(row -> row.getValue()
                                         .entrySet()
                                         .stream()
                                         .map(col -> Tables.immutableCell(row.getKey(),
                                                                          col.getKey(),
                                                                          col.getValue())));
        }

        @Override
        public Spliterator<Cell<R, C, V>> spliterator() {
            return stream().spliterator();
        }

        @Override
        public Iterator<Cell<R, C, V>> iterator() {
            return Spliterators.iterator(spliterator());
        }
    };
}
 
Example 17
Project: Blur   File: BasicMetadataStorage.java   View source code 4 votes vote down vote up
@Nonnull
@Override
public Table<HOLDER, Class<Object>, Object> getAll() {
    return Tables.unmodifiableTable(metadata);
}
 
Example 18
Project: Rapture   File: ReflexSparseMatrixValue.java   View source code 4 votes vote down vote up
public ReflexSparseMatrixValue transpose() {
    ReflexSparseMatrixValue ret = new ReflexSparseMatrixValue(2);
    ret.table = Tables.transpose(table);
    return ret;
}
 
Example 19
Project: Blur   File: BasicMetadataStorage.java   View source code 4 votes vote down vote up
@Nonnull
@Override
public Table<HOLDER, Class<Object>, Object> getAll() {
    return Tables.unmodifiableTable(metadata);
}
 
Example 20
Project: owsi-core-parent   File: Functions2.java   View source code 4 votes vote down vote up
@Override
public Table<R, C, V> apply(Table<? extends R, ? extends C, ? extends V> input) {
	return input == null ? null : Tables.unmodifiableTable(input);
}
 
Example 21
Project: bazel   File: PhaseVfsStatistics.java   View source code 4 votes vote down vote up
public PhaseVfsStatistics(ProfilePhase phase) {
  this.phase = phase;
  this.statistics =
      Tables.newCustomTable(
          new EnumMap<ProfilerTask, Map<String, Stat>>(ProfilerTask.class), HashMap::new);
}
 
Example 22
Project: jpmml-evaluator   File: InlineTableUtil.java   View source code 4 votes vote down vote up
@Override
public Table<Integer, String, String> load(InlineTable inlineTable){
	return Tables.unmodifiableTable(parse(inlineTable));
}
 
Example 23
Project: azure-table   File: RowViewTest.java   View source code 4 votes vote down vote up
@Test
public void contains_value_returns_false_if_does_not_contain_value_in_row() throws StorageException {
    setAzureTableToContain(Tables.immutableCell(ROW_KEY_1, OTHER_COLUMN_KEY, VALUE_1));

    assertThat(rowView.containsValue(VALUE_1), is(equalTo(false)));
}
 
Example 24
Project: azure-table   File: ColumnViewTest.java   View source code 4 votes vote down vote up
@Test
public void contains_value_returns_false_if_does_not_contain_value_in_row() throws StorageException {
    setAzureTableToContain(Tables.immutableCell(OTHER_ROW_KEY, COLUMN_KEY_1, VALUE_1));

    assertThat(columnView.containsValue(VALUE_1), is(equalTo(false)));
}
 
Example 25
Project: mondo-integration   File: EffectiveMetamodelRuleset.java   View source code 2 votes vote down vote up
/**
 * Returns an unmodifiable view of the table of inclusion rules: rows are
 * metamodel URIs, columns are type names or WILDCARD (meaning all types in
 * the metamodel) and cells are either sets of slot names or a singleton set
 * with WILDCARD (meaning "all"). An empty table means "include everything".
 */
public Table<String, String, ImmutableSet<String>> getInclusionRules() {
	return Tables.unmodifiableTable(inclusions);
}
 
Example 26
Project: mondo-integration   File: EffectiveMetamodelRuleset.java   View source code 2 votes vote down vote up
/**
 * Returns an unmodifiable view of the table of exclusion rules: rows are
 * metamodel URIs, columns are type names and cells are either sets of slot
 * names or a singleton set with WILDCARD (meaning "all"). An empty table
 * means "exclude nothing".
 */
public Table<String, String, ImmutableSet<String>> getExclusionRules() {
	return Tables.unmodifiableTable(exclusions);
}
 
Example 27
Project: mondo-hawk   File: EffectiveMetamodelRuleset.java   View source code 2 votes vote down vote up
/**
 * Returns an unmodifiable view of the table of inclusion rules: rows are
 * metamodel URIs, columns are type names or WILDCARD (meaning all types in
 * the metamodel) and cells are either sets of slot names or a singleton set
 * with WILDCARD (meaning "all"). An empty table means "include everything".
 */
public Table<String, String, ImmutableSet<String>> getInclusionRules() {
	return Tables.unmodifiableTable(inclusions);
}
 
Example 28
Project: mondo-hawk   File: EffectiveMetamodelRuleset.java   View source code 2 votes vote down vote up
/**
 * Returns an unmodifiable view of the table of exclusion rules: rows are
 * metamodel URIs, columns are type names and cells are either sets of slot
 * names or a singleton set with WILDCARD (meaning "all"). An empty table
 * means "exclude nothing".
 */
public Table<String, String, ImmutableSet<String>> getExclusionRules() {
	return Tables.unmodifiableTable(exclusions);
}
 
Example 29
Project: mondo-collab-framework   File: EffectiveMetamodelRuleset.java   View source code 2 votes vote down vote up
/**
 * Returns an unmodifiable view of the table of inclusion rules: rows are
 * metamodel URIs, columns are type names or WILDCARD (meaning all types in
 * the metamodel) and cells are either sets of slot names or a singleton set
 * with WILDCARD (meaning "all"). An empty table means "include everything".
 */
public Table<String, String, ImmutableSet<String>> getInclusionRules() {
	return Tables.unmodifiableTable(inclusions);
}
 
Example 30
Project: mondo-collab-framework   File: EffectiveMetamodelRuleset.java   View source code 2 votes vote down vote up
/**
 * Returns an unmodifiable view of the table of exclusion rules: rows are
 * metamodel URIs, columns are type names and cells are either sets of slot
 * names or a singleton set with WILDCARD (meaning "all"). An empty table
 * means "exclude nothing".
 */
public Table<String, String, ImmutableSet<String>> getExclusionRules() {
	return Tables.unmodifiableTable(exclusions);
}