public Set < GraphObject > run ( ) { /** * Candidate contains all the graph objects that are the results of BFS. * Eliminating nodes from candidate according to the reached counts * will yield result. */ Map < GraphObject , Integer > candidate = new HashMap < GraphObject , Integer > ( ) ; Set < GraphObject > result = new HashSet < GraphObject > ( ) ; //for each set of states of entity, run BFS separately for ( Set < Node > source : sourceSet ) { //run BFS for set of states of each entity BFS bfs = new BFS ( source , null , direction , limit ) ; Map < GraphObject , Integer > BFSResult = new HashMap < GraphObject , Integer > ( ) ; BFSResult . putAll ( bfs . run ( ) ) ; /** * Reached counts of the graph objects that are in BFSResult will * be incremented by 1. */ for ( GraphObject go : BFSResult . keySet ( ) ) { setLabel ( go , ( getLabel ( go ) + 1 ) ) ; } //put BFS Result into candidate set candidate . putAll ( BFSResult ) ; } /** * Having a reached count equal to number of nodes in the source set * indicates being in common stream. */ for ( GraphObject go : candidate . keySet ( ) ) { if ( getLabel ( go ) == sourceSet . size ( ) ) { result . add ( go ) ; } } //Return the result of query return result ; }
Method to run the query .