com.google.common.collect.ImmutableTable Java Examples

The following examples show how to use com.google.common.collect.ImmutableTable. 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: RuntimeEntityResolver.java    From bazel with Apache License 2.0 6 votes vote down vote up
private static ImmutableTable<Integer, ClassMemberKey<?>, Member> getReflectionBasedClassMembers(
    int round, Class<?> classLiteral) {
  ImmutableTable.Builder<Integer, ClassMemberKey<?>, Member> reflectionBasedMembers =
      ImmutableTable.builder();
  ClassName owner = ClassName.create(classLiteral);
  for (Field field : classLiteral.getDeclaredFields()) {
    reflectionBasedMembers.put(
        round,
        FieldKey.create(owner, field.getName(), Type.getDescriptor(field.getType())),
        field);
  }
  for (Constructor<?> constructor : classLiteral.getDeclaredConstructors()) {
    reflectionBasedMembers.put(
        round,
        MethodKey.create(owner, "<init>", Type.getConstructorDescriptor(constructor)),
        constructor);
  }
  for (Method method : classLiteral.getDeclaredMethods()) {
    reflectionBasedMembers.put(
        round,
        MethodKey.create(owner, method.getName(), Type.getMethodDescriptor(method)),
        method);
  }
  return reflectionBasedMembers.build();
}
 
Example #2
Source File: ConfigTtlProvider.java    From blueflood with Apache License 2.0 6 votes vote down vote up
/**
 * Helper function to build the ttl mapping. Only insert to the mapping if the value is a valid date.
 * @param ttlMapBuilder
 * @param config
 * @param gran
 * @param rollupType
 * @param configKey
 * @return true if the insertion is successful, false otherwise.
 */
private boolean put(
    ImmutableTable.Builder<Granularity, RollupType, TimeValue> ttlMapBuilder,
    Configuration config,
    Granularity gran,
    RollupType rollupType,
    TtlConfig configKey) {
    int value;
    try {
        value = config.getIntegerProperty(configKey);
        if (value < 0) return false;
    } catch (NumberFormatException ex) {
        log.trace(String.format("No valid TTL config set for granularity: %s, rollup type: %s",
                gran.name(), rollupType.name()), ex);
        return false;
    }
    ttlMapBuilder.put(gran, rollupType, new TimeValue(value, TimeUnit.DAYS));
    return true;
}
 
Example #3
Source File: ImmutableTableCodec.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableTable<R, C, V> deserialize(
    DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  int length = codedIn.readInt32();
  if (length < 0) {
    throw new SerializationException("Expected non-negative length: " + length);
  }
  ImmutableTable.Builder<R, C, V> builder = ImmutableTable.builder();
  for (int i = 0; i < length; i++) {
    builder.put(
        /*rowKey=*/ context.deserialize(codedIn),
        /*columnKey=*/ context.deserialize(codedIn),
        /*value=*/ context.deserialize(codedIn));
  }
  return builder.build();
}
 
Example #4
Source File: TableSerializationTest.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
/**
     * This test illustrates one way to use objects as keys in Tables.
     */
    public void testComplexKeyImmutableTableSerde() throws IOException
    {
        final ImmutableTable.Builder<Integer, ComplexKey, String> ckBuilder = ImmutableTable.builder();
        ckBuilder.put(Integer.valueOf(42), new ComplexKey("field1", "field2"), "some value 42");
        ckBuilder.put(Integer.valueOf(45), new ComplexKey("field1", "field2"), "some value 45");
        final ImmutableTable<Integer, ComplexKey, String> complexKeyTable = ckBuilder.build();

        final TypeReference<ImmutableTable<Integer, ComplexKey, String>> tableType = new TypeReference<ImmutableTable<Integer, ComplexKey, String>>()
        {};

        final String ckJson = this.MAPPER.writerFor(tableType).writeValueAsString(complexKeyTable);
        assertEquals("{\"42\":{\"field1:field2\":\"some value 42\"},\"45\":{\"field1:field2\":\"some value 45\"}}", ckJson);

        // !!! TODO: support deser
/*        
        
        final ImmutableTable<Integer, ComplexKey, String> reconstitutedTable = this.MAPPER.readValue(ckJson, tableType);
        assertEquals(complexKeyTable, reconstitutedTable);
        */
    }
 
