Java 类com.google.common.collect.ImmutableSetMultimap.Builder 实例源码

项目:guava-mock    文件:ImmutableSetMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableSetMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(ImmutableSet.of(1), builder.build().get("one"));
}
项目:guava-mock    文件:ImmutableSetMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(ImmutableSet.of(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava-mock    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava-mock    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava-mock    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:guava-mock    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:guava-mock    文件:ImmutableSetMultimapTest.java   
@GwtIncompatible // SerializableTester
public void testSortedSerialization() {
  Multimap<String, Integer> multimap = new ImmutableSetMultimap.Builder<String, Integer>()
      .orderKeysBy(Ordering.natural().reverse())
      .orderValuesBy(Ordering.usingToString())
      .put("a", 2)
      .put("a", 10)
      .put("b", 1)
      .build();
  multimap = SerializableTester.reserialize(multimap);
  assertThat(multimap.keySet()).containsExactly("b", "a").inOrder();
  assertThat(multimap.get("a")).containsExactly(10, 2).inOrder();
  assertEquals(Ordering.usingToString(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertEquals(Ordering.usingToString(),
      ((ImmutableSortedSet<Integer>) multimap.get("z")).comparator());
}
项目:athena    文件:DefaultTopology.java   
/**
 * Computes on-demand the set of shortest paths between source and
 * destination devices.
 *
 * @param src    source device
 * @param dst    destination device
 * @param weight link weight function
 * @return set of shortest paths
 */
public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
    DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }

    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
            graphPathSearch().search(graph, srcV, dstV, weight, ALL_PATHS);
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkPath(path));
    }
    return builder.build();
}
项目:athena    文件:DefaultTopology.java   
/**
 * Computes on-demand the set of shortest disjoint path pairs between source and
 * destination devices.
 *
 * @param src    source device
 * @param dst    destination device
 * @param weight link weight function
 * @return set of disjoint shortest path pairs
 */
public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
    DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }

    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
            SUURBALLE.search(graph, srcV, dstV, weight, ALL_PATHS);
    ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkDisjointPath((org.onlab.graph.DisjointPathPair<TopologyVertex, TopologyEdge>) path));
    }
    return builder.build();
}
项目:athena    文件:DefaultTopology.java   
/**
 * Computes on-demand the set of shortest disjoint risk groups path pairs between source and
 * destination devices.
 *
 * @param src         source device
 * @param dst         destination device
 * @param weight      edge weight object
 * @param riskProfile map representing risk groups for each edge
 * @return set of shortest disjoint paths
 */
