本文整理匯總了Java中com.google.common.collect.ImmutableTable類的典型用法代碼示例。如果您正苦於以下問題:Java ImmutableTable類的具體用法?Java ImmutableTable怎麽用?Java ImmutableTable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ImmutableTable類屬於com.google.common.collect包,在下文中一共展示了ImmutableTable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildPropertyValueTable
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
public void buildPropertyValueTable(Map<Map<IProperty, Comparable>, BlockState.StateImplementation> map)
{
if (this.propertyValueTable != null)
{
throw new IllegalStateException();
}
else
{
Table<IProperty, Comparable, IBlockState> table = HashBasedTable.<IProperty, Comparable, IBlockState>create();
for (IProperty <? extends Comparable > iproperty : this.properties.keySet())
{
for (Comparable comparable : iproperty.getAllowedValues())
{
if (comparable != this.properties.get(iproperty))
{
table.put(iproperty, comparable, map.get(this.getPropertiesWithValue(iproperty, comparable)));
}
}
}
this.propertyValueTable = ImmutableTable.<IProperty, Comparable, IBlockState>copyOf(table);
}
}
示例2: MediaTypeClassifierImpl
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
MediaTypeClassifierImpl(Iterable<? extends MediaType> mts) {
Table<String, String, Set<MediaType>> typeTable =
HashBasedTable.<String, String, Set<MediaType>>create();
for (MediaType mt : mts) {
String type = mt.type();
String subtype = mt.subtype();
Set<MediaType> typeSet = typeTable.get(type, subtype);
if (typeSet == null) {
typeSet = Sets.newLinkedHashSet();
typeTable.put(type, subtype, typeSet);
}
typeSet.add(mt);
}
ImmutableTable.Builder<String, String, ImmutableSet<MediaType>> b =
ImmutableTable.builder();
for (Table.Cell<String, String, Set<MediaType>> cell
: typeTable.cellSet()) {
b.put(cell.getRowKey(), cell.getColumnKey(), ImmutableSet.copyOf(cell.getValue()));
}
this.types = b.build();
}
示例3: register
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
public static void register(final Kryo kryo) {
// register list
final ImmutableListSerializer serializer = new ImmutableListSerializer();
kryo.register(ImmutableList.class, serializer);
kryo.register(ImmutableList.of().getClass(), serializer);
kryo.register(ImmutableList.of(Integer.valueOf(1)).getClass(), serializer);
kryo.register(ImmutableList.of(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)).subList(1, 2).getClass(), serializer);
kryo.register(ImmutableList.of().reverse().getClass(), serializer);
kryo.register(Lists.charactersOf("dremio").getClass(), serializer);
final HashBasedTable baseTable = HashBasedTable.create();
baseTable.put(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3));
baseTable.put(Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6));
ImmutableTable table = ImmutableTable.copyOf(baseTable);
kryo.register(table.values().getClass(), serializer);
}
示例4: buildPropertyValueTable
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
public void buildPropertyValueTable(Map < Map < IProperty<?>, Comparable<? >> , BlockStateContainer.StateImplementation > map)
{
if (this.propertyValueTable != null)
{
throw new IllegalStateException();
}
else
{
Table < IProperty<?>, Comparable<?>, IBlockState > table = HashBasedTable. < IProperty<?>, Comparable<?>, IBlockState > create();
for (Entry < IProperty<?>, Comparable<? >> entry : this.properties.entrySet())
{
IProperty<?> iproperty = (IProperty)entry.getKey();
for (Comparable<?> comparable : iproperty.getAllowedValues())
{
if (comparable != entry.getValue())
{
table.put(iproperty, comparable, map.get(this.getPropertiesWithValue(iproperty, comparable)));
}
}
}
this.propertyValueTable = ImmutableTable. < IProperty<?>, Comparable<?>, IBlockState > copyOf(table);
}
}
示例5: stageReports
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
/**
* Creates and stores reports of a given type on GCS.
*
* <p>This is factored out to facilitate choosing which reports to upload,
*/
ImmutableList<String> stageReports(ReportType reportType) throws Exception {
QueryBuilder queryBuilder =
(reportType == ReportType.ACTIVITY) ? activityQueryBuilder : transactionsQueryBuilder;
ImmutableMap<String, String> viewQueryMap = queryBuilder.getViewQueryMap();
// Generate intermediary views
for (Entry<String, String> entry : viewQueryMap.entrySet()) {
createIntermediaryTableView(entry.getKey(), entry.getValue(), reportType);
}
// Get an in-memory table of the aggregate query's result
ImmutableTable<Integer, TableFieldSchema, Object> reportTable =
bigquery.queryToLocalTableSync(queryBuilder.getReportQuery());
// Get report headers from the table schema and convert into CSV format
String headerRow = constructRow(getHeaders(reportTable.columnKeySet()));
return (reportType == ReportType.ACTIVITY)
? stageActivityReports(headerRow, reportTable.rowMap().values())
: stageTransactionsReports(headerRow, reportTable.rowMap().values());
}
示例6: extractData
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
/**
* Returns a table of data for the given sets of fields and objects. The table is row-keyed by
* object and column-keyed by field, in the same iteration order as the provided sets.
*/
private ImmutableTable<T, String, String>
extractData(ImmutableSet<String> fields, ImmutableSet<T> objects) {
ImmutableTable.Builder<T, String, String> builder = new ImmutableTable.Builder<>();
for (T object : objects) {
Map<String, Object> fieldMap = new HashMap<>();
// Base case of the mapping is to use ImmutableObject's toDiffableFieldMap().
fieldMap.putAll(object.toDiffableFieldMap());
// Next, overlay any field-level overrides specified by the subclass.
fieldMap.putAll(getFieldOverrides(object));
// Next, add to the mapping all the aliases, with their values defined as whatever was in the
// map under the aliased field's original name.
fieldMap.putAll(new HashMap<>(Maps.transformValues(getFieldAliases(), fieldMap::get)));
Set<String> expectedFields = ImmutableSortedSet.copyOf(fieldMap.keySet());
for (String field : fields) {
checkArgument(fieldMap.containsKey(field),
"Field '%s' not found - recognized fields are:\n%s", field, expectedFields);
builder.put(object, field, Objects.toString(fieldMap.get(field), ""));
}
}
return builder.build();
}
示例7: generateFormattedData
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
/** Converts the provided table of data to text, formatted using the provided column widths. */
private List<String> generateFormattedData(
ImmutableTable<T, String, String> data,
ImmutableMap<String, Integer> columnWidths) {
Function<Map<String, String>, String> rowFormatter = makeRowFormatter(columnWidths);
List<String> lines = new ArrayList<>();
if (isHeaderRowInUse(data)) {
// Add a row of headers (column names mapping to themselves).
Map<String, String> headerRow = Maps.asMap(data.columnKeySet(), key -> key);
lines.add(rowFormatter.apply(headerRow));
// Add a row of separator lines (column names mapping to '-' * column width).
Map<String, String> separatorRow =
Maps.transformValues(columnWidths, width -> Strings.repeat("-", width));
lines.add(rowFormatter.apply(separatorRow));
}
// Add the actual data rows.
for (Map<String, String> row : data.rowMap().values()) {
lines.add(rowFormatter.apply(row));
}
return lines;
}
示例8: build
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
@Override
public ImmutableMarkovChain<S> build() {
// todo: check if sum of transition probabilities in rows are <= 1
for (final S state : table.rowKeySet()) {
double sum = 0.0;
for (final Double value : table.row(state).values()) {
sum += value;
}
if (sum < 0 || sum > 1) {
final String message = "Sum of transition probabilities from state "
+ state + " must be in >= 0 and <= 1";
throw new IllegalArgumentException(message);
}
}
rng = RandomGenerators.rng();
return new ImmutableMarkovChain<S>(ImmutableTable.copyOf(table), rng);
}
示例9: parseReviewerFieldValues
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
public static ReviewerSet parseReviewerFieldValues(Iterable<String> values) {
ImmutableTable.Builder<ReviewerStateInternal, Account.Id, Timestamp> b =
ImmutableTable.builder();
for (String v : values) {
int f = v.indexOf(',');
if (f < 0) {
continue;
}
int l = v.lastIndexOf(',');
if (l == f) {
continue;
}
b.put(
ReviewerStateInternal.valueOf(v.substring(0, f)),
Account.Id.parse(v.substring(f + 1, l)),
new Timestamp(Long.valueOf(v.substring(l + 1, v.length()))));
}
return ReviewerSet.fromTable(b.build());
}
示例10: parseReviewerByEmailFieldValues
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
public static ReviewerByEmailSet parseReviewerByEmailFieldValues(Iterable<String> values) {
ImmutableTable.Builder<ReviewerStateInternal, Address, Timestamp> b = ImmutableTable.builder();
for (String v : values) {
int f = v.indexOf(',');
if (f < 0) {
continue;
}
int l = v.lastIndexOf(',');
if (l == f) {
continue;
}
b.put(
ReviewerStateInternal.valueOf(v.substring(0, f)),
Address.parse(v.substring(f + 1, l)),
new Timestamp(Long.valueOf(v.substring(l + 1, v.length()))));
}
return ReviewerByEmailSet.fromTable(b.build());
}
示例11: multipleReviewers
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
@Test
public void multipleReviewers() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
update.commit();
ChangeNotes notes = newNotes(c);
Timestamp ts = new Timestamp(update.getWhen().getTime());
assertThat(notes.getReviewers())
.isEqualTo(
ReviewerSet.fromTable(
ImmutableTable.<ReviewerStateInternal, Account.Id, Timestamp>builder()
.put(REVIEWER, new Account.Id(1), ts)
.put(REVIEWER, new Account.Id(2), ts)
.build()));
}
示例12: reviewerTypes
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
@Test
public void reviewerTypes() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
update.putReviewer(otherUser.getAccount().getId(), CC);
update.commit();
ChangeNotes notes = newNotes(c);
Timestamp ts = new Timestamp(update.getWhen().getTime());
assertThat(notes.getReviewers())
.isEqualTo(
ReviewerSet.fromTable(
ImmutableTable.<ReviewerStateInternal, Account.Id, Timestamp>builder()
.put(REVIEWER, new Account.Id(1), ts)
.put(CC, new Account.Id(2), ts)
.build()));
}
示例13: oneReviewerMultipleTypes
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
@Test
public void oneReviewerMultipleTypes() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
update.commit();
ChangeNotes notes = newNotes(c);
Timestamp ts = new Timestamp(update.getWhen().getTime());
assertThat(notes.getReviewers())
.isEqualTo(ReviewerSet.fromTable(ImmutableTable.of(REVIEWER, new Account.Id(2), ts)));
update = newUpdate(c, otherUser);
update.putReviewer(otherUser.getAccount().getId(), CC);
update.commit();
notes = newNotes(c);
ts = new Timestamp(update.getWhen().getTime());
assertThat(notes.getReviewers())
.isEqualTo(ReviewerSet.fromTable(ImmutableTable.of(CC, new Account.Id(2), ts)));
}
示例14: filteredCopy
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
/**
* Return a new {@code ProvenancedConfusionMatrix} containing only those provenance entries
* matching the provided predicate.
*/
public ProvenancedConfusionMatrix<CellFiller> filteredCopy(Predicate<CellFiller> predicate) {
final ImmutableTable.Builder<Symbol, Symbol, List<CellFiller>> newTable =
ImmutableTable.builder();
for (final Cell<Symbol, Symbol, List<CellFiller>> curCell : table.cellSet()) {
final List<CellFiller> newFiller = FluentIterable.from(curCell.getValue())
.filter(predicate).toList();
if (!newFiller.isEmpty()) {
newTable.put(curCell.getRowKey(), curCell.getColumnKey(), newFiller);
}
}
return new ProvenancedConfusionMatrix<CellFiller>(newTable.build());
}
示例15: build
import com.google.common.collect.ImmutableTable; //導入依賴的package包/類
public ImmutableSetMultitable<R, C, V> build() {
final ImmutableTable.Builder<R, C, Collection<V>> immutableTable =
ImmutableTable.builder();
int size = 0;
ImmutableSet.Builder<R> rowIterationBuilder = ImmutableSet.builder();
ImmutableSet.Builder<C> columnIterationBuilder = ImmutableSet.builder();
for (final RowKeyColumnKeyPair<R, C> rowKeyColKey : rowInsertionOrder.build()) {
final ImmutableSet<V> valuesForPair =
tableWeCanLookUpIn.get(rowKeyColKey.row(), rowKeyColKey.column()).build();
size += valuesForPair.size();
immutableTable.put(rowKeyColKey.row(), rowKeyColKey.column(),
valuesForPair);
rowIterationBuilder.add(rowKeyColKey.row());
columnIterationBuilder.add(rowKeyColKey.column());
}
return new ImmutableSetMultitable<>(immutableTable.build(), size, rowIterationBuilder.build(),
columnIterationBuilder.build());
}