Example usage for java.util Queue removeAll

List of usage examples for java.util Queue removeAll

Introduction

In this page you can find the example usage for java.util Queue removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes all of this collection's elements that are also contained in the specified collection (optional operation).

Usage

From source file:playground.johannes.statistics.GraphStatistics.java

public static SortedSet<Collection<Vertex>> getDisconnectedComponents(Graph g) {
    TreeSet<Collection<Vertex>> clusters = new TreeSet<Collection<Vertex>>(new SizeComparator());
    CentralityGraphDecorator graphDecorator = new CentralityGraphDecorator(g);
    UnweightedDijkstra dijkstra = new UnweightedDijkstra((CentralityGraph) graphDecorator.getSparseGraph());
    Queue<CentralityVertex> vertices = new LinkedList<CentralityVertex>();
    for (SparseVertex v : graphDecorator.getSparseGraph().getVertices())
        vertices.add((CentralityVertex) v);

    CentralityVertex source;//from  w w w . j ava 2  s .  c o  m
    while ((source = vertices.poll()) != null) {
        List<CentralityVertex> reached = dijkstra.run(source);
        reached.add(source);
        List<Vertex> reached2 = new LinkedList<Vertex>();
        for (CentralityVertex cv : reached)
            reached2.add(graphDecorator.getVertex(cv));
        clusters.add(reached2);
        vertices.removeAll(reached);
    }

    return clusters;
}

From source file:playground.johannes.statistics.SampledGraphStatistics.java

public static SortedSet<Collection<SampledVertex>> getDisconnectedComponents(SampledGraph g) {
    TreeSet<Collection<SampledVertex>> clusters = new TreeSet<Collection<SampledVertex>>(new SizeComparator());
    CentralityGraphDecorator graphDecorator = new CentralityGraphDecorator(g);
    UnweightedDijkstra dijkstra = new UnweightedDijkstra((CentralityGraph) graphDecorator.getSparseGraph());
    Queue<CentralityVertex> vertices = new LinkedList<CentralityVertex>();
    for (SparseVertex v : graphDecorator.getSparseGraph().getVertices())
        vertices.add((CentralityVertex) v);

    CentralityVertex source;//from   w w  w  .  ja  v a2s. c o m
    while ((source = vertices.poll()) != null) {
        List<CentralityVertex> reached = dijkstra.run(source);
        reached.add(source);
        List<SampledVertex> reached2 = new LinkedList<SampledVertex>();
        for (CentralityVertex cv : reached)
            reached2.add((SampledVertex) graphDecorator.getVertex(cv));
        clusters.add(reached2);
        vertices.removeAll(reached);
    }

    return clusters;
}