Java Code Examples for com.google.common.collect.HashBasedTable#put()

The following examples show how to use com.google.common.collect.HashBasedTable#put() . 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: 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 2
Source File: WeightedPAutomaton.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
public String toLabelGroupedDotString() {
    HashBasedTable<D, N, Collection<D>> groupedByTargetAndLabel = HashBasedTable.create();
    for (Transition<N, D> t : transitions) {
        Collection<D> collection = groupedByTargetAndLabel.get(t.getTarget(), t.getLabel());
        if (collection == null)
            collection = Sets.newHashSet();
        collection.add(t.getStart());
        groupedByTargetAndLabel.put(t.getTarget(), t.getLabel(), collection);
    }
    String s = "digraph {\n";
    for (D target : groupedByTargetAndLabel.rowKeySet()) {
        for (N label : groupedByTargetAndLabel.columnKeySet()) {
            Collection<D> source = groupedByTargetAndLabel.get(target, label);
            if (source == null)
                continue;
            s += "\t\"" + Joiner.on("\\n").join(source) + "\"";
            s += " -> \"" + wrapIfInitialOrFinalState(target) + "\"";
            s += "[label=\"" + label + "\"];\n";
        }
    }
    s += "}\n";
    s += "Transitions: " + transitions.size() + "\n";
    for (WeightedPAutomaton<N, D, W> nested : nestedAutomatons) {
        s += "NESTED -> \n";
        s += nested.toDotString();
    }
    return s;
}
 
Example 3
Source File: ScanUploaderTest.java    From emodb with Apache License 2.0 5 votes vote down vote up
private PutObjectResult mockUploadS3File(String bucket, String key, byte[] contents, HashBasedTable<String, String, ByteBuffer> s3FileTable) {
    // Place the contents in the s3 file table keyed by the file's parent directory and file name
    int idx = key.lastIndexOf('/');
    String parentDir = key.substring(0, idx);
    String fileName = key.substring(idx + 1);
    // HashBasedTable is not thread-safe if multiple threads try to write to the same directory concurrently
    synchronized (s3FileTable) {
        s3FileTable.put(format("%s/%s", bucket, parentDir), fileName, ByteBuffer.wrap(contents));
    }

    PutObjectResult result = new PutObjectResult();
    result.setETag("etag");
    return result;
}
 
Example 4
Source File: VxlanVniPropertiesAnswererTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Override
public DataPlane loadDataPlane(NetworkSnapshot snapshot) {
  SortedMap<String, Configuration> configs = loadConfigurations(snapshot);
  HashBasedTable<String, String, Set<Layer2Vni>> vnis = HashBasedTable.create();
  vnis.put(
      "hostname",
      DEFAULT_VRF_NAME,
      ImmutableSet.of(
          testBuilder()
              .setVni(10001)
              .setVlan(1)
              .setSourceAddress(Ip.parse("1.2.3.4"))
              .setUdpPort(4242)
              .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP)
              .setBumTransportIps(
                  ImmutableSortedSet.of(Ip.parse("2.3.4.5"), Ip.parse("2.3.4.6")))
              .build(),
          testBuilder()
              .setVni(10002)
              .setVlan(2)
              .setSourceAddress(Ip.parse("1.2.3.4"))
              .setUdpPort(4789)
              .setBumTransportMethod(BumTransportMethod.MULTICAST_GROUP)
              .setBumTransportIps(ImmutableSortedSet.of(Ip.parse("227.10.1.1")))
              .build()));
  vnis.put(
      "minimal",
      DEFAULT_VRF_NAME,
      ImmutableSet.of(
          testBuilder()
              .setVni(10001)
              .setVlan(1)
              .setUdpPort(1234)
              .setBumTransportMethod(BumTransportMethod.MULTICAST_GROUP)
              .build()));
  return MockDataPlane.builder().setConfigs(configs).setVniSettings(vnis).build();
}