Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove static variable allPaths so that getAllPaths method can be use…
…d in a threaded environment.

Change-Id: I489e13c284df141e57b68dc0258b036a12e209af
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
yapchunwei authored and egonw committed May 5, 2012
1 parent 36db127 commit 071169b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/main/org/openscience/cdk/graph/PathTools.java
Expand Up @@ -508,8 +508,6 @@ public static List<IAtom> getShortestPath(IAtomContainer atomContainer, IAtom st
return tmp;
}

private static List<List<IAtom>> allPaths;

/**
* Get a list of all the paths between two atoms.
* <p/>
Expand All @@ -523,13 +521,13 @@ public static List<IAtom> getShortestPath(IAtomContainer atomContainer, IAtom st
*/
@TestMethod("testGetAllPaths_IAtomContainer_IAtom_IAtom")
public static List<List<IAtom>> getAllPaths(IAtomContainer atomContainer, IAtom start, IAtom end) {
allPaths = new ArrayList<List<IAtom>>();
List<List<IAtom>> allPaths = new ArrayList<List<IAtom>>();
if (start.equals(end)) return allPaths;
findPathBetween(atomContainer, start, end, new ArrayList<IAtom>());
findPathBetween(allPaths, atomContainer, start, end, new ArrayList<IAtom>());
return allPaths;
}

private static void findPathBetween(IAtomContainer atomContainer, IAtom start, IAtom end, List<IAtom> path) {
private static void findPathBetween(List<List<IAtom>> allPaths, IAtomContainer atomContainer, IAtom start, IAtom end, List<IAtom> path) {
if (start == end) {
path.add(start);
allPaths.add(new ArrayList<IAtom>(path));
Expand All @@ -540,7 +538,7 @@ private static void findPathBetween(IAtomContainer atomContainer, IAtom start, I
return;
path.add(start);
List<IAtom> nbrs = atomContainer.getConnectedAtomsList(start);
for (IAtom nbr : nbrs) findPathBetween(atomContainer, nbr, end, path);
for (IAtom nbr : nbrs) findPathBetween(allPaths, atomContainer, nbr, end, path);
path.remove(path.size() - 1);
}

Expand Down

0 comments on commit 071169b

Please sign in to comment.