Skip to content
Permalink
Browse files

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 4, 2012
1 parent 0fbe8cc commit ea828a914754d58658f10d819a24843923eebfeb
Showing with 4 additions and 6 deletions.
  1. +4 −6 src/main/org/openscience/cdk/graph/PathTools.java
@@ -508,8 +508,6 @@ public static int getVertexCountAtDistance(IAtomContainer atomContainer, int dis
return tmp;
}

private static List<List<IAtom>> allPaths;

/**
* Get a list of all the paths between two atoms.
* <p/>
@@ -523,13 +521,13 @@ public static int getVertexCountAtDistance(IAtomContainer atomContainer, int dis
*/
@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));
@@ -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);
}

0 comments on commit ea828a9

Please sign in to comment.
You can’t perform that action at this time.