Example #5
Source File: TableUI.java    From Rails with GNU General Public License v2.0 6 votes vote down vote up
public static TableUI from(GridTable gridTable) {

        TableAxis rows = TableAxis.from(gridTable.getRows());
        TableAxis cols = TableAxis.from(gridTable.getCols());

        ImmutableTable.Builder<TableCoordinate,TableCoordinate,TableField> tableFields =
                ImmutableTable.builder();

        for (TableCoordinate row:rows) {
            for (TableCoordinate col:cols) {
                log.debug("Try to add field at {},{} ", row, col);
                GridField gridField = gridTable.getFields().get(row.getGridCoordinate(), col.getGridCoordinate());
                Preconditions.checkState(gridField != null, "No gridField available for row %s, col %s ", row, col);
                TableField tableField = gridField.toTableField(row.getItem(), col.getItem());
                tableFields.put(row, col, tableField);
            }
        }
        TableUI table = new TableUI(rows, cols, tableFields.build());

        return table;
    }
 
Example #6
Source File: BDDTracerTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void testBranch() {
  BDD toB = PKT.getDstIpSpaceToBDD().toBDD(Prefix.parse("0.0.0.0/1"));
  BDD toC = PKT.getDstIpSpaceToBDD().toBDD(Prefix.parse("128.0.0.0/1"));
  ImmutableTable<StateExpr, StateExpr, Transition> table =
      ImmutableTable.<StateExpr, StateExpr, Transition>builder()
          .put(A, B, constraint(toB))
          .put(A, C, constraint(toC))
          .build();
  List<BDDTrace> traces = BDDTracer.getTraces(table, A, ONE);
  assertThat(
      traces,
      contains(
          trace(TERMINATED, hop(A), hop(B, toB)), //
          trace(TERMINATED, hop(A), hop(C, toC))));
}
 
Example #7
Source File: ListObjectsAction.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/** 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;
}
 
Example #8
Source File: TableSerializationTest.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testSimpleKeyImmutableTableSerde() throws IOException
{
    final ImmutableTable.Builder<Integer, String, String> builder = ImmutableTable.builder();
    builder.put(Integer.valueOf(42), "column42", "some value 42");
    builder.put(Integer.valueOf(45), "column45", "some value 45");
    final ImmutableTable<Integer, String, String> simpleTable = builder.build();

    final String simpleJson = MAPPER.writeValueAsString(simpleTable);
    assertEquals("{\"42\":{\"column42\":\"some value 42\"},\"45\":{\"column45\":\"some value 45\"}}", simpleJson);

    // !!! TODO: support deser
    
    /*
    final ImmutableTable<Integer, String, String> reconstitutedTable =
            this.MAPPER.readValue(simpleJson, new TypeReference<ImmutableTable<Integer, String, String>>() {});
    assertEquals(simpleTable, reconstitutedTable);
    */
}
 
Example #9
Source File: ShellCommand.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the completions and documentation based on the JCommander.
 *
 * The input data is copied, so changing the jcommander after creation of the
 * JCommanderCompletor doesn't change the completions.
 */
JCommanderCompletor(JCommander jcommander) {
  ImmutableTable.Builder<String, String, ParamDoc> builder = new ImmutableTable.Builder<>();

  // Go over all the commands
  for (Entry<String, JCommander> entry : jcommander.getCommands().entrySet()) {
    String command = entry.getKey();
    JCommander subCommander = entry.getValue();

    // Add the "main" parameters documentation
    builder.put(command, "", ParamDoc.create(subCommander.getMainParameter()));

    // For each command - go over the parameters (arguments / flags)
    for (ParameterDescription parameter : subCommander.getParameters()) {
      ParamDoc paramDoc = ParamDoc.create(parameter);

      // For each parameter - go over all the "flag" names of that parameter (e.g., -o and
      // --output being aliases of the same parameter) and populate each one
      Arrays.stream(parameter.getParameter().names())
          .forEach(flag -> builder.put(command, flag, paramDoc));
    }
  }
  commandFlagDocs = builder.build();
}
 
Example #10
Source File: ListObjectsAction.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #11
Source File: ImmutableCollectionSerializers.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #12
Source File: CashFlowReport.java    From Strata with Apache License 2.0 6 votes vote down vote up
private CashFlowReport(
    LocalDate valuationDate,
    Instant runInstant,
    List<ExplainKey<?>> columnKeys,
    List<String> columnHeaders,
    Table<Integer, Integer, Object> data) {
  JodaBeanUtils.notNull(valuationDate, "valuationDate");
  JodaBeanUtils.notNull(runInstant, "runInstant");
  JodaBeanUtils.notNull(columnKeys, "columnKeys");
  JodaBeanUtils.notNull(columnHeaders, "columnHeaders");
  JodaBeanUtils.notNull(data, "data");
  this.valuationDate = valuationDate;
  this.runInstant = runInstant;
  this.columnKeys = ImmutableList.copyOf(columnKeys);
  this.columnHeaders = ImmutableList.copyOf(columnHeaders);
  this.data = ImmutableTable.copyOf(data);
}
 
