From 4fae0e890c4d696ffc60e4aa92b8ddf65b69edf3 Mon Sep 17 00:00:00 2001 From: Holt59 Date: Thu, 1 Mar 2018 21:20:17 +0100 Subject: [PATCH] Rename getInstance() -> getInputData(). Override getInputData() in solution classes to return correct type instead of abstract one. --- src/main/org/insa/algo/AbstractAlgorithm.java | 2 +- src/main/org/insa/algo/AbstractSolution.java | 2 +- .../StronglyConnectedComponentsAlgorithm.java | 4 +- .../StronglyConnectedComponentsSolution.java | 41 +++++++++++-------- .../strongconnectivity/TarjanAlgorithm.java | 4 +- .../WeaklyConnectedComponentsAlgorithm.java | 14 +++---- .../WeaklyConnectedComponentsSolution.java | 41 +++++++++++-------- .../graphics/ShortestPathSolutionPanel.java | 2 +- 8 files changed, 62 insertions(+), 48 deletions(-) diff --git a/src/main/org/insa/algo/AbstractAlgorithm.java b/src/main/org/insa/algo/AbstractAlgorithm.java index c487d4e..cdc748a 100644 --- a/src/main/org/insa/algo/AbstractAlgorithm.java +++ b/src/main/org/insa/algo/AbstractAlgorithm.java @@ -38,7 +38,7 @@ public abstract class AbstractAlgorithm { /** * @return Instance corresponding to this algorithm. */ - public AbstractData getInstance() { return instance; } + public AbstractData getInputData() { return instance; } /** * Run the algorithm and update the current solution. diff --git a/src/main/org/insa/algo/AbstractSolution.java b/src/main/org/insa/algo/AbstractSolution.java index bb5acf3..2069c51 100644 --- a/src/main/org/insa/algo/AbstractSolution.java +++ b/src/main/org/insa/algo/AbstractSolution.java @@ -43,7 +43,7 @@ public abstract class AbstractSolution { /** * @return Original instance for this solution. */ - public AbstractData getInstance() { return instance; } + public AbstractData getInputData() { return instance; } /** * @return Status of this solution. diff --git a/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsAlgorithm.java b/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsAlgorithm.java index 57d9f37..f0cea71 100644 --- a/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsAlgorithm.java +++ b/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsAlgorithm.java @@ -19,8 +19,8 @@ public abstract class StronglyConnectedComponentsAlgorithm extends AbstractAlgor } @Override - public StronglyConnectedComponentsData getInstance() { - return (StronglyConnectedComponentsData)super.getInstance(); + public StronglyConnectedComponentsData getInputData() { + return (StronglyConnectedComponentsData)super.getInputData(); } } diff --git a/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsSolution.java b/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsSolution.java index f96297d..753a6cb 100644 --- a/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsSolution.java +++ b/src/main/org/insa/algo/strongconnectivity/StronglyConnectedComponentsSolution.java @@ -6,23 +6,30 @@ import org.insa.algo.AbstractSolution; import org.insa.graph.Node; public class StronglyConnectedComponentsSolution extends AbstractSolution { - - // Components - private ArrayList> components; - protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) { - super(instance); - } - - protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance, - Status status, ArrayList> components) { - super(instance, status); - this.components = components; - } - - /** - * @return Components of the solution, if any. - */ - public ArrayList> getComponents() { return components; } + // Components + private ArrayList> components; + + protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) { + super(instance); + } + + protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance, Status status, + ArrayList> components) { + super(instance, status); + this.components = components; + } + + @Override + public StronglyConnectedComponentsData getInputData() { + return (StronglyConnectedComponentsData) super.getInputData(); + } + + /** + * @return Components of the solution, if any. + */ + public ArrayList> getComponents() { + return components; + } } diff --git a/src/main/org/insa/algo/strongconnectivity/TarjanAlgorithm.java b/src/main/org/insa/algo/strongconnectivity/TarjanAlgorithm.java index 3cd8771..ccff6aa 100644 --- a/src/main/org/insa/algo/strongconnectivity/TarjanAlgorithm.java +++ b/src/main/org/insa/algo/strongconnectivity/TarjanAlgorithm.java @@ -114,7 +114,7 @@ public class TarjanAlgorithm extends StronglyConnectedComponentsAlgorithm { @Override protected StronglyConnectedComponentsSolution doRun() { - Graph graph = getInstance().getGraph(); + Graph graph = getInputData().getGraph(); components = new ArrayList>(); @@ -138,7 +138,7 @@ public class TarjanAlgorithm extends StronglyConnectedComponentsAlgorithm { } } - return new StronglyConnectedComponentsSolution(getInstance(), Status.OPTIMAL, components); + return new StronglyConnectedComponentsSolution(getInputData(), Status.OPTIMAL, components); } } diff --git a/src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java b/src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java index 8dc96c0..13eed13 100644 --- a/src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java +++ b/src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java @@ -30,8 +30,8 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm> createUndirectedGraph() { - int nNodes = getInstance().getGraph().getNodes().size(); + int nNodes = getInputData().getGraph().getNodes().size(); ArrayList> res = new ArrayList>(nNodes); for (int i = 0; i < nNodes; ++i) { res.add(new HashSet()); } - for (Node node: getInstance().getGraph().getNodes()) { + for (Node node: getInputData().getGraph().getNodes()) { for (Arc arc: node.getSuccessors()) { res.get(node.getId()).add(arc.getDestination().getId()); if (arc.getRoadInformation().isOneWay()) { @@ -101,7 +101,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm bfs(ArrayList> ugraph, boolean[] marked, int cur) { - List nodes = getInstance().getGraph().getNodes(); + List nodes = getInputData().getGraph().getNodes(); ArrayList component = new ArrayList(); // Using a queue because we are doing a BFS @@ -137,7 +137,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm> ugraph = createUndirectedGraph(); boolean[] marked = new boolean[graph.getNodes().size()]; Arrays.fill(marked, false); @@ -155,7 +155,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm> components; - protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) { - super(instance); - } - - protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance, - Status status, ArrayList> components) { - super(instance, status); - this.components = components; - } - - /** - * @return Components of the solution, if any. - */ - public ArrayList> getComponents() { return components; } + // Components + private ArrayList> components; + + protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) { + super(instance); + } + + protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance, Status status, + ArrayList> components) { + super(instance, status); + this.components = components; + } + + @Override + public WeaklyConnectedComponentsData getInputData() { + return (WeaklyConnectedComponentsData) super.getInputData(); + } + + /** + * @return Components of the solution, if any. + */ + public ArrayList> getComponents() { + return components; + } } diff --git a/src/main/org/insa/graphics/ShortestPathSolutionPanel.java b/src/main/org/insa/graphics/ShortestPathSolutionPanel.java index e92fb11..ed49292 100644 --- a/src/main/org/insa/graphics/ShortestPathSolutionPanel.java +++ b/src/main/org/insa/graphics/ShortestPathSolutionPanel.java @@ -70,7 +70,7 @@ public class ShortestPathSolutionPanel extends JPanel implements DrawingChangeLi * @return Data assocaited with this bundle. */ public ShortestPathData getData() { - return (ShortestPathData) this.solution.getInstance(); + return this.solution.getInputData(); } /**