Skip to content

Commit 501ff3e

Browse files
committed
refactoring
1 parent d6283b9 commit 501ff3e

22 files changed

+126
-67
lines changed

src/main/java/com/hendrix/erdos/Erdos.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ static public AbstractGraph cloneGraphOf(IGraph graph) {
6161
*
6262
* @return a new graph
6363
*/
64-
static public <T extends IGraphEngine> AbstractGraph newGraphWithEngine(final T graphEngine, final EDGE_DIRECTION direction,
64+
static public <T extends IGraphEngine, R extends AbstractGraph> R newGraphWithEngine(final T graphEngine, final EDGE_DIRECTION direction,
6565
final boolean selfLoops, final boolean multiEdges) {
6666
switch (direction) {
6767
case DIRECTED:
68-
return newDirectedGraphWithEngine(graphEngine, selfLoops, multiEdges);
68+
return (R) newDirectedGraphWithEngine(graphEngine, selfLoops, multiEdges);
6969
case UNDIRECTED:
70-
return newUndirectedGraphWithEngine(graphEngine, selfLoops, multiEdges);
70+
return (R) newUndirectedGraphWithEngine(graphEngine, selfLoops, multiEdges);
7171
}
7272

7373
return null;
@@ -83,7 +83,7 @@ static public <T extends IGraphEngine> AbstractGraph newGraphWithEngine(final T
8383
*
8484
* @return a new graph
8585
*/
86-
static private <T extends IGraphEngine> DirectedGraph newDirectedGraphWithEngine(final T graphEngine, final boolean selfLoops,
86+
static public <T extends IGraphEngine> DirectedGraph newDirectedGraphWithEngine(final T graphEngine, final boolean selfLoops,
8787
final boolean multiEdges) {
8888
return new DirectedGraph() {
8989
@Override
@@ -113,7 +113,7 @@ public IGraphEngine graphEngineFactory() {
113113
*
114114
* @return a new graph
115115
*/
116-
static private <T extends IGraphEngine> UndirectedGraph newUndirectedGraphWithEngine(final T graphEngine, final boolean selfLoops,
116+
static public <T extends IGraphEngine> UndirectedGraph newUndirectedGraphWithEngine(final T graphEngine, final boolean selfLoops,
117117
final boolean multiEdges) {
118118
return new UndirectedGraph() {
119119
@Override

src/main/java/com/hendrix/erdos/algorithms/GraphAlgorithm.java renamed to src/main/java/com/hendrix/erdos/algorithms/AbstractGraphAlgorithm.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
* @param <T> the return type of the algorithm
99
* @param <E> the input type of the algorithm
1010
*/
11-
abstract public class GraphAlgorithm<T, E extends IGraph> implements IGraphAlgorithm<T, E>
11+
abstract public class AbstractGraphAlgorithm<T, E extends IGraph> implements IGraphAlgorithm<T, E>
1212
{
1313
protected E _graph_input = null;
1414
protected T _result_algorithm = null;
1515
protected String _tag = "empty";
1616

17-
public GraphAlgorithm(E graph_input, String tag) {
17+
public AbstractGraphAlgorithm(E graph_input, String tag) {
1818
_graph_input = graph_input;
1919
_tag = tag;
2020
}
2121

22-
public GraphAlgorithm(E graph_input) {
22+
public AbstractGraphAlgorithm(E graph_input) {
2323
this(graph_input, null);
2424
}
2525

26-
public GraphAlgorithm(String tag) {
26+
public AbstractGraphAlgorithm(String tag) {
2727
this(null, tag);
2828
}
2929

30-
public GraphAlgorithm() {}
30+
public AbstractGraphAlgorithm() {}
3131

3232
@Override
3333
public void setInputGraph(E graph) {

src/main/java/com/hendrix/erdos/algorithms/AbstractShortestPathAlgorithm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @author Tomer Shalev
1919
*/
2020
@SuppressWarnings("UnusedDeclaration")
21-
abstract public class AbstractShortestPathAlgorithm<E extends IGraph> extends GraphAlgorithm<ShortestPathsTree, E> {
21+
abstract public class AbstractShortestPathAlgorithm<E extends IGraph> extends AbstractGraphAlgorithm<ShortestPathsTree, E> {
2222
/**
2323
* the predecessor of u is stored in PIE. If u has no predecessor (for example, if u = s or u has not been discovered), then π[u] = NIL
2424
*/

src/main/java/com/hendrix/erdos/algorithms/BFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @author Tomer Shalev
2121
*/
22-
public class BFS extends GraphAlgorithm<BreadthFirstTree, IGraph>
22+
public class BFS extends AbstractGraphAlgorithm<BreadthFirstTree, IGraph>
2323
{
2424
protected IVertex _sourceIVertex = null;
2525
/**

src/main/java/com/hendrix/erdos/algorithms/DFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* @author Tomer Shalev
1919
*/
20-
public class DFS extends GraphAlgorithm<DFS.DepthFirstForest, IGraph>
20+
public class DFS extends AbstractGraphAlgorithm<DFS.DepthFirstForest, IGraph>
2121
{
2222
/**
2323
* edge classification

src/main/java/com/hendrix/erdos/algorithms/FloydWarshall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @author Tomer Shalev
1010
*/
1111
@SuppressWarnings("UnusedDeclaration")
12-
public class FloydWarshall extends GraphAlgorithm<AllPairsShortPathResult, IDirectedGraph> {
12+
public class FloydWarshall extends AbstractGraphAlgorithm<AllPairsShortPathResult, IDirectedGraph> {
1313

1414
public FloydWarshall(IDirectedGraph graph_input) {
1515
super(graph_input, "result Floyd Warshall Algorithm");

src/main/java/com/hendrix/erdos/algorithms/Johnson.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @author Tomer Shalev
2727
*/
2828
@SuppressWarnings("UnusedDeclaration")
29-
public class Johnson extends GraphAlgorithm<AllPairsShortPathResult, IDirectedGraph> {
29+
public class Johnson extends AbstractGraphAlgorithm<AllPairsShortPathResult, IDirectedGraph> {
3030
private HashMap<IVertex, Float> H = null;
3131
private EdgeFunction W_cap = null;
3232

src/main/java/com/hendrix/erdos/algorithms/MSTKruskal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @see MinSpanTreeFactory
2020
*/
2121
@SuppressWarnings("UnusedDeclaration")
22-
public class MSTKruskal extends GraphAlgorithm<UndirectedGraph, IUndirectedGraph> {
22+
public class MSTKruskal extends AbstractGraphAlgorithm<UndirectedGraph, IUndirectedGraph> {
2323

2424
public MSTKruskal(IUndirectedGraph graph_input) {
2525
super(graph_input, "MST_Kruskal");

src/main/java/com/hendrix/erdos/algorithms/MSTPrim.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @author Tomer Shalev
1818
*/
1919
@SuppressWarnings("UnusedDeclaration")
20-
public class MSTPrim extends GraphAlgorithm<UndirectedGraph, IUndirectedGraph> {
20+
public class MSTPrim extends AbstractGraphAlgorithm<UndirectedGraph, IUndirectedGraph> {
2121
/**
2222
* the predecessor of u is stored in PIE. If u has no predecessor (for example, if u = s or u has not been discovered), then π[u] = NIL
2323
*/
@@ -54,7 +54,7 @@ public UndirectedGraph applyAlgorithm() {
5454
*
5555
* @param vertex the starting vertex
5656
*/
57-
public GraphAlgorithm<UndirectedGraph, IUndirectedGraph> setStartVertex(IVertex vertex) {
57+
public AbstractGraphAlgorithm<UndirectedGraph, IUndirectedGraph> setStartVertex(IVertex vertex) {
5858
_startVertex = vertex;
5959

6060
return this;

src/main/java/com/hendrix/erdos/algorithms/SCC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* computes the Strongly Connected Components of input Graph G
1717
* @author Tomer Shalev
1818
*/
19-
public class SCC extends GraphAlgorithm<ArrayList<HashSet<IVertex>>, IDirectedGraph> {
19+
public class SCC extends AbstractGraphAlgorithm<ArrayList<HashSet<IVertex>>, IDirectedGraph> {
2020

2121
public SCC(IDirectedGraph graph_input) {
2222
super(graph_input, "Strongly Connected Components");

0 commit comments

Comments
 (0)