Example #13
Source File: SingularGuavaTable.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
SingularGuavaTable(final ImmutableTable rawTypes, final ImmutableTable<Integer, Float, String> integers, final ImmutableTable<A, B, C> generics, final ImmutableTable<? extends Number, ? extends Float, ? extends String> extendsGenerics) {
  this.rawTypes = rawTypes;
  this.integers = integers;
  this.generics = generics;
  this.extendsGenerics = extendsGenerics;
}
 
Example #14
Source File: SingularGuavaTable2.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
SingularGuavaTable2(final ImmutableTable rawTypes, final ImmutableTable<Integer, Float, String> integers, final ImmutableTable<A, B, C> generics, final ImmutableTable<? extends Number, ? extends Float, ? extends String> extendsGenerics) {
  this.rawTypes = rawTypes;
  this.integers = integers;
  this.generics = generics;
  this.extendsGenerics = extendsGenerics;
}
 
Example #15
Source File: SingularGuavaTable.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
public SingularGuavaTable<A, B, C> build() {
  com.google.common.collect.ImmutableTable<java.lang.Object, java.lang.Object, java.lang.Object> rawTypes = this.rawTypes == null ? com.google.common.collect.ImmutableTable.<java.lang.Object, java.lang.Object, java.lang.Object>of() : this.rawTypes.build();
  com.google.common.collect.ImmutableTable<Integer, Float, String> integers = this.integers == null ? com.google.common.collect.ImmutableTable.<Integer, Float, String>of() : this.integers.build();
  com.google.common.collect.ImmutableTable<A, B, C> generics = this.generics == null ? com.google.common.collect.ImmutableTable.<A, B, C>of() : this.generics.build();
  com.google.common.collect.ImmutableTable<Number, Float, String> extendsGenerics = this.extendsGenerics == null ? com.google.common.collect.ImmutableTable.<Number, Float, String>of() : this.extendsGenerics.build();
  return new SingularGuavaTable<A, B, C>(rawTypes, integers, generics, extendsGenerics);
}
 
Example #16
Source File: TradeReport.java    From Strata with Apache License 2.0 5 votes vote down vote up
private TradeReport(
    LocalDate valuationDate,
    Instant runInstant,
    List<TradeReportColumn> columns,
    Table<Integer, Integer, Result<?>> data) {
  JodaBeanUtils.notNull(valuationDate, "valuationDate");
  JodaBeanUtils.notNull(runInstant, "runInstant");
  JodaBeanUtils.notNull(columns, "columns");
  JodaBeanUtils.notNull(data, "data");
  this.valuationDate = valuationDate;
  this.runInstant = runInstant;
  this.columns = ImmutableList.copyOf(columns);
  this.data = ImmutableTable.copyOf(data);
}
 
Example #17
Source File: BuilderSingularGuavaListsSets.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
public BuilderSingularGuavaListsSets<T> build() {
	com.google.common.collect.ImmutableList<T> cards = this.cards == null ? com.google.common.collect.ImmutableList.<T>of() : this.cards.build();
	com.google.common.collect.ImmutableCollection<Number> frogs = this.frogs == null ? com.google.common.collect.ImmutableList.<Number>of() : this.frogs.build();
	com.google.common.collect.ImmutableSet<java.lang.Object> rawSet = this.rawSet == null ? com.google.common.collect.ImmutableSet.<java.lang.Object>of() : this.rawSet.build();
	com.google.common.collect.ImmutableSortedSet<String> passes = this.passes == null ? com.google.common.collect.ImmutableSortedSet.<String>of() : this.passes.build();
	com.google.common.collect.ImmutableTable<Number, Number, String> users = this.users == null ? com.google.common.collect.ImmutableTable.<Number, Number, String>of() : this.users.build();
	return new BuilderSingularGuavaListsSets<T>(cards, frogs, rawSet, passes, users);
}
 