private Set<DisjointPath> disjointPaths(DeviceId src, DeviceId dst, LinkWeight weight,
                                        Map<TopologyEdge, Object> riskProfile) {
    DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);

    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }

    SrlgGraphSearch<TopologyVertex, TopologyEdge> srlg = new SrlgGraphSearch<>(riskProfile);
    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
            srlg.search(graph, srcV, dstV, weight, ALL_PATHS);
    ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkDisjointPath((org.onlab.graph.DisjointPathPair<TopologyVertex, TopologyEdge>) path));
    }
    return builder.build();
}
项目:athena    文件:DefaultTopology.java   
private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() {
    ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
    SccResult<TopologyVertex, TopologyEdge> results = clusterResults.get();

    // Extract both vertexes and edges from the results; the lists form
    // pairs along the same index.
    List<Set<TopologyVertex>> clusterVertexes = results.clusterVertexes();
    List<Set<TopologyEdge>> clusterEdges = results.clusterEdges();

    // Scan over the lists and create a cluster from the results.
    for (int i = 0, n = results.clusterCount(); i < n; i++) {
        Set<TopologyVertex> vertexSet = clusterVertexes.get(i);
        Set<TopologyEdge> edgeSet = clusterEdges.get(i);

        ClusterId cid = ClusterId.clusterId(i);
        DefaultTopologyCluster cluster = new DefaultTopologyCluster(cid,
                                                                    vertexSet.size(),
                                                                    edgeSet.size(),
                                                                    findRoot(vertexSet));
        clusterBuilder.put(cid, cluster);
    }
    return clusterBuilder.build();
}
项目:googles-monorepo-demo    文件:ImmutableSetMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableSetMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(ImmutableSet.of(1), builder.build().get("one"));
}
项目:googles-monorepo-demo    文件:ImmutableSetMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(ImmutableSet.of(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:googles-monorepo-demo    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:googles-monorepo-demo    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:googles-monorepo-demo    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:googles-monorepo-demo    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:googles-monorepo-demo    文件:ImmutableSetMultimapTest.java   
@GwtIncompatible // SerializableTester
public void testSortedSerialization() {
  Multimap<String, Integer> multimap = new ImmutableSetMultimap.Builder<String, Integer>()
      .orderKeysBy(Ordering.natural().reverse())
      .orderValuesBy(Ordering.usingToString())
      .put("a", 2)
      .put("a", 10)
      .put("b", 1)
      .build();
  multimap = SerializableTester.reserialize(multimap);
  assertThat(multimap.keySet()).containsExactly("b", "a").inOrder();
  assertThat(multimap.get("a")).containsExactly(10, 2).inOrder();
  assertEquals(Ordering.usingToString(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertEquals(Ordering.usingToString(),
      ((ImmutableSortedSet<Integer>) multimap.get("z")).comparator());
}
项目:ravikumaran201504    文件:DefaultTopology.java   
/**
 * Computes on-demand the set of shortest paths between source and
 * destination devices.
 *
 * @param src source device
 *
 * @param dst destination device
 *
 * @param weight link weight function
 *
 * @return set of shortest paths
 */
Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
    final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }

    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
            DIJKSTRA.search(graph, srcV, dstV, weight, ALL_PATHS);
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkPath(path));
    }
    return builder.build();
}
项目:ravikumaran201504    文件:DefaultTopology.java   
private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() {
    ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
    SCCResult<TopologyVertex, TopologyEdge> results = clusterResults.get();
    // Extract both vertexes and edges from the results; the lists form
    // pairs along the same index.
    List<Set<TopologyVertex>> clusterVertexes = results.clusterVertexes();
    List<Set<TopologyEdge>> clusterEdges = results.clusterEdges();

    // Scan over the lists and create a cluster from the results.
    for (int i = 0, n = results.clusterCount(); i < n; i++) {
        Set<TopologyVertex> vertexSet = clusterVertexes.get(i);
        Set<TopologyEdge> edgeSet = clusterEdges.get(i);

        ClusterId cid = ClusterId.clusterId(i);
        DefaultTopologyCluster cluster = new DefaultTopologyCluster(cid,
                                                                    vertexSet.size(),
                                                                    edgeSet.size(),
                                                                    findRoot(vertexSet));
        clusterBuilder.put(cid, cluster);
    }
    return clusterBuilder.build();
}
项目:ravikumaran201504    文件:DefaultTopology.java   
/**
 * Computes on-demand the set of shortest paths between source and
 * destination devices.
 *
 * @param src source device
 *
 * @param dst destination device
 *
 * @param weight link weight function
 *
 * @return set of shortest paths
 */
Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
    final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }

    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
            DIJKSTRA.search(graph, srcV, dstV, weight, ALL_PATHS);
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkPath(path));
    }
    return builder.build();
}
项目:ravikumaran201504    文件:DefaultTopology.java   
private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() {
    ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
    SCCResult<TopologyVertex, TopologyEdge> results = clusterResults.get();
    // Extract both vertexes and edges from the results; the lists form
    // pairs along the same index.
    List<Set<TopologyVertex>> clusterVertexes = results.clusterVertexes();
    List<Set<TopologyEdge>> clusterEdges = results.clusterEdges();

    // Scan over the lists and create a cluster from the results.
    for (int i = 0, n = results.clusterCount(); i < n; i++) {
        Set<TopologyVertex> vertexSet = clusterVertexes.get(i);
        Set<TopologyEdge> edgeSet = clusterEdges.get(i);

        ClusterId cid = ClusterId.clusterId(i);
        DefaultTopologyCluster cluster = new DefaultTopologyCluster(cid,
                                                                    vertexSet.size(),
                                                                    edgeSet.size(),
                                                                    findRoot(vertexSet));
        clusterBuilder.put(cid, cluster);
    }
    return clusterBuilder.build();
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableSetMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(ImmutableSet.of(1), builder.build().get("one"));
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(ImmutableSet.of(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableSetMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(ImmutableSet.of(1), builder.build().get("one"));
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(ImmutableSet.of(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder
      = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}
项目:guava-libraries    文件:ImmutableSetMultimapTest.java   
@GwtIncompatible("SerializableTester")
public void testSortedSerialization() {
  Multimap<String, Integer> multimap = new ImmutableSetMultimap.Builder<String, Integer>()
      .orderKeysBy(Ordering.natural().reverse())
      .orderValuesBy(Ordering.usingToString())
      .put("a", 2)
      .put("a", 10)
      .put("b", 1)
      .build();
  multimap = SerializableTester.reserialize(multimap);
  assertThat(multimap.keySet()).containsExactly("b", "a").inOrder();
  assertThat(multimap.get("a")).containsExactly(10, 2).inOrder();
  assertEquals(Ordering.usingToString(),
      ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertEquals(Ordering.usingToString(),
      ((ImmutableSortedSet<Integer>) multimap.get("z")).comparator());
}
项目:guava    文件:ImmutableSetMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableSetMultimap.Builder<String, Integer> builder = new Builder<>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry =
      new AbstractMapEntry<String, Integer>() {
        @Override
        public String getKey() {
          return holder.string;
        }

        @Override
        public Integer getValue() {
          return 1;
        }
      };

  builder.put(entry);
  holder.string = "two";
  assertEquals(ImmutableSet.of(1), builder.build().get("one"));
}
项目:guava    文件:ImmutableSetMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(ImmutableSet.of(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(
      new Ordering<String>() {
        @Override
        public int compare(String left, String right) {
          return left.length() - right.length();
        }
      });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
  assertFalse(multimap.get("a") instanceof ImmutableSortedSet);
  assertFalse(multimap.get("x") instanceof ImmutableSortedSet);
  assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet);
}
项目:guava    文件:ImmutableSetMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableSetMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
  assertTrue(multimap.get("a") instanceof ImmutableSortedSet);
  assertEquals(
      Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator());
  assertTrue(multimap.get("x") instanceof ImmutableSortedSet);
  assertEquals(
      Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator());
  assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet);
  assertEquals(
      Collections.reverseOrder(),
      ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator());
}