org.jgrapht.traverse.BreadthFirstIterator Java Examples

The following examples show how to use org.jgrapht.traverse.BreadthFirstIterator. 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: ResourceManager.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
/**
 * Find the resources in {@link #resourcesGraph} matching the given {@code query}.
 *
 * @param query a location eventually containing wildcards
 * @param locationResolver the {@link LocationResolver} to perform the matching of graph nodes against the given
 *            {@code query}
 * @return an unmodifiable list of {@link Resources} that match the given {@code query}
 */
public List<Resource<L>> findResources(L query, LocationResolver<L> locationResolver) {
    graphLockRead.lock();
    try {
        List<Resource<L>> result = new ArrayList<Resource<L>>();
        GraphIterator<Resource<L>, DefaultEdge> it = new BreadthFirstIterator<Resource<L>, DefaultEdge>(
                this.resourcesGraph);
        while (it.hasNext()) {
            Resource<L> resource = it.next();
            if (locationResolver.matches(query, resource.getLocation())) {
                result.add(resource);
            }
        }
        return Collections.unmodifiableList(result);
    } finally {
        graphLockRead.unlock();
    }
}
 
Example #2
Source File: ModelInfoGraphAnalyzer.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Set<InfoVertex<T, C>> connectedSetOf(InfoVertex<T, C> vertex) {
	Set<InfoVertex<T, C>> connectedSet = vertexToConnectedSet.get(vertex);

	if (connectedSet == null) {
		connectedSet = new HashSet<InfoVertex<T, C>>();

		final BreadthFirstIterator<InfoVertex<T, C>, DependencyEdge> i = new BreadthFirstIterator<InfoVertex<T, C>, DependencyEdge>(
				graph, vertex);

		while (i.hasNext()) {
			connectedSet.add(i.next());
		}

		vertexToConnectedSet.put(vertex, connectedSet);
	}

	return connectedSet;
}
 
Example #3
Source File: MasterGraphChangeHandler.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
private void stopDirty()
{
   BreadthFirstIterator<AddonVertex, AddonDependencyEdge> iterator = new BreadthFirstIterator<AddonVertex, AddonDependencyEdge>(
            graph.getGraph());

   iterator.addTraversalListener(new TraversalListenerAdapter<AddonVertex, AddonDependencyEdge>()
   {
      @Override
      public void vertexTraversed(VertexTraversalEvent<AddonVertex> event)
      {
         if (event.getVertex().isDirty())
            lifecycleManager.stopAddon(event.getVertex().getAddon());
      };
   });

   while (iterator.hasNext())
      iterator.next();
}
 
Example #4
Source File: MasterGraphChangeHandler.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
private void stopRemoved()
{
   if (lastMasterGraph != null)
   {
      BreadthFirstIterator<AddonVertex, AddonDependencyEdge> iterator = new BreadthFirstIterator<AddonVertex, AddonDependencyEdge>(
               lastMasterGraph.getGraph());

      iterator.addTraversalListener(new TraversalListenerAdapter<AddonVertex, AddonDependencyEdge>()
      {
         @Override
         public void vertexTraversed(VertexTraversalEvent<AddonVertex> event)
         {
            if (event.getVertex().isDirty())
               lifecycleManager.stopAddon(event.getVertex().getAddon());
         };
      });

      while (iterator.hasNext())
         iterator.next();
   }
}
 
Example #5
Source File: GamlResourceIndexer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see msi.gama.lang.gaml.indexer.IModelIndexer#allImportsOf(org.eclipse.emf.common.util.URI)
 */
public static Iterator<URI> allImportsOf(final URI uri) {
	if (!indexes(uri)) {
		return Iterators.singletonIterator(uri);// .emptyIterator();
	}
	final Iterator<URI> result = new BreadthFirstIterator(index, GamlResourceServices.properlyEncodedURI(uri));
	result.next(); // to eliminate the uri
	return result;
}
 
Example #6
Source File: ResourceManager.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an immutable {@link List} of all {@link Resource}s contained in {@link #resourcesGraph} in breadth-first
 * order.
 *
 * @return the list of all {@link Resource}s
 */
public List<Resource<L>> getResourcesBreadthFirst() {
    graphLockRead.lock();
    try {
        List<Resource<L>> result = new ArrayList<Resource<L>>();

        Set<Resource<L>> roots = getRootResources();
        if (roots.isEmpty()) {
            return Collections.emptyList();
        }

        // loop over each root resource and traverse their tree hierarchy breadth-first
        // roots.forEach(root -> new BreadthFirstIterator<>(ResourceManager.this.resourcesGraph, root)
        //     .forEachRemaining(it -> result.add(it)));
        for (Resource<L> root : roots) {
            GraphIterator<Resource<L>, DefaultEdge> it = new BreadthFirstIterator<Resource<L>, DefaultEdge>(
                    ResourceManager.this.resourcesGraph, root);
            while (it.hasNext()) {
                result.add(it.next());
            }
        }

        return Collections.unmodifiableList(result);
    } finally {
        graphLockRead.unlock();
    }
}
 
Example #7
Source File: ResourceTypeManager.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an immutable {@link List} of all {@link ResourceType}s contained in {@link #resourceTypesGraph} in
 * breadth-first order.
 *
 * @return the list of all {@link ResourceType}s
 */
public List<ResourceType<L>> getResourceTypesBreadthFirst() {
    List<ResourceType<L>> result = new ArrayList<ResourceType<L>>();
    GraphIterator<ResourceType<L>, DefaultEdge> it = new BreadthFirstIterator<ResourceType<L>, DefaultEdge>(
            this.resourceTypesGraph);
    while (it.hasNext()) {
        result.add(it.next());
    }
    return Collections.unmodifiableList(result);
}
 
Example #8
Source File: DirectedGraphUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenDirectedGraph_whenCreateInstanceBreadthFirstIterator_thenGetIterator() {
    BreadthFirstIterator breadthFirstIterator = new BreadthFirstIterator<>(directedGraph);
    assertNotNull(breadthFirstIterator);
}