Example #18
Source File: SingularGuavaTable.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
protected SingularGuavaTable(final SingularGuavaTableBuilder<A, B, C, ?, ?> b) {
  com.google.common.collect.ImmutableTable<java.lang.Object, java.lang.Object, java.lang.Object> rawTypes = b.rawTypes == null ? com.google.common.collect.ImmutableTable.<java.lang.Object, java.lang.Object, java.lang.Object>of() : b.rawTypes.build();
  this.rawTypes = rawTypes;
  com.google.common.collect.ImmutableTable<Integer, Float, String> integers = b.integers == null ? com.google.common.collect.ImmutableTable.<Integer, Float, String>of() : b.integers.build();
  this.integers = integers;
  com.google.common.collect.ImmutableTable<A, B, C> generics = b.generics == null ? com.google.common.collect.ImmutableTable.<A, B, C>of() : b.generics.build();
  this.generics = generics;
  com.google.common.collect.ImmutableTable<Number, Float, String> extendsGenerics = b.extendsGenerics == null ? com.google.common.collect.ImmutableTable.<Number, Float, String>of() : b.extendsGenerics.build();
  this.extendsGenerics = extendsGenerics;
}
 
Example #19
Source File: TradeReportRunner.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Override
public TradeReport runReport(ReportCalculationResults results, TradeReportTemplate reportTemplate) {
  ImmutableTable.Builder<Integer, Integer, Result<?>> resultTable = ImmutableTable.builder();

  for (int reportColumnIdx = 0; reportColumnIdx < reportTemplate.getColumns().size(); reportColumnIdx++) {
    TradeReportColumn reportColumn = reportTemplate.getColumns().get(reportColumnIdx);
    List<Result<?>> columnResults;

    if (reportColumn.getValue().isPresent()) {
      columnResults = ValuePathEvaluator.evaluate(reportColumn.getValue().get(), results);
    } else {
      columnResults = IntStream.range(0, results.getTargets().size())
          .mapToObj(i -> Result.failure(FailureReason.INVALID, "No value specified in report template"))
          .collect(toImmutableList());
    }
    int rowCount = results.getCalculationResults().getRowCount();

    for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
      resultTable.put(rowIdx, reportColumnIdx, columnResults.get(rowIdx));
    }
  }

  return TradeReport.builder()
      .runInstant(Instant.now())
      .valuationDate(results.getValuationDate())
      .columns(reportTemplate.getColumns())
      .data(resultTable.build())
      .build();
}
 
Example #20
Source File: ImmutableTableCodecTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void smoke() throws Exception {
  ImmutableTable.Builder<String, String, Integer> builder = ImmutableTable.builder();
  builder.put("a", "b", 1);
  builder.put("c", "d", -200);
  builder.put("a", "d", 4);
  new SerializationTester(ImmutableTable.of(), builder.build()).runTests();
}
 
Example #21
Source File: CodeReferenceMap.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public CodeReferenceMap build() {
  ImmutableTable.Builder<String, String, ImmutableSet<String>> deadMethodsBuilder =
      ImmutableTable.builder();
  for (Table.Cell<String, String, Set<String>> cell : this.deadMethods.cellSet()) {
    deadMethodsBuilder.put(
        cell.getRowKey(),
        cell.getColumnKey(),
        ImmutableSet.copyOf(cell.getValue()));
  }
  return new CodeReferenceMap(
      ImmutableSet.copyOf(deadClasses),
      deadMethodsBuilder.build(),
      ImmutableMultimap.copyOf(deadFields));
}
 
Example #22
Source File: SingularGuavaTable2.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public SingularGuavaTableBuilder<A, B, C> rawType(final java.lang.Object rowKey, final java.lang.Object columnKey, final java.lang.Object value) {
  if (this.rawTypes == null) this.rawTypes = com.google.common.collect.ImmutableTable.builder();
  this.rawTypes.put(rowKey, columnKey, value);
  return this;
}
 
Example #23
Source File: SingularGuavaTable2.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public SingularGuavaTable2<A, B, C> build() {
  com.google.common.collect.ImmutableTable<java.lang.Object, java.lang.Object, java.lang.Object> rawTypes = this.rawTypes == null ? com.google.common.collect.ImmutableTable.<java.lang.Object, java.lang.Object, java.lang.Object>of() : this.rawTypes.build();
  com.google.common.collect.ImmutableTable<Integer, Float, String> integers = this.integers == null ? com.google.common.collect.ImmutableTable.<Integer, Float, String>of() : this.integers.build();
  com.google.common.collect.ImmutableTable<A, B, C> generics = this.generics == null ? com.google.common.collect.ImmutableTable.<A, B, C>of() : this.generics.build();
  com.google.common.collect.ImmutableTable<Number, Float, String> extendsGenerics = this.extendsGenerics == null ? com.google.common.collect.ImmutableTable.<Number, Float, String>of() : this.extendsGenerics.build();
  return new SingularGuavaTable2<A, B, C>(rawTypes, integers, generics, extendsGenerics);
}
 
Example #24
Source File: ImmutableTableCodec.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
    SerializationContext context, ImmutableTable<R, C, V> object, CodedOutputStream codedOut)
    throws SerializationException, IOException {
  Set<Cell<R, C, V>> cellSet = object.cellSet();
  codedOut.writeInt32NoTag(cellSet.size());
  for (Cell<R, C, V> cell : cellSet) {
    context.serialize(cell.getRowKey(), codedOut);
    context.serialize(cell.getColumnKey(), codedOut);
    context.serialize(cell.getValue(), codedOut);
  }
}
 
Example #25
Source File: StatementSupportBundle.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private StatementSupportBundle(final StatementSupportBundle parent,
        final ImmutableSet<YangVersion> supportedVersions,
        final ImmutableMap<QName, StatementSupport<?, ?, ?>> commonStatements,
        final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces,
        final ImmutableTable<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificStatements) {
    this.parent = parent;
    this.supportedVersions = supportedVersions;
    this.commonDefinitions = commonStatements;
    this.namespaceDefinitions = namespaces;
    this.versionSpecificDefinitions = versionSpecificStatements;
}
 
Example #26
Source File: Adapters.java    From activitystreams with Apache License 2.0 5 votes vote down vote up
public Table<?, ?, ?> deserialize(
  JsonElement json, 
  Type typeOfT,
  JsonDeserializationContext context) 
    throws JsonParseException {
  ImmutableTable.Builder<String,String,Object> table = 
    ImmutableTable.builder();
  checkArgument(json.isJsonObject());
  JsonObject obj = json.getAsJsonObject();
  for (Map.Entry<String,JsonElement> rowentry : obj.entrySet()) {
    String row = rowentry.getKey();
    JsonElement cell = rowentry.getValue();
    checkArgument(cell.isJsonObject());
    for (Map.Entry<String,JsonElement> cellentry : cell.getAsJsonObject().entrySet()) {
      String ckey = cellentry.getKey();
      JsonElement val = cellentry.getValue();
      Object desval = null;
      if (val.isJsonArray())
        desval = MultimapAdapter.arraydes(val.getAsJsonArray(),context);
      else if (val.isJsonObject())
        desval = context.deserialize(val, ASObject.class);
      else if (val.isJsonPrimitive())
        desval = primConverter.convert(val.getAsJsonPrimitive());
      if (desval != null)
        table.put(row,ckey,desval);
    }
  }
  return table.build();
}
 
Example #27
Source File: BDDTracerTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoopWithConstraint() {
  BDD dst1 = PKT.getDstIpSpaceToBDD().toBDD(Prefix.parse("128.0.0.0/1"));
  ImmutableTable<StateExpr, StateExpr, Transition> table =
      ImmutableTable.<StateExpr, StateExpr, Transition>builder()
          .put(A, B, IDENTITY)
          .put(B, A, constraint(dst1))
          .build();
  List<BDDTrace> traces = BDDTracer.getTraces(table, A, ONE);
  assertThat(
      traces,
      containsInAnyOrder(
          trace(TERMINATED, hop(A), hop(B), hop(B, dst1.not())),
          trace(LOOPED, hop(A), hop(B), hop(A, dst1))));
}
 
Example #28
Source File: BDDTracerTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() {
  ImmutableTable<StateExpr, StateExpr, Transition> table =
      ImmutableTable.<StateExpr, StateExpr, Transition>builder()
          .put(A, B, IDENTITY)
          .put(B, C, IDENTITY)
          .build();
  List<BDDTrace> traces = BDDTracer.getTraces(table, A, ONE);
  assertThat(traces, contains(trace(TERMINATED, hop(A), hop(B), hop(C))));
}
 
Example #29
Source File: CodeReferenceMap.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private CodeReferenceMap(
    ImmutableSet<String> referencedClasses,
    ImmutableTable<String, String, ImmutableSet<String>> referencedMethods,
    ImmutableMultimap<String, String> referencedFields) {
  this.referencedClasses = referencedClasses;
  this.referencedMethods = referencedMethods;
  this.referencedFields = referencedFields;
}
 
Example #30
Source File: GuavaTableUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenImmutableTable_whenGet_returnsSuccessfully() {
    final Table<String, String, Integer> universityCourseSeatTable = ImmutableTable.<String, String, Integer> builder()
        .put("Mumbai", "Chemical", 120)
        .put("Mumbai", "IT", 60)
        .put("Harvard", "Electrical", 60)
        .put("Harvard", "IT", 120)
        .build();

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

    assertThat(seatCount).isEqualTo(60);
}