diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml
index 7c1620d7..15f6d726 100755
--- a/.github/workflows/ant.yml
+++ b/.github/workflows/ant.yml
@@ -1,17 +1,32 @@
name: Java CI
-on: [push]
+on: [push, pull_request]
jobs:
- build:
+ build-and-test:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v1
- - name: Set up JDK 1.8
- uses: actions/setup-java@v1
+ - uses: actions/checkout@v4
+
+ - name: Set up JDK 11
+ uses: actions/setup-java@v4
with:
- java-version: 1.8
+ java-version: '11'
+ distribution: 'temurin'
+
+ - name: Download JUnit 5 dependencies
+ run: |
+ mvn dependency:get -q -Dartifact=org.junit.jupiter:junit-jupiter-api:5.9.3
+ mvn dependency:get -q -Dartifact=org.junit.jupiter:junit-jupiter-engine:5.9.3
+ mvn dependency:get -q -Dartifact=org.junit.platform:junit-platform-engine:1.9.3
+ mvn dependency:get -q -Dartifact=org.junit.platform:junit-platform-commons:1.9.3
+ mvn dependency:get -q -Dartifact=org.junit.platform:junit-platform-launcher:1.9.3
+ mvn dependency:get -q -Dartifact=org.opentest4j:opentest4j:1.2.0
+
- name: Build with Ant
- run: ant -noinput -buildfile build.xml
+ run: ant -noinput
+
+ - name: Run tests
+ run: ant -noinput test
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 00000000..3d792843
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,105 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## Build & Run
+
+```bash
+# Full clean build + run (with JDWP debug port 8000)
+./make.sh
+
+# Build only
+ant clean && ant
+
+# Run the built JAR
+java -jar binary/graphtea-main.jar
+
+# Platform-specific launchers
+./GraphTea-linux.sh
+./GraphTea-mac.sh
+./GraphTea-windows.bat
+
+# Create distribution packages (macOS .dmg, Windows .exe, Linux .deb)
+./create_packages.sh
+```
+
+Build output goes to `build/` (compiled classes) and `binary/` (JARs, plugins, extensions).
+
+## Tests
+
+Tests use JUnit 5 and live in `/test/`. There is no dedicated test runner script — run tests through your IDE or a JUnit runner with the classpath from `src/scripts/lib/`.
+
+## Code Style (Checkstyle)
+
+Checkstyle 10 enforces style on all **new** source files. Existing files are grandfathered
+in `config/checkstyle-suppressions.xml` and are exempt until cleaned up.
+
+```bash
+# Report violations (never fails the build — good for local inspection)
+ant checkstyle
+
+# Strict mode — fails the build on any violation (use in CI)
+ant checkstyle-strict
+
+# CLI equivalent (exit code = number of errors; 0 = clean)
+java -jar tools/checkstyle.jar -c config/checkstyle.xml \
+ -p config/checkstyle.properties src/graphtea
+```
+
+Key rules enforced on new code (`config/checkstyle.xml`):
+- Braces required on all `if`/`for`/`while` bodies (`NeedBraces`)
+- No `==` for string comparison (`StringLiteralEquality`)
+- No unused or redundant imports
+- `L` suffix on long literals, not `l`
+- One statement per line; array brackets on type (`String[]` not `String []`)
+- Whitespace around operators and after keywords
+- Modifier order (`public static final`, not `static public final`)
+- Complexity limits: cyclomatic ≤ 15, nesting depth ≤ 4
+
+To **add a new file** to the suppression baseline (only if truly needed):
+```xml
+
+
+```
+Prefer fixing violations over suppressing them.
+
+## Architecture
+
+GraphTea is a **Java Swing desktop application** for graph theory, built around a plugin-extension architecture.
+
+### Core Concepts
+
+**BlackBoard** (`src/graphtea/platform/core/BlackBoard.java`)
+The central event bus and state store. All inter-component communication flows through it. Components call `blackboard.setData(key, value)` to publish and `blackboard.addListener(key, listener)` to subscribe. This replaces direct dependencies between plugins.
+
+**Plugin System** (`src/graphtea/platform/plugin/Plugger.java`)
+Plugins are JAR files in `binary/plugins/`. Each JAR's manifest declares `plugin-name`, `plugin-version`, and `plugin-depends`. Plugger resolves load order via DFS topological sort. Each plugin has an `Init` class at `graphtea.plugins..Init` (or a custom manifest-specified class).
+
+**Extension System** (`src/graphtea/platform/extension/`)
+Extensions are JARs in `binary/extensions/`, dynamically loaded at startup. They implement typed interfaces:
+- `AlgorithmExtension` — graph algorithms
+- `GraphGeneratorExtension` — graph generators
+- `ReportExtension` — computed graph properties/reports
+- `ActionExtension` — graph transformations (products, line graphs, etc.)
+
+### Module Layout
+
+| Package | Role |
+|---|---|
+| `graphtea.platform` | Bootstrapping, BlackBoard, plugin/extension loading, preferences |
+| `graphtea.graph` | Core graph model (`GraphModel`, `Vertex`, `Edge`), rendering, events |
+| `graphtea.library` | Pure graph algorithm library, utilities |
+| `graphtea.plugins` | Main UI, visualization, generators, algorithm animator, reports UI |
+| `graphtea.extensions` | Concrete algorithms, generators, reports, actions (the bulk of domain logic) |
+| `graphtea.ui` | Swing UI components: property editors, sidebars, menus |
+| `graphtea.samples` | Example extension implementations |
+
+### Entry Point
+
+`graphtea.platform.Application.main()` → initializes BlackBoard → loads Preferences → loads Plugins (from `binary/plugins/`) → loads Extensions (from `binary/extensions/`) → fires `POST_INIT_EVENT`.
+
+### Adding a New Extension
+
+1. Implement the appropriate interface (e.g., `ReportExtension`).
+2. Build it as a JAR and drop it in `binary/extensions/`.
+3. See `src/graphtea/samples/` for working examples.
diff --git a/build.xml b/build.xml
index 208233e9..cabf39b5 100755
--- a/build.xml
+++ b/build.xml
@@ -37,7 +37,71 @@
The ant build file of GraphTea Project.
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -270,6 +334,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/config/checkstyle-suppressions.xml b/config/checkstyle-suppressions.xml
new file mode 100644
index 00000000..12bc3865
--- /dev/null
+++ b/config/checkstyle-suppressions.xml
@@ -0,0 +1,691 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/config/checkstyle.properties b/config/checkstyle.properties
new file mode 100644
index 00000000..e7b24fde
--- /dev/null
+++ b/config/checkstyle.properties
@@ -0,0 +1 @@
+config_loc=config
diff --git a/config/checkstyle.xml b/config/checkstyle.xml
new file mode 100644
index 00000000..34948155
--- /dev/null
+++ b/config/checkstyle.xml
@@ -0,0 +1,186 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/graphtea/extensions/AlgorithmUtils.java b/src/graphtea/extensions/AlgorithmUtils.java
index 496c2132..249d8417 100755
--- a/src/graphtea/extensions/AlgorithmUtils.java
+++ b/src/graphtea/extensions/AlgorithmUtils.java
@@ -5,6 +5,8 @@
package graphtea.extensions;
+import java.util.ArrayList;
+import java.util.List;
import Jama.EigenvalueDecomposition;
import Jama.Matrix;
import graphtea.extensions.algorithms.shortestpath.algs.FloydWarshall;
@@ -73,7 +75,7 @@ boolean isCompleteGraph(GraphModel g) {
Path getPath(GraphModel g, Vertex source, Vertex dest) {
boolean[] vertexMarksBackup = LibraryUtils.getVertexMarks(g);
clearVertexMarks(g);
- Vector q = new Vector<>();
+ List q = new ArrayList<>();
q.add(source);
source.setMark(true);
@@ -494,7 +496,7 @@ public static String getEigenValues(Matrix A) {
double[] rv = ed.getRealEigenvalues();
double[] iv = ed.getImagEigenvalues();
String res = "";
- Vector EigenValues = new Vector<>();
+ List EigenValues = new ArrayList<>();
for (int i = 0; i < rv.length; i++) {
if (iv[i] != 0)
res +="" + AlgorithmUtils.round(rv[i],10) + " + " + AlgorithmUtils.round(iv[i],10) + "i";
@@ -586,13 +588,8 @@ public static GraphModel createLineGraph(GraphModel g1) {
g2.insertVertex(v);
}
for (Vertex v : g1) {
- Iterator ie = g1.lightEdgeIterator(v);
-
- while (ie.hasNext()) {
- Edge e = ie.next();
- Iterator ie2 = g1.lightEdgeIterator(v);
- while (ie2.hasNext()) {
- Edge e2 = ie2.next();
+ for (Edge e : g1.edges(v)) {
+ for (Edge e2 : g1.edges(v)) {
if (e != e2) {
Edge ne = new Edge((Vertex) e.getProp().obj, (Vertex) e2.getProp().obj);
g2.insertEdge(ne);
diff --git a/src/graphtea/extensions/G6Format.java b/src/graphtea/extensions/G6Format.java
index a9d9b865..7d71c873 100755
--- a/src/graphtea/extensions/G6Format.java
+++ b/src/graphtea/extensions/G6Format.java
@@ -6,7 +6,8 @@
import graphtea.graph.graph.Vertex;
import java.util.HashMap;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* Created by rostam on 2/11/17.
@@ -40,9 +41,9 @@ int SETBT(int pos) {
}
- public static HashMap> stringToGraph(String g6) {
+ public static HashMap> stringToGraph(String g6) {
int n = graphsize(g6);
- HashMap> graph = new HashMap<>();
+ HashMap> graph = new HashMap<>();
String p = g6;
if (g6.charAt(0) == ':' || g6.charAt(0) == '&')
p = g6.substring(1);
@@ -62,7 +63,7 @@ public static HashMap> stringToGraph(String g6) {
}
if ((x & TOPBIT6) != 0) {
if (!graph.containsKey(i)) {
- graph.put(i, new Vector<>());
+ graph.put(i, new ArrayList<>());
}
graph.get(i).add(j);
}
@@ -126,29 +127,28 @@ public static String graphToG6(GraphModel g) {
}
public static String createAdjMatrix (Matrix m){
- String result="";
+ StringBuilder result = new StringBuilder();
for (int i = 1, k = 1; k < m.getColumnDimension(); i++, k++) {
for (int j = 0; j < i; j++) {
- if (m.get(j,i) != 0) result += "1";
- else result += "0";
+ result.append(m.get(j, i) != 0 ? '1' : '0');
}
}
- return result;
+ return result.toString();
}
public static String encodeGraph(int NoNodes, String adjmatrix) {
- String rv = "";
int[] nn = encodeN(NoNodes);
int[] adj = encodeR(adjmatrix);
int[] res = new int[nn.length + adj.length];
System.arraycopy(nn, 0, res, 0, nn.length);
System.arraycopy(adj, 0, res, nn.length, adj.length);
+ StringBuilder rv = new StringBuilder();
for (int re : res) {
- rv = rv + (char) re;
+ rv.append((char) re);
}
- return rv;
+ return rv.toString();
}
private static int[] encodeN(long i) {
@@ -189,16 +189,17 @@ private static int[] encodeR(String a) {
private static String padR(String str) {
int padwith = 6 - (str.length() % 6);
+ StringBuilder sb = new StringBuilder(str);
for (int i = 0; i < padwith; i++) {
- str += "0";
+ sb.append('0');
}
- return str;
+ return sb.toString();
}
private static String padL(String str, int h) {
- String retval = "";
+ StringBuilder retval = new StringBuilder();
for (int i = 0; i < h - str.length(); i++) {
- retval += "0";
+ retval.append('0');
}
return retval + str;
}
diff --git a/src/graphtea/extensions/actions/ComplementGraph.java b/src/graphtea/extensions/actions/ComplementGraph.java
index c5f1b16a..ac37e836 100755
--- a/src/graphtea/extensions/actions/ComplementGraph.java
+++ b/src/graphtea/extensions/actions/ComplementGraph.java
@@ -31,13 +31,14 @@ public void action(GraphData graphData) {
}
- for(Vertex v1 : g1.getVertexArray()) {
- for(Vertex v2 : g1.getVertexArray()) {
- if(v1.getId() != v2.getId()) {
- if (!g1.isEdge(v1, v2)) {
- g2.addEdge(new Edge(g2.getVertex(v1.getId()),
- g2.getVertex(v2.getId())));
- }
+ Vertex[] verts = g1.getVertexArray();
+ for (int i = 0; i < verts.length; i++) {
+ for (int j = i + 1; j < verts.length; j++) {
+ // Use i < j so each unordered pair is visited exactly once,
+ // avoiding duplicate edges in the (always-undirected) complement.
+ if (!g1.isEdge(verts[i], verts[j])) {
+ g2.addEdge(new Edge(g2.getVertex(verts[i].getId()),
+ g2.getVertex(verts[j].getId())));
}
}
}
diff --git a/src/graphtea/extensions/actions/GraphPower.java b/src/graphtea/extensions/actions/GraphPower.java
index c7b975a3..7a7f553b 100755
--- a/src/graphtea/extensions/actions/GraphPower.java
+++ b/src/graphtea/extensions/actions/GraphPower.java
@@ -14,7 +14,8 @@
import graphtea.plugins.main.GraphData;
import graphtea.plugins.main.extension.GraphActionExtension;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Azin Azadi
@@ -25,8 +26,8 @@ public class GraphPower implements GraphActionExtension, Parametrizable {
@Parameter
public int k = 2;
- Vector toInsert = new Vector<>();
- Vector subtree = new Vector<>();
+ List toInsert = new ArrayList<>();
+ List subtree = new ArrayList<>();
public String getName() {
return "Create Power Graph";
@@ -66,8 +67,8 @@ void aStar(Vertex root, Vertex v, int k, GraphModel g) {
}
public String checkParameters() {
- toInsert = new Vector<>();
- subtree = new Vector<>();
+ toInsert = new ArrayList<>();
+ subtree = new ArrayList<>();
return (k < 2 ? "K must be larger than 1" : null);
}
diff --git a/src/graphtea/extensions/actions/g6/G6CSVStringLoader.java b/src/graphtea/extensions/actions/g6/G6CSVStringLoader.java
index 1e546976..66749038 100755
--- a/src/graphtea/extensions/actions/g6/G6CSVStringLoader.java
+++ b/src/graphtea/extensions/actions/g6/G6CSVStringLoader.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
package graphtea.extensions.actions.g6;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.extensions.G6Format;
import graphtea.graph.graph.GPoint;
@@ -50,7 +51,7 @@ public void action(GraphData graphData) {
try {
file_scan = new Scanner(curFile);
} catch (FileNotFoundException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
int given_id = sc.nextInt();
@@ -60,7 +61,7 @@ public void action(GraphData graphData) {
if (id == given_id)
g6 = line.substring(line.lastIndexOf(",") + 1).trim();
}
- if(!g6.equals("")) {
+ if(!g6.isEmpty()) {
GraphModel g = G6Format.stringToGraphModel(g6);
GPoint[] pp = PositionGenerators.circle(200, 400, 250, g.numOfVertices());
diff --git a/src/graphtea/extensions/algorithms/BiconnectedComponents.java b/src/graphtea/extensions/algorithms/BiconnectedComponents.java
index 1c55434a..a560eedf 100755
--- a/src/graphtea/extensions/algorithms/BiconnectedComponents.java
+++ b/src/graphtea/extensions/algorithms/BiconnectedComponents.java
@@ -13,10 +13,12 @@
import graphtea.library.algorithms.util.EventUtils;
import graphtea.library.util.Pair;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Stack;
-import java.util.Vector;
+import java.util.List;
/**
* This Method find the biconnected components of a
@@ -31,8 +33,8 @@ public class BiconnectedComponents extends Algorithm implements AutomatedAlgorit
Integer[] DFS_Number;
Integer[] High;
int[] parent;
- Vector, Vector>> BiC = new Vector<>();
- Vector> ret;
+ List, List>> BiC = new ArrayList<>();
+ List> ret;
int DFS_N;
private Vertex root;
@@ -91,7 +93,7 @@ private static class VE {
int rootChilds = 0;
int foundDecompositions;
- Stack S = new Stack<>(); //stack is initially empty
+ Deque S = new ArrayDeque<>(); //stack is initially empty
/**
* This method is in fact dfs, with some preworks and postworks
@@ -144,12 +146,12 @@ private void BC(GraphModel g, Vertex v) {
}
- public Vector> biconnected_components(GraphModel g, Vertex v, int n) {
+ public List> biconnected_components(GraphModel g, Vertex v, int n) {
DFS_Number=new Integer[n];
High=new Integer[n];
parent=new int[n];
- S = new Stack<>();
- ret= new Vector<>();
+ S = new ArrayDeque<>();
+ ret = new ArrayList<>();
for (Vertex scan : g)
DFS_Number[scan.getId()] = 0;
diff --git a/src/graphtea/extensions/algorithms/CholeskyFactorizationExtension.java b/src/graphtea/extensions/algorithms/CholeskyFactorizationExtension.java
index 10afcfcd..f1bed1c0 100755
--- a/src/graphtea/extensions/algorithms/CholeskyFactorizationExtension.java
+++ b/src/graphtea/extensions/algorithms/CholeskyFactorizationExtension.java
@@ -1,5 +1,6 @@
package graphtea.extensions.algorithms;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -7,8 +8,7 @@
import graphtea.plugins.algorithmanimator.core.GraphAlgorithm;
import graphtea.plugins.algorithmanimator.extension.AlgorithmExtension;
-import java.util.Vector;
-
+import java.util.ArrayList;
/**
* author: rostam
* author: azin
@@ -24,7 +24,7 @@ public void doAlgorithm() {
while(g.getEdgesCount() > 0) {
Vertex v1 = requestVertex(g, "select a vertex");
step("Clique on neighbours");
- Vector vs = new Vector<>(g.directNeighbors(v1));
+ List vs = new ArrayList<>(g.directNeighbors(v1));
for(Vertex vv1 : vs)
for(Vertex vv2 : vs)
g.addEdge(new Edge(vv1,vv2));
diff --git a/src/graphtea/extensions/algorithms/Cluster.java b/src/graphtea/extensions/algorithms/Cluster.java
index aa9894bd..3f0f1396 100755
--- a/src/graphtea/extensions/algorithms/Cluster.java
+++ b/src/graphtea/extensions/algorithms/Cluster.java
@@ -1,5 +1,6 @@
package graphtea.extensions.algorithms;
+import java.util.List;
import graphtea.graph.graph.GPoint;
import java.util.ArrayList;
diff --git a/src/graphtea/extensions/algorithms/DAG.java b/src/graphtea/extensions/algorithms/DAG.java
index 5dc726b2..9512d457 100755
--- a/src/graphtea/extensions/algorithms/DAG.java
+++ b/src/graphtea/extensions/algorithms/DAG.java
@@ -5,6 +5,8 @@
package graphtea.extensions.algorithms;
+import java.util.ArrayList;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -237,18 +239,18 @@ public static AbstractList doSort(GraphModel graph) {
/**
* finds all paths in the given DAG from src to trg.
*/
- public static
- Vector> findAllPaths(GraphModel dag, Vertex src, Vertex trg) {
- Vector> ret = new Vector<>();
- findAllPathsRec(dag, src, trg, ret, new Stack<>());
+ public static
+ List> findAllPaths(GraphModel dag, Vertex src, Vertex trg) {
+ List> ret = new ArrayList<>();
+ findAllPathsRec(dag, src, trg, ret, new ArrayDeque<>());
return ret;
}
- private static
- void findAllPathsRec(GraphModel graph, Vertex src, Vertex trg, Vector> ret, Stack currentPath) {
+ private static
+ void findAllPathsRec(GraphModel graph, Vertex src, Vertex trg, List> ret, Deque currentPath) {
currentPath.push(src);
if (src == trg) {
- ret.add((Stack) currentPath.clone());
+ ret.add(new ArrayDeque<>(currentPath));
} else {
for (Vertex v : graph.getNeighbors(src)) {
findAllPathsRec(graph, v, trg, ret, currentPath);
@@ -262,8 +264,8 @@ void findAllPathsRec(GraphModel graph, Vertex src, Vertex trg, Vector findAllAncestors(GraphModel dag, Vertex src) {
- Vector ret = new Vector<>();
+ List findAllAncestors(GraphModel dag, Vertex src) {
+ List ret = new ArrayList<>();
Queue q = new LinkedList<>();
q.add(src);
while (!q.isEmpty()) {
diff --git a/src/graphtea/extensions/algorithms/EdgeInduced.java b/src/graphtea/extensions/algorithms/EdgeInduced.java
index cae8259a..4532aaa6 100755
--- a/src/graphtea/extensions/algorithms/EdgeInduced.java
+++ b/src/graphtea/extensions/algorithms/EdgeInduced.java
@@ -34,14 +34,13 @@ public static GraphModel edgeInduced(GraphModel g, Collection S) {
}
for (Edge ee : S) {
- Vertex v1 = ee.source;
- Vertex v2 = ee.target;
+ Vertex v1 = vv.get(ee.source);
+ Vertex v2 = vv.get(ee.target);
+ ret.removeEdge(ret.getEdges(v1, v2).get(0));
if (ret.getInDegree(v1) + ret.getOutDegree(v1) == 0)
ret.removeVertex(v1);
- else if (ret.getInDegree(v2) + ret.getOutDegree(v2) == 0)
+ if (v2 != v1 && ret.getInDegree(v2) + ret.getOutDegree(v2) == 0)
ret.removeVertex(v2);
- else
- ret.removeEdge(ret.getEdges(vv.get(ee.source), vv.get(ee.target)).get(0));
}
return ret;
}
diff --git a/src/graphtea/extensions/algorithms/GraphJoin.java b/src/graphtea/extensions/algorithms/GraphJoin.java
index 52ac3e83..d0ed1a49 100755
--- a/src/graphtea/extensions/algorithms/GraphJoin.java
+++ b/src/graphtea/extensions/algorithms/GraphJoin.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
package graphtea.extensions.algorithms;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
@@ -14,7 +15,6 @@
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
/**
* @author Mohammad Ali Rostami
@@ -41,15 +41,11 @@ public static GraphModel join(GraphModel g1, GraphModel g2) {
g.insertVertex(vt);
}
- Iterator iet = g1.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g1.getEdges()) {
E.add(e.getCopy(temp.get(e.source), temp.get(e.target)));
}
- iet = g2.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g2.getEdges()) {
E.add(e.getCopy(temp.get(e.source), temp.get(e.target)));
}
@@ -63,7 +59,7 @@ public static GraphModel join(GraphModel g1, GraphModel g2) {
try {
g.insertEdge(e);
} catch (InvalidVertexException e1) {
- e1.printStackTrace();
+ ExceptionHandler.catchException(e1);
}
}
return g;
diff --git a/src/graphtea/extensions/algorithms/GraphSum.java b/src/graphtea/extensions/algorithms/GraphSum.java
index 57ce01a6..89d69d4b 100755
--- a/src/graphtea/extensions/algorithms/GraphSum.java
+++ b/src/graphtea/extensions/algorithms/GraphSum.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
package graphtea.extensions.algorithms;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
@@ -14,7 +15,6 @@
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
/**
* @author Mohammad Ali Rostami
@@ -42,16 +42,12 @@ public static GraphModel sum(GraphModel g1, GraphModel g2) {
g.insertVertex(vt);
}
- Iterator iet = g1.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g1.getEdges()) {
E.add(e.getCopy(temp.get(e.source), temp.get(e.target)));
- //E.add(iet.next());
+ //E.add(e);
}
- iet = g2.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g2.getEdges()) {
E.add(e.getCopy(temp.get(e.source), temp.get(e.target)));
}
@@ -67,7 +63,7 @@ public static GraphModel sum(GraphModel g1, GraphModel g2) {
try {
g.insertEdge(e);
} catch (InvalidVertexException e1) {
- e1.printStackTrace();
+ ExceptionHandler.catchException(e1);
}
}
return g;
diff --git a/src/graphtea/extensions/algorithms/GraphUnion.java b/src/graphtea/extensions/algorithms/GraphUnion.java
index 159163c5..75f6a303 100755
--- a/src/graphtea/extensions/algorithms/GraphUnion.java
+++ b/src/graphtea/extensions/algorithms/GraphUnion.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
package graphtea.extensions.algorithms;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
@@ -14,7 +15,6 @@
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
/**
* @author Mohammad Ali Rostami
@@ -41,16 +41,12 @@ public static GraphModel union(GraphModel g1, GraphModel g2) {
g.insertVertex(vt);
}
- Iterator iet = g1.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g1.getEdges()) {
E.add(e.getCopy(temp.get(e.source), temp.get(e.target)));
- //E.add(iet.next());
+ //E.add(e);
}
- iet = g2.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g2.getEdges()) {
E.add(e.getCopy(temp.get(e.source), temp.get(e.target)));
}
@@ -58,7 +54,7 @@ public static GraphModel union(GraphModel g1, GraphModel g2) {
try {
g.insertEdge(e);
} catch (InvalidVertexException e1) {
- e1.printStackTrace();
+ ExceptionHandler.catchException(e1);
}
}
return g;
diff --git a/src/graphtea/extensions/algorithms/GreedyColoring.java b/src/graphtea/extensions/algorithms/GreedyColoring.java
index 6aaf41ac..90bcb7ff 100755
--- a/src/graphtea/extensions/algorithms/GreedyColoring.java
+++ b/src/graphtea/extensions/algorithms/GreedyColoring.java
@@ -10,8 +10,7 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
-import java.util.Vector;
+import java.util.List;
/**
* Created by rostam on 06.03.15.
@@ -35,7 +34,7 @@ public void doAlgorithm() {
step("Move over the vertices one by one and find all the colors that the neighbors are colored by.");
for(Vertex v : g) {
if(v.getColor() == 0) {
- Vector colors = new Vector<>();
+ List colors = new ArrayList<>();
for(Vertex u : g.directNeighbors(v))
colors.add(u.getColor());
for(int i = 1;i < g.getVerticesCount();i++) {
diff --git a/src/graphtea/extensions/algorithms/ILU.java b/src/graphtea/extensions/algorithms/ILU.java
index 51804d44..2c026544 100755
--- a/src/graphtea/extensions/algorithms/ILU.java
+++ b/src/graphtea/extensions/algorithms/ILU.java
@@ -7,7 +7,8 @@
import graphtea.plugins.algorithmanimator.core.GraphAlgorithm;
import graphtea.plugins.algorithmanimator.extension.AlgorithmExtension;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* author: rostam
@@ -25,8 +26,8 @@ public void doAlgorithm() {
int fillin = 0;
while(cont) {
Vertex v1 = requestVertex(g, "select a vertex");
- Vector InV = new Vector<>();
- Vector OutV = new Vector<>();
+ List InV = new ArrayList<>();
+ List OutV = new ArrayList<>();
for(Vertex v : g) {
if(g.isEdge(v,v1)) InV.add(v);
if(g.isEdge(v1,v)) OutV.add(v);
diff --git a/src/graphtea/extensions/algorithms/IndSetProductColoring.java b/src/graphtea/extensions/algorithms/IndSetProductColoring.java
index fd2ae9fa..469aa3c7 100755
--- a/src/graphtea/extensions/algorithms/IndSetProductColoring.java
+++ b/src/graphtea/extensions/algorithms/IndSetProductColoring.java
@@ -1,4 +1,5 @@
package graphtea.extensions.algorithms;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.extensions.reports.Partitioner;
import graphtea.extensions.reports.SubSetListener;
@@ -18,8 +19,9 @@
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayDeque;
+import java.util.ArrayList;
import java.util.HashSet;
-import java.util.Vector;
+import java.util.List;
/**
* author: rostam
@@ -30,11 +32,11 @@ public IndSetProductColoring(BlackBoard blackBoard) {
super(blackBoard);
}
- public static Vector> getAllIndependentSets(GraphModel graph) {
+ public static List> getAllIndependentSets(GraphModel graph) {
Partitioner p = new Partitioner(graph);
AllIndSetSubSetListener l = new AllIndSetSubSetListener();
p.findAllSubsets(l);
- return new Vector<>(l.maxsets);
+ return new ArrayList<>(l.maxsets);
}
@Override
@@ -45,7 +47,7 @@ public void doAlgorithm() {
try {
url = Paths.get("binary/zeta.jpg").toUri().toURL();
} catch (MalformedURLException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
GraphUtils.setMessage("The Zeta transformation of I is computed.
" +
@@ -67,8 +69,8 @@ public void doAlgorithm() {
// "");
GraphModel g = graphData.getGraph();
- Vector> maxsets = getAllIndependentSets(g);
- Vector ret = new Vector<>();
+ List> maxsets = getAllIndependentSets(g);
+ List ret = new ArrayList<>();
for (ArrayDeque maxset : maxsets) {
SubGraph sd = new SubGraph(g);
sd.vertices = new HashSet<>();
@@ -76,10 +78,10 @@ public void doAlgorithm() {
ret.add(sd);
}
- Vector> ind_sets= new Vector<>();
+ List> ind_sets= new ArrayList<>();
for (SubGraph subGraph : ret) {
HashSet ind_set = subGraph.vertices;
- Vector indset = new Vector<>();
+ List indset = new ArrayList<>();
for (Vertex vid : ind_set)
indset.add(vid.getId());
ind_sets.add(indset);
@@ -90,13 +92,13 @@ public void doAlgorithm() {
step("
Now, the nth power of I is computed in each step, until " +
"all vertices of G are seen.");
- Vector> ind_sets2= new Vector<>(ind_sets);
+ List> ind_sets2= new ArrayList<>(ind_sets);
for(int i=0;i<3;i++) {
ind_sets2=setproduct(ind_sets2,ind_sets,i+1);
IndSetsDialog isd = new IndSetsDialog(ind_sets2,"I^"+(i+2),"");
boolean hasAllVSets = true;
- for (Vector integers : ind_sets2) {
+ for (List integers : ind_sets2) {
hasAllVSets = true;
for (int j = 0; j < g.getVerticesCount(); j++) {
if (!integers.contains(j)) {
@@ -117,11 +119,11 @@ public void doAlgorithm() {
}
- public Vector> setproduct(Vector> set1,Vector> set2,int minuscount) {
- Vector> ret = new Vector<>();
- for (Vector tt : set1) {
- for (Vector integers : set2) {
- Vector tmp = new Vector<>(tt);
+ public List> setproduct(List> set1,List> set2,int minuscount) {
+ List> ret = new ArrayList<>();
+ for (List tt : set1) {
+ for (List integers : set2) {
+ List tmp = new ArrayList<>(tt);
boolean sameItem = false;
for (Integer aTt2 : integers) {
@@ -160,7 +162,7 @@ public String getDescription() {
}
class AllIndSetSubSetListener implements SubSetListener {
- Vector> maxsets = new Vector<>();
+ List> maxsets = new ArrayList<>();
public boolean subsetFound(int t, ArrayDeque complement, ArrayDeque set) {
maxsets.add(new ArrayDeque<>(set));
return false;
@@ -168,15 +170,15 @@ public boolean subsetFound(int t, ArrayDeque complement, ArrayDeque> ind_sets,
+ public IndSetsDialog(List> ind_sets,
String name, String description) {
this.setVisible(true);
this.setTitle(name);
this.setSize(new Dimension(200,400));
//jdd.setLayout(new BorderLayout(3, 3));
this.add(new JLabel(description), BorderLayout.NORTH);
- Vector isg = new Vector<>();
- for (Vector ind_set : ind_sets) {
+ List isg = new ArrayList<>();
+ for (List ind_set : ind_sets) {
IndSubGraphs isgs = new IndSubGraphs();
isgs.addAll(ind_set);
isg.add(isgs);
diff --git a/src/graphtea/extensions/algorithms/KruskalAlgorithm.java b/src/graphtea/extensions/algorithms/KruskalAlgorithm.java
index 3693b16e..33439994 100755
--- a/src/graphtea/extensions/algorithms/KruskalAlgorithm.java
+++ b/src/graphtea/extensions/algorithms/KruskalAlgorithm.java
@@ -1,5 +1,6 @@
package graphtea.extensions.algorithms;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
diff --git a/src/graphtea/extensions/algorithms/LloydKMeans.java b/src/graphtea/extensions/algorithms/LloydKMeans.java
index 93e42f2d..bb0960a5 100755
--- a/src/graphtea/extensions/algorithms/LloydKMeans.java
+++ b/src/graphtea/extensions/algorithms/LloydKMeans.java
@@ -1,5 +1,6 @@
package graphtea.extensions.algorithms;
+import java.util.List;
import graphtea.graph.graph.GPoint;
import java.util.ArrayList;
diff --git a/src/graphtea/extensions/algorithms/NetworkGenerateorAlgrithm.java b/src/graphtea/extensions/algorithms/NetworkGenerateorAlgrithm.java
index d42266ab..f1539b7e 100755
--- a/src/graphtea/extensions/algorithms/NetworkGenerateorAlgrithm.java
+++ b/src/graphtea/extensions/algorithms/NetworkGenerateorAlgrithm.java
@@ -1,4 +1,5 @@
package graphtea.extensions.algorithms;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GPoint;
@@ -16,7 +17,8 @@
import java.awt.*;
import java.io.File;
import java.util.Scanner;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* author: rostam
@@ -42,7 +44,7 @@ public void doAlgorithm(){
File selectedFile = fileChooser.getSelectedFile();
fread = new Scanner(selectedFile);
} catch (Exception e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
}
@@ -52,7 +54,7 @@ public void doAlgorithm(){
int scNum = 0;
int cnt = 0;
int maxNumNodesInLevel = 30;
- Vector forbiddenIndex = null;
+ List forbiddenIndex = null;
GPoint center = new GPoint(500,300);
Vertex cent = new Vertex();
cent.setLocation(center);
@@ -60,7 +62,7 @@ public void doAlgorithm(){
cent.setSize(new GPoint(0, 0));
cent.setLabelLocation(new GPoint(0,-1));
g.addVertex(cent);
- forbiddenIndex = new Vector<>();
+ forbiddenIndex = new ArrayList<>();
while(fread.hasNextLine()) {
String command = fread.nextLine();
step(command);
@@ -82,7 +84,7 @@ public void doAlgorithm(){
randInd = (int) (Math.random() * maxNumNodesInLevel);
}
forbiddenIndex.add(randInd);
- if(forbiddenIndex.size() > (maxNumNodesInLevel * 2/3)) forbiddenIndex = new Vector<>();
+ if(forbiddenIndex.size() > (maxNumNodesInLevel * 2/3)) forbiddenIndex = new ArrayList<>();
v.setColor(1);
v.setLocation(new GPoint(ps[randInd].x, ps[randInd].y));
v.setShapeStroke(GStroke.empty);
diff --git a/src/graphtea/extensions/algorithms/PrimAlgorithm.java b/src/graphtea/extensions/algorithms/PrimAlgorithm.java
index 8c0a0f1b..828c1797 100755
--- a/src/graphtea/extensions/algorithms/PrimAlgorithm.java
+++ b/src/graphtea/extensions/algorithms/PrimAlgorithm.java
@@ -1,5 +1,7 @@
package graphtea.extensions.algorithms;
+import java.util.ArrayList;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -39,8 +41,8 @@ public int compare(Edge o1, Edge o2) {
}
// graph.checkVertex(v);
- Vector oVertices = new Vector<>();
- Vector oEdges = new Vector<>();
+ List oVertices = new ArrayList<>();
+ List oEdges = new ArrayList<>();
//dispatchEvent(new GraphEvent(oGraph));
@@ -87,7 +89,7 @@ public int compare(Edge o1, Edge o2) {
}
private Pair
- getNewEdgeForSpanningTree(Vector vertices) {
+ getNewEdgeForSpanningTree(List vertices) {
ArrayList tempEdgeArray = new ArrayList<>();
try {
diff --git a/src/graphtea/extensions/algorithms/SampleAlgorithm.java b/src/graphtea/extensions/algorithms/SampleAlgorithm.java
index 7d3fb2d3..dbd2780a 100755
--- a/src/graphtea/extensions/algorithms/SampleAlgorithm.java
+++ b/src/graphtea/extensions/algorithms/SampleAlgorithm.java
@@ -9,7 +9,8 @@
import graphtea.plugins.algorithmanimator.core.GraphAlgorithm;
import graphtea.plugins.algorithmanimator.extension.AlgorithmExtension;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author M. Ali Rostami, A. Azadi
@@ -40,7 +41,7 @@ public void doAlgorithm() {
e.setColor(3);
step("connect v2 to the neighbors of its neighbours");
- Vector toInsert = new Vector<>();
+ List toInsert = new ArrayList<>();
for (Vertex v:g.neighbors(v2))
for (Vertex vv:g.neighbors(v))
toInsert.add(new Edge(v2, vv));
diff --git a/src/graphtea/extensions/algorithms/TopologicalSort.java b/src/graphtea/extensions/algorithms/TopologicalSort.java
index 617a138c..1c72a981 100755
--- a/src/graphtea/extensions/algorithms/TopologicalSort.java
+++ b/src/graphtea/extensions/algorithms/TopologicalSort.java
@@ -5,6 +5,7 @@
package graphtea.extensions.algorithms;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -39,16 +40,6 @@ public class TopologicalSort extends Algorithm implements AutomatedAlgorithm {
iet = graph.edgeIterator(v, true);
while (iet.hasNext()) {
Edge e = iet.next();
- /*
- if(e.getMark())
- continue;
-
- e.setMark(true);
-
-
- if(alv.contains(e.target))
- continue;
- */
if (graph.getInDegree(e.target) == 1)
alv.add(e.target);
}
@@ -61,20 +52,6 @@ public class TopologicalSort extends Algorithm implements AutomatedAlgorithm {
}
public void doAlgorithm() {
-// BaseGraphRequest gr = new BaseGraphRequest();
-// dispatchEvent(gr);
-// GraphModel graph = gr.getGraph();
-// AbstractList alv = doSort(graph);
-// if (alv == null)
-// dispatchEvent(new MessageEvent("Graph has a cycle"));
-// else {
-// StringBuilder s = new StringBuilder("Topological sort sequence:");
-// for (BaseVertex v : alv)
-// s.append(v.getId() + ',');
-//
-// dispatchEvent(new MessageEvent(s.toString()));
-// }
-
}
diff --git a/src/graphtea/extensions/algorithms/VertexCorona.java b/src/graphtea/extensions/algorithms/VertexCorona.java
index 155f9c52..06aa3a12 100755
--- a/src/graphtea/extensions/algorithms/VertexCorona.java
+++ b/src/graphtea/extensions/algorithms/VertexCorona.java
@@ -13,7 +13,6 @@
import graphtea.plugins.algorithmanimator.core.GraphAlgorithm;
import java.util.HashMap;
-import java.util.Iterator;
/**
* @author Mohammad Ali Rostami
@@ -35,9 +34,7 @@ public static GraphModel corona(GraphModel g1, GraphModel g2) {
g.insertVertex(vt);
}
- Iterator iet = g1.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g1.getEdges()) {
g.insertEdge(e.getCopy(temp1.get(e.source), temp1.get(e.target)));
}
@@ -53,9 +50,7 @@ public static GraphModel corona(GraphModel g1, GraphModel g2) {
}
- iet = g2.lightEdgeIterator();
- while (iet.hasNext()) {
- Edge e = iet.next();
+ for (Edge e : g2.getEdges()) {
g.addEdge(e.getCopy(temp2.get(e.source), temp2.get(e.target)));
}
diff --git a/src/graphtea/extensions/algorithms/VertexInduced.java b/src/graphtea/extensions/algorithms/VertexInduced.java
index 7819f290..3d0709a0 100755
--- a/src/graphtea/extensions/algorithms/VertexInduced.java
+++ b/src/graphtea/extensions/algorithms/VertexInduced.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
package graphtea.extensions.algorithms;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
@@ -41,7 +42,7 @@ public static GraphModel induced(GraphModel g, Collection S) {
try {
baseGraph.removeVertex(hm.get(v));
} catch (InvalidVertexException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
}
}
diff --git a/src/graphtea/extensions/algorithms/homomorphism/FindingHomomorphism.java b/src/graphtea/extensions/algorithms/homomorphism/FindingHomomorphism.java
index d30cbd97..c63c1f53 100755
--- a/src/graphtea/extensions/algorithms/homomorphism/FindingHomomorphism.java
+++ b/src/graphtea/extensions/algorithms/homomorphism/FindingHomomorphism.java
@@ -1,4 +1,5 @@
package graphtea.extensions.algorithms.homomorphism;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.extensions.generators.CircleGenerator;
import graphtea.extensions.generators.GeneralizedPetersonGenerator;
@@ -53,7 +54,7 @@ Homomorphism findAHomomorphism(GraphModel G, GraphModel H) throws GraphIOExcepti
return new Homomorphism(G, H, homomorphism);
}
} catch (IOException | InterruptedException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
}
return null;
@@ -65,7 +66,7 @@ public static void main(String[] args) {
try {
new FindingHomomorphism().findAHomomorphism(peterson, circle3);
} catch (GraphIOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
}
}
diff --git a/src/graphtea/extensions/algorithms/homomorphism/Homomorphism.java b/src/graphtea/extensions/algorithms/homomorphism/Homomorphism.java
index 78f0df96..061a0e15 100755
--- a/src/graphtea/extensions/algorithms/homomorphism/Homomorphism.java
+++ b/src/graphtea/extensions/algorithms/homomorphism/Homomorphism.java
@@ -5,6 +5,7 @@
package graphtea.extensions.algorithms.homomorphism;
+import java.util.List;
import graphtea.extensions.generators.CompleteGraphGenerator;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
@@ -36,7 +37,7 @@ public class Homomorphism {
* @param colors The coloring as a list of integers
* @param numOfColors the number of colors
*/
- public Homomorphism(GraphModel domain, Vector colors, int numOfColors) {
+ public Homomorphism(GraphModel domain, List colors, int numOfColors) {
if (Collections.max(colors) != numOfColors) {
throw new InvalidParameterException("The given number of colors is not equal" +
"with the real existing number of colors inside the vector colors.");
@@ -98,13 +99,13 @@ public GraphModel getQuotient() {
GraphModel quotient = new GraphModel();
for (Vertex v : this.range) {
Vertex u = new Vertex();
- u.getProp().obj = new Vector();
+ u.getProp().obj = new ArrayList<>();
quotient.addVertex(u);
}
for (Vertex key : homomorphism.keySet()) {
Vertex value = homomorphism.get(key);
- ((Vector) quotient.getVertex(value.getId()).getProp().obj).add(key.getId());
+ ((List) quotient.getVertex(value.getId()).getProp().obj).add(key.getId());
}
for (Vertex v : quotient) {
diff --git a/src/graphtea/extensions/algorithms/shortestpath/algs/AcyclicSP.java b/src/graphtea/extensions/algorithms/shortestpath/algs/AcyclicSP.java
index e3d7a98c..0b189c2b 100755
--- a/src/graphtea/extensions/algorithms/shortestpath/algs/AcyclicSP.java
+++ b/src/graphtea/extensions/algorithms/shortestpath/algs/AcyclicSP.java
@@ -6,6 +6,8 @@
package graphtea.extensions.algorithms.shortestpath.algs;
+import java.util.ArrayList;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -35,10 +37,10 @@ public AcyclicSP(BlackBoard blackBoard) {
// this.gc = gc;
// }
- public Vector acyclicSP(GraphModel g, Vertex v) throws InvalidVertexException {
+ public List acyclicSP(GraphModel g, Vertex v) throws InvalidVertexException {
GraphModel gcopy = (GraphModel) g.copy(gc);
final Integer[] dist = new Integer[g.getVerticesCount()];
- Vector prev = new Vector<>();
+ List prev = new ArrayList<>();
Queue Q = new LinkedList<>();
HashMap gcopy2g = new HashMap<>();
HashMap t = new HashMap<>();
diff --git a/src/graphtea/extensions/algorithms/shortestpath/algs/BellmanFord.java b/src/graphtea/extensions/algorithms/shortestpath/algs/BellmanFord.java
index 959670ec..d0855acc 100755
--- a/src/graphtea/extensions/algorithms/shortestpath/algs/BellmanFord.java
+++ b/src/graphtea/extensions/algorithms/shortestpath/algs/BellmanFord.java
@@ -13,8 +13,9 @@
import graphtea.plugins.algorithmanimator.core.GraphAlgorithm;
import java.util.Arrays;
-import java.util.Iterator;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* This method finds the shortest path from a source vertex v, to all
@@ -44,42 +45,39 @@ public BellmanFord(BlackBoard blackBoard) {
* and the vector of predecessors, otherwise.
*/
- public Vector computePaths
+ public List computePaths
(final GraphModel graph, Vertex Vertex) {
// graph.checkVertex(Vertex);
- Integer[] dist;
- dist = new Integer[graph.getVerticesCount()];
- Vector ret = new Vector<>();
-
+ int n = graph.getVerticesCount();
+ Integer[] dist = new Integer[n];
+ // predecessors: pred[i] = the vertex that immediately precedes vertex i
+ // on the shortest path from Vertex to i
+ List pred = new ArrayList<>(Collections.nCopies(n, null));
Arrays.fill(dist, Integer.MAX_VALUE);
-
dist[Vertex.getId()] = 0;
- Edge edge;
- int i;
- Iterator iet;
-
- for (i = 1; i < graph.getVerticesCount(); i++) {
- iet = graph.edgeIterator();
- while (iet.hasNext()) {
- edge = iet.next();
- if (dist[edge.source.getId()] > dist[edge.target.getId()] + edge.getWeight()) {
- dist[edge.source.getId()] = dist[edge.target.getId()] + edge.getWeight();
- ret.add(edge.source.getId(), edge.target);
+ for (int i = 1; i < n; i++) {
+ for (Edge edge : graph.getEdges()) {
+ // guard against Integer.MAX_VALUE + weight overflow
+ if (dist[edge.source.getId()] == Integer.MAX_VALUE) continue;
+ if (dist[edge.target.getId()] > dist[edge.source.getId()] + edge.getWeight()) {
+ dist[edge.target.getId()] = dist[edge.source.getId()] + edge.getWeight();
+ pred.set(edge.target.getId(), edge.source);
}
}
}
- iet = graph.edgeIterator();
- while (iet.hasNext()) {
- edge = iet.next();
- if (dist[edge.source.getId()] > dist[edge.target.getId()] + edge.getWeight())
+ // negative-cycle detection
+ for (Edge edge : graph.getEdges()) {
+ if (dist[edge.source.getId()] != Integer.MAX_VALUE &&
+ dist[edge.target.getId()] > dist[edge.source.getId()] + edge.getWeight()) {
return null;
+ }
}
- return ret;
+ return pred;
}
public void doAlgorithm() {
@@ -88,7 +86,7 @@ public void doAlgorithm() {
// this.graph = gr.getGraph();
// VertexRequest vr = new VertexRequest<>(graph, "Please choose a vertex for the BellmanFord algorithm.");
// dispatchEvent(vr);
-// Vector vv = this.computePaths(graph, vr.getVertex());
+// List vv = this.computePaths(graph, vr.getVertex());
// for (Vertex v : vv)
// v.setColor(v.getColor() + 1);
// //how to show the results??
diff --git a/src/graphtea/extensions/algorithms/shortestpath/algs/Dijkstra.java b/src/graphtea/extensions/algorithms/shortestpath/algs/Dijkstra.java
index 901a82dd..73fa89a2 100755
--- a/src/graphtea/extensions/algorithms/shortestpath/algs/Dijkstra.java
+++ b/src/graphtea/extensions/algorithms/shortestpath/algs/Dijkstra.java
@@ -5,6 +5,9 @@
package graphtea.extensions.algorithms.shortestpath.algs;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -37,7 +40,7 @@ public class Dijkstra extends Algorithm implements AutomatedAlgorithm {
* @throws InvalidVertexException if the supplied vertices are invalid.
*/
- public Vector
+ public List
getShortestPath(final GraphModel graph,
Vertex vertex)
throws InvalidVertexException {
@@ -46,7 +49,7 @@ public class Dijkstra extends Algorithm implements AutomatedAlgorithm {
final Integer[] dist = new Integer[graph.getVerticesCount()];
//the edge connected to i'th vertex
final HashMap edges = new HashMap<>();
- Vector prev = new Vector<>();
+ List prev = new ArrayList<>(Collections.nCopies(graph.getVerticesCount(), null));
Arrays.fill(dist, Integer.MAX_VALUE);
@@ -94,7 +97,7 @@ public int compare(Vertex o1, Vertex o2) {
target.setMark(true);
target.setColor(5);
Q.add(target);
- prev.add(edge.source.getId(), edge.target);
+ prev.set(edge.source.getId(), edge.target);
}
}
}
diff --git a/src/graphtea/extensions/algorithms/shortestpath/algs/Johnson.java b/src/graphtea/extensions/algorithms/shortestpath/algs/Johnson.java
index 52370d33..b70f98f8 100755
--- a/src/graphtea/extensions/algorithms/shortestpath/algs/Johnson.java
+++ b/src/graphtea/extensions/algorithms/shortestpath/algs/Johnson.java
@@ -5,6 +5,7 @@
package graphtea.extensions.algorithms.shortestpath.algs;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -15,7 +16,6 @@
import java.util.Collection;
import java.util.Iterator;
-import java.util.Vector;
/**
* This Algorithm computes the length of the shortest
@@ -54,7 +54,7 @@ public int[][] ComputePaths(GraphModel g) {
BellmanFord sp = new BellmanFord(blackBoard);
if (sp.computePaths(g, u) != null) {
- Vector pd = sp.computePaths(g, u);
+ List pd = sp.computePaths(g, u);
for (Vertex v : g) {
int dd = 0;
@@ -77,7 +77,7 @@ public int[][] ComputePaths(GraphModel g) {
for (Vertex v : g) {
Dijkstra dj = new Dijkstra();
- Vector pdj = dj.getShortestPath(g, v);
+ List pdj = dj.getShortestPath(g, v);
for (Vertex z : g) {
int dd = 0;
Edge f;
diff --git a/src/graphtea/extensions/algorithms/spanningtree/Kruskal.java b/src/graphtea/extensions/algorithms/spanningtree/Kruskal.java
index c4633330..89221117 100755
--- a/src/graphtea/extensions/algorithms/spanningtree/Kruskal.java
+++ b/src/graphtea/extensions/algorithms/spanningtree/Kruskal.java
@@ -5,6 +5,7 @@
package graphtea.extensions.algorithms.spanningtree;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -45,10 +46,6 @@ else if (o1.getWeight() == o2.getWeight())
return 1;
});
- for (Edge e : edges)
- System.out.print(e.getWeight() + " ");
- System.out.println();
-
for (Edge e : edges) {
int set1 = findSet(sets, e.source);
int set2 = findSet(sets, e.target);
diff --git a/src/graphtea/extensions/algorithms/spanningtree/Prim.java b/src/graphtea/extensions/algorithms/spanningtree/Prim.java
index 8b0e02e7..90896919 100755
--- a/src/graphtea/extensions/algorithms/spanningtree/Prim.java
+++ b/src/graphtea/extensions/algorithms/spanningtree/Prim.java
@@ -5,6 +5,8 @@
package graphtea.extensions.algorithms.spanningtree;
+import java.util.ArrayList;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
@@ -86,7 +88,7 @@ public Prim(GraphModel graph,
* @return The spanning tree graph.
* @throws InvalidGraphException if the supplied vertex is invalid.
*/
- public Pair, Vector>
+ public Pair, List>
findMinimumSpanningTree(Vertex v, Comparator comparator)
throws InvalidGraphException, InvalidVertexException {
if (comparator == null)
@@ -106,7 +108,7 @@ public Prim(GraphModel graph,
* @return The spanning tree graph.
* @throws InvalidGraphException if the supplied vertex is invalid.
*/
- public Pair, Vector>
+ public Pair, List>
findMinimumSpanningTree(Vertex v)
throws InvalidGraphException, InvalidVertexException {
graph.checkVertex(v);
@@ -114,8 +116,8 @@ public Prim(GraphModel graph,
// GraphModel gCopy = graph.copy(gc);
// gCopy = graph;
- Vector oVertices = new Vector<>();
- Vector oEdges = new Vector<>();
+ List oVertices = new ArrayList<>();
+ List oEdges = new ArrayList<>();
//dispatchEvent(new GraphEvent(oGraph));
@@ -157,7 +159,7 @@ public Prim(GraphModel graph,
private Pair
- getNewEdgeForSpanningTree(Vector vertices, Vector edges) {
+ getNewEdgeForSpanningTree(List vertices, List edges) {
ArrayList tempEdgeArray = new ArrayList<>();
try {
diff --git a/src/graphtea/extensions/algorithms/subgraphs/InducedSubgraphs.java b/src/graphtea/extensions/algorithms/subgraphs/InducedSubgraphs.java
index 499c3501..d4a703cd 100755
--- a/src/graphtea/extensions/algorithms/subgraphs/InducedSubgraphs.java
+++ b/src/graphtea/extensions/algorithms/subgraphs/InducedSubgraphs.java
@@ -5,6 +5,7 @@
package graphtea.extensions.algorithms.subgraphs;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
diff --git a/src/graphtea/extensions/algorithms/subgraphs/TestInducedSubgraphs.java b/src/graphtea/extensions/algorithms/subgraphs/TestInducedSubgraphs.java
deleted file mode 100755
index a34659aa..00000000
--- a/src/graphtea/extensions/algorithms/subgraphs/TestInducedSubgraphs.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
-// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
-// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
-// Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
-
-package graphtea.extensions.algorithms.subgraphs;
-
-import graphtea.library.algorithms.Algorithm;
-import graphtea.library.algorithms.AutomatedAlgorithm;
-
-public class TestInducedSubgraphs extends Algorithm implements AutomatedAlgorithm {
-
- public void doAlgorithm() {
-// BaseGraphRequest gr = new BaseGraphRequest();
-// dispatchEvent(gr);
-// GraphModel graph = gr.getGraph(), induced;
-//
-// ArrayList inducedVertices = new ArrayList<>();
-//
-// int i = 0;
-// for (Vertex v : graph) {
-// if (i > graph.getVerticesCount() / 2)
-// break;
-// inducedVertices.add(v);
-// }
-//
-// induced = InducedSubgraphs.getVertexInducedSubgraph(graph, inducedVertices);
-// dispatchEvent(new GraphEvent<>(induced, GraphEvent.EventType.NEW_GRAPH));
- }
-
-}
\ No newline at end of file
diff --git a/src/graphtea/extensions/algorithms/vertexcover/AppVertexCover.java b/src/graphtea/extensions/algorithms/vertexcover/AppVertexCover.java
index 590b3141..8ee66494 100755
--- a/src/graphtea/extensions/algorithms/vertexcover/AppVertexCover.java
+++ b/src/graphtea/extensions/algorithms/vertexcover/AppVertexCover.java
@@ -14,8 +14,9 @@
import graphtea.plugins.algorithmanimator.core.GraphAlgorithm;
import graphtea.plugins.algorithmanimator.extension.AlgorithmExtension;
+import java.util.ArrayList;
import java.util.Iterator;
-import java.util.Vector;
+import java.util.List;
/**
* @author Soroush Sabet
@@ -33,13 +34,12 @@ public void doAlgorithm() {
step("Start of the algorithm.") ;
GraphModel graph = graphData.getGraph();
GraphModel gCopy = graph.getCopy();
- Vector C = new Vector<>();
- Vector D = new Vector<>();
- Vector marked = new Vector<>();
- Iterator i;
+ List C = new ArrayList<>();
+ List D = new ArrayList<>();
+ List marked = new ArrayList<>();
//cleat marks
- for (Iterator ie = graph.edgeIterator(); ie.hasNext();)
- ie.next().setMark(false);
+ for (Edge edge : graph.getEdges())
+ edge.setMark(false);
Edge e;
Iterator iet = graph.edgeIterator();
@@ -50,15 +50,12 @@ public void doAlgorithm() {
step("");
C.add(e.source);
C.add(e.target);
- i = graph.edgeIterator(e.source);
- while(i.hasNext()){
- gCopy.removeEdge(i.next());
-
+ for (Edge edge : graph.edges(e.source)) {
+ gCopy.removeEdge(edge);
}
- i= gCopy.edgeIterator(e.target);
- while(i.hasNext()){
- gCopy.removeEdge(i.next());
+ for (Edge edge : gCopy.edges(e.target)) {
+ gCopy.removeEdge(edge);
}
iet = gCopy.edgeIterator();
}
diff --git a/src/graphtea/extensions/generators/ExampleChainGraph2.java b/src/graphtea/extensions/generators/ExampleChainGraph2.java
index 0f198bb7..452bb375 100755
--- a/src/graphtea/extensions/generators/ExampleChainGraph2.java
+++ b/src/graphtea/extensions/generators/ExampleChainGraph2.java
@@ -17,7 +17,8 @@
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import java.util.Arrays;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author azin azadi
@@ -46,7 +47,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector ret = new Vector<>(); //new Edge[2 * n - 2 + n/3 + 2];
+ List ret = new ArrayList<>(); //new Edge[2 * n - 2 + n/3 + 2];
for (int i = 0; i < n - 1; i++) {
ret.add(new Edge(v[i], v[i + 1]));
}
diff --git a/src/graphtea/extensions/generators/ExampleChainGraph4.java b/src/graphtea/extensions/generators/ExampleChainGraph4.java
index a481a7bc..532882fc 100755
--- a/src/graphtea/extensions/generators/ExampleChainGraph4.java
+++ b/src/graphtea/extensions/generators/ExampleChainGraph4.java
@@ -17,7 +17,8 @@
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import java.util.Arrays;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Ali Rostami
@@ -46,7 +47,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector ret = new Vector<>();
+ List ret = new ArrayList<>();
for (int i = 0; i < n - 1; i++) {
ret.add(new Edge(v[i], v[i + 1]));
}
diff --git a/src/graphtea/extensions/generators/ExampleChainGraph5.java b/src/graphtea/extensions/generators/ExampleChainGraph5.java
index 305dfa8e..eef691f4 100755
--- a/src/graphtea/extensions/generators/ExampleChainGraph5.java
+++ b/src/graphtea/extensions/generators/ExampleChainGraph5.java
@@ -17,7 +17,8 @@
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import java.util.Arrays;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Ali Rostami
@@ -46,7 +47,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector ret = new Vector<>();
+ List ret = new ArrayList<>();
for (int i = 0; i < n - 1; i++) {
ret.add(new Edge(v[i], v[i + 1]));
}
diff --git a/src/graphtea/extensions/generators/ExampleChainGraph6.java b/src/graphtea/extensions/generators/ExampleChainGraph6.java
index dfa45aa8..b6612976 100755
--- a/src/graphtea/extensions/generators/ExampleChainGraph6.java
+++ b/src/graphtea/extensions/generators/ExampleChainGraph6.java
@@ -17,7 +17,8 @@
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import java.util.Arrays;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Ali Rostami
@@ -46,7 +47,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector ret = new Vector<>();
+ List ret = new ArrayList<>();
for (int i = 0; i < n - 1; i++) {
ret.add(new Edge(v[i], v[i + 1]));
}
diff --git a/src/graphtea/extensions/generators/ExampleChainGraph7.java b/src/graphtea/extensions/generators/ExampleChainGraph7.java
index 6d707710..6a76ed69 100755
--- a/src/graphtea/extensions/generators/ExampleChainGraph7.java
+++ b/src/graphtea/extensions/generators/ExampleChainGraph7.java
@@ -17,7 +17,8 @@
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import java.util.Arrays;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Ali Rostami
@@ -46,7 +47,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector ret = new Vector<>();
+ List ret = new ArrayList<>();
for (int i = 0; i < 2*n - 1; i++) {
ret.add(new Edge(v[i], v[i + 1]));
}
diff --git a/src/graphtea/extensions/generators/KndKneserGraphGenerator.java b/src/graphtea/extensions/generators/KndKneserGraphGenerator.java
index 3092adf5..b1d888dc 100755
--- a/src/graphtea/extensions/generators/KndKneserGraphGenerator.java
+++ b/src/graphtea/extensions/generators/KndKneserGraphGenerator.java
@@ -16,7 +16,8 @@
import graphtea.plugins.graphgenerator.core.SimpleGeneratorInterface;
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* Author: M. Ali Rostami
@@ -41,7 +42,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector ret = new Vector<>();
+ List ret = new ArrayList<>();
for (int i = 0; i < n; i++) {
for (int j = i; j < (Math.min(n, i + d)); j++) {
ret.add(new Edge(v[i], v[j]));
diff --git a/src/graphtea/extensions/generators/KneserGraphGenerator.java b/src/graphtea/extensions/generators/KneserGraphGenerator.java
index 462acee2..dc83f1d5 100755
--- a/src/graphtea/extensions/generators/KneserGraphGenerator.java
+++ b/src/graphtea/extensions/generators/KneserGraphGenerator.java
@@ -4,6 +4,8 @@
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.generators;
+import java.util.ArrayList;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GPoint;
import graphtea.graph.graph.GraphModel;
@@ -36,9 +38,9 @@ public class KneserGraphGenerator implements GraphGeneratorExtension, Parametriz
@Parameter(name = "n")
public static Integer n = 5;
- private Vector> computedVertices;
+ private List> computedVertices;
- private static Vector> ComputeVertices(int n, int k) {
+ private static List> ComputeVertices(int n, int k) {
List list = new ArrayList<>();
for(int i : IntStream.rangeClosed(0, n-1).toArray()) {
list.add(i+"");
@@ -57,12 +59,12 @@ private static Vector> ComputeVertices(int n, int k) {
}
).stream().filter(s -> s.chars().filter(ch -> ch == '-').count() == (k/2)).collect(Collectors.toList());
- Vector> vs = new Vector<>();
+ List> vs = new ArrayList<>();
for(String s : combinations) {
vs.add(new HashSet<>());
String[] splitted = s.split("-");
for(String ss : splitted) {
- vs.lastElement().add(Integer.parseInt(ss));
+ vs.get(vs.size() - 1).add(Integer.parseInt(ss));
}
}
// System.out.println(vs);
@@ -82,7 +84,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector ret = new Vector<>();
+ List ret = new ArrayList<>();
for(int i=0;i < computedVertices.size();i++) {
for(int j=i+1;j < computedVertices.size();j++) {
HashSet s1 = computedVertices.get(i);
diff --git a/src/graphtea/extensions/generators/NNGenerator.java b/src/graphtea/extensions/generators/NNGenerator.java
index 7b4ff684..070bf558 100755
--- a/src/graphtea/extensions/generators/NNGenerator.java
+++ b/src/graphtea/extensions/generators/NNGenerator.java
@@ -15,7 +15,8 @@
import graphtea.plugins.graphgenerator.core.SimpleGeneratorInterface;
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Ali Rostami
@@ -51,7 +52,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector rets = new Vector<>();
+ List rets = new ArrayList<>();
for(int i=1;i cach = new Vector<>();
+ List cach = new ArrayList<>();
if(deg%2 == 0) {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < i+(deg / 2) + 1; j++) {
diff --git a/src/graphtea/extensions/generators/Sudoko.java b/src/graphtea/extensions/generators/Sudoko.java
index f52c3cfd..2f4e7adf 100755
--- a/src/graphtea/extensions/generators/Sudoko.java
+++ b/src/graphtea/extensions/generators/Sudoko.java
@@ -15,7 +15,8 @@
import graphtea.plugins.graphgenerator.core.SimpleGeneratorInterface;
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author M. Ali Rostami
@@ -43,7 +44,7 @@ public Vertex[] getVertices() {
}
public Edge[] getEdges() {
- Vector vs = new Vector<>();
+ List vs = new ArrayList<>();
for(int k=0;k < n;k++) {
for (int i = k * n; i < (k + 1) * n; i++)
@@ -70,7 +71,7 @@ public Edge[] getEdges() {
}
public GPoint[] getVertexPositions() {
- Vector vs = new Vector<>();
+ List vs = new ArrayList<>();
int baseX = 210;int distX = 60;
int baseY = 210;int distY = 60;
diff --git a/src/graphtea/extensions/io/GraphSaveObject.java b/src/graphtea/extensions/io/GraphSaveObject.java
index 12e04823..a47a9427 100755
--- a/src/graphtea/extensions/io/GraphSaveObject.java
+++ b/src/graphtea/extensions/io/GraphSaveObject.java
@@ -1,4 +1,5 @@
package graphtea.extensions.io;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
@@ -51,26 +52,20 @@ public void insertIntoGraph(GraphModel g){
public static byte[] getBytesOfGraph(GraphModel g) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
- try {
- ObjectOutputStream oop = new ObjectOutputStream(bout);
+ try (ObjectOutputStream oop = new ObjectOutputStream(bout)) {
oop.writeObject(new GraphSaveObject(g));
- oop.flush();
- oop.close();
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
return bout.toByteArray();
}
public static byte[] getBytesOfGraphSaveObject(GraphSaveObject gso) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
- try {
- ObjectOutputStream oop = new ObjectOutputStream(bout);
+ try (ObjectOutputStream oop = new ObjectOutputStream(bout)) {
oop.writeObject(gso);
- oop.flush();
- oop.close();
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
return bout.toByteArray();
}
@@ -88,12 +83,11 @@ public static GraphSaveObject string2GraphSaveObject(String s){
}
public static GraphSaveObject getGraphSaveOobjectfromBytes(byte[] b){
- try {
- ObjectInputStream ois = new ObjectInputStream(
- new ByteArrayInputStream(b));
+ try (ObjectInputStream ois = new ObjectInputStream(
+ new ByteArrayInputStream(b))) {
return (GraphSaveObject) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
return null;
diff --git a/src/graphtea/extensions/io/LatexWriter.java b/src/graphtea/extensions/io/LatexWriter.java
index 74be78d4..144a5c9d 100755
--- a/src/graphtea/extensions/io/LatexWriter.java
+++ b/src/graphtea/extensions/io/LatexWriter.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.io;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.*;
import graphtea.plugins.main.saveload.core.GraphIOException;
@@ -30,10 +31,13 @@ public String getExtension() {
public void write(File file, GraphModel graph) throws GraphIOException {
- FileWriter output;
- try {
- output = new FileWriter(file);
+ // Use try-with-resources so the FileWriter is always closed
+ try (FileWriter output = new FileWriter(file)) {
GRect r = graph.getAbsBounds();
+ // Preamble: uses standard LaTeX picture environment.
+ // \qbezier draws edges and works with all modern compilers (pdflatex,
+ // xelatex, lualatex). The old em:moveto / em:lineto specials only
+ // worked with the emtex DVI driver and are silently ignored by pdflatex.
output.write(
"\\documentclass[12pt,bezier]{article}\n" +
"\\textwidth = 15 cm\n" +
@@ -43,107 +47,70 @@ public void write(File file, GraphModel graph) throws GraphIOException {
"\\topmargin = -1 cm\n" +
"\\parskip = 1.5 mm\n" +
"\\parindent = 5 mm\n" +
- "%\n" +
"\\def\\bfG{\\mbox{\\boldmath$G$}}\n" +
"\n" +
"\\title{" + graph.getLabel() + "}\n" +
- "\\input{epsf}\n" +
- "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
"\\pagestyle{plain}\n" +
- "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
- "\\def\\emline#1#2#3#4#5#6{\\put(#4,#5){\\special{em:lineto}}}\n" +
- "\\def\\newpic#1{}\n" +
- "%\n" +
- "\n" +
"\\author{GraphTea}\n" +
- "%\n" +
"\\date{}\n" +
"\n" +
"\\begin{document}\n" +
"\n" +
"\\begin{figure}[h]\n" +
- "%\n" +
- "\\def\\emline#1#2#3#4#5#6{%\n" +
- "%\n" +
- "\\put(#1,#2){\\special{em:moveto}}%\n" +
- "%\n" +
- "\\put(#4,#5){\\special{em:lineto}}}\n" +
- "%\n" +
- "\\def\\newpic#1{}\n" +
- "%\n" +
- "%\\pagestyle{empty}\n" +
- "%\n" +
- "%\\begin{document}\n" +
- "%\n" +
"\\unitlength 0.7mm\n" +
- "%\n" +
- "\\special{em:linewidth 0.4pt}\n" +
- "%\n" +
"\\linethickness{0.4pt}\n" +
- "%\n" +
"\\begin{picture}(150,150)(0,0)\n" +
- "%\n" +
"%Vertices\n");
- String vertices = " ";
+ StringBuilder vertices = new StringBuilder(" ");
for (Vertex vm : graph)
- vertices += "\\put("
- + (vm.getLocation().getX() / r.getMaxX()) * 100
- + ","
- + (vm.getLocation().getY() / r.getMaxY()) * 100
- + "){\\circle*{2}}\n";
- output.write(vertices);
+ vertices.append("\\put(")
+ .append((vm.getLocation().getX() / r.getMaxX()) * 100)
+ .append(",")
+ .append((vm.getLocation().getY() / r.getMaxY()) * 100)
+ .append("){\\circle*{2}}\n");
+ output.write(vertices.toString());
- String edges = "";
+ StringBuilder edges = new StringBuilder();
Iterator em = graph.edgeIterator();
while (em.hasNext()) {
Edge e = em.next();
final GPoint sx = e.source.getLocation();
- if (!graph.isEdgesCurved()) {
- edges += "%Edge Label:" + e.getLabel() + "\n";
- edges += "\\emline{" +
- (sx.getX() / r.getMaxX()) * 100
- + "}{" +
- (sx.getY() / r.getMaxY()) * 100
- + "}{1}{" +
+ double x1 = (sx.getX() / r.getMaxX()) * 100;
+ double y1 = (sx.getY() / r.getMaxY()) * 100;
+ double x2 = (e.target.getLocation().getX() / r.getMaxX()) * 100;
+ double y2 = (e.target.getLocation().getY() / r.getMaxY()) * 100;
- (e.target.getLocation().getX() / r.getMaxX()) * 100
- + "}{" +
- (e.target.getLocation().getY() / r.getMaxY()) * 100
- + "}{2}\n";
+ edges.append("%Edge Label:").append(e.getLabel()).append("\n");
+ if (!graph.isEdgesCurved()) {
+ // Straight edge: \qbezier with midpoint as control point draws a
+ // straight line and works with pdflatex / xelatex / lualatex.
+ // (The old em:moveto / em:lineto specials only work with emtex.)
+ double mx = (x1 + x2) / 2;
+ double my = (y1 + y2) / 2;
+ edges.append("\\qbezier(")
+ .append(x1).append(",").append(y1).append(")(")
+ .append(mx).append(",").append(my).append(")(")
+ .append(x2).append(",").append(y2).append(")\n");
} else {
- edges += "%Edge Label:" + e.getLabel() + "\n";
- double centerx, centery;
- centerx = (sx.getX() + e.target.getLocation().getX()) / 2;
- centery = (sx.getY() + e.target.getLocation().getY()) / 2;
+ double centerx = (sx.getX() + e.target.getLocation().getX()) / 2;
+ double centery = (sx.getY() + e.target.getLocation().getY()) / 2;
double cx = ((centerx + e.getCurveControlPoint().getX()) / r.getMaxX()) * 100;
- double cy = ((e.getCurveControlPoint().getY() + centery) / r.getMaxY()) * 100;
- edges += "\\bezier{500}(" +
- (sx.getX() / r.getMaxX()) * 100
- + "," +
- (sx.getY() / r.getMaxY()) * 100
- + ")(" +
- +cx
- + "," +
- cy
- + ")(" +
- (e.target.getLocation().getX() / r.getMaxX()) * 100
- + "," +
- (e.target.getLocation().getY() / r.getMaxY()) * 100
- + ")\n";
+ double cy = ((centery + e.getCurveControlPoint().getY()) / r.getMaxY()) * 100;
+ edges.append("\\qbezier(")
+ .append(x1).append(",").append(y1).append(")(")
+ .append(cx).append(",").append(cy).append(")(")
+ .append(x2).append(",").append(y2).append(")\n");
}
}
- output.write(edges);
+ output.write(edges.toString());
output.write("\n" +
"\\end{picture}\n" +
"\\end{figure}\n" +
- "\\end{document}\n"
- );
-
- output.flush();
+ "\\end{document}\n");
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
}
diff --git a/src/graphtea/extensions/io/LoadGraph.java b/src/graphtea/extensions/io/LoadGraph.java
index d3aabc3e..494d8ccc 100755
--- a/src/graphtea/extensions/io/LoadGraph.java
+++ b/src/graphtea/extensions/io/LoadGraph.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.io;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.GraphModel;
import graphtea.plugins.main.saveload.SaveLoadPluginMethods;
@@ -32,13 +33,12 @@ public String getExtension() {
}
public GraphModel read(File file) {
- try {
- ObjectInputStream in = new ObjectInputStream(
- new FileInputStream(file));
+ try (ObjectInputStream in = new ObjectInputStream(
+ new FileInputStream(file))) {
GraphSaveObject gso = (GraphSaveObject) in.readObject();
return gso.getG();
} catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
return null;
}
diff --git a/src/graphtea/extensions/io/LoadMtx.java b/src/graphtea/extensions/io/LoadMtx.java
index e60291eb..5f647f57 100755
--- a/src/graphtea/extensions/io/LoadMtx.java
+++ b/src/graphtea/extensions/io/LoadMtx.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.io;
+import graphtea.platform.core.exception.ExceptionHandler;
import Jama.Matrix;
import graphtea.graph.graph.Edge;
@@ -62,7 +63,7 @@ public GraphModel read(File file) {
}
return g;
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
return null;
}
diff --git a/src/graphtea/extensions/io/LoadSimpleGraph.java b/src/graphtea/extensions/io/LoadSimpleGraph.java
index 92d3cfda..9ff39f59 100755
--- a/src/graphtea/extensions/io/LoadSimpleGraph.java
+++ b/src/graphtea/extensions/io/LoadSimpleGraph.java
@@ -5,6 +5,7 @@
package graphtea.extensions.io;
+import java.util.List;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GPoint;
import graphtea.graph.graph.GraphModel;
@@ -64,8 +65,7 @@ public String getExtension() {
}
public GraphModel read(File file) throws GraphIOException {
- try {
- Scanner sc = new Scanner(file);
+ try (Scanner sc = new Scanner(file)) {
String l = sc.nextLine();
if (!l.equals("graph:"))
throw new GraphIOException("Incorrect Format(in the first line)");
diff --git a/src/graphtea/extensions/io/LoadSpecialGML.java b/src/graphtea/extensions/io/LoadSpecialGML.java
index 3824163d..709cb969 100755
--- a/src/graphtea/extensions/io/LoadSpecialGML.java
+++ b/src/graphtea/extensions/io/LoadSpecialGML.java
@@ -4,6 +4,7 @@
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.io;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
@@ -35,8 +36,7 @@ public String getExtension() {
public GraphModel read(File file) throws GraphIOException {
GraphModel g = new GraphModel();
- try {
- Scanner sc = new Scanner(file);
+ try (Scanner sc = new Scanner(file)) {
while (sc.hasNext()) {
String line = sc.nextLine();
if(line.contains(" ie = graph.edgeIterator(); ie.hasNext();) {
- Edge e = ie.next();
+ for (Edge e : graph.getEdges()) {
o.println(e.source.getId() + " -> " + e.target.getId());
o.println("label " + e.getLabel());
o.println("color " + e.getColor());
o.println("weight " + e.getWeight());
}
- o.close();
} catch (IOException e) {
throw new GraphIOException(e.getMessage());
}
diff --git a/src/graphtea/extensions/io/g6format/LoadGraph6Format.java b/src/graphtea/extensions/io/g6format/LoadGraph6Format.java
index 91f02f53..27ffc0cb 100755
--- a/src/graphtea/extensions/io/g6format/LoadGraph6Format.java
+++ b/src/graphtea/extensions/io/g6format/LoadGraph6Format.java
@@ -2,12 +2,9 @@
// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
-// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
-// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
-// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
-// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.io.g6format;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.extensions.G6Format;
import graphtea.graph.graph.Edge;
@@ -39,11 +36,10 @@ public String getExtension() {
@Override
public GraphModel read(File file) {
String g6 = "";
- try {
- Scanner sc = new Scanner(file);
+ try (Scanner sc = new Scanner(file)) {
g6 = sc.nextLine();
} catch (FileNotFoundException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
GraphModel g = G6Format.stringToGraphModel(g6);
@@ -63,7 +59,7 @@ public GraphModel next(BufferedReader bri) {
bri.readLine();
g=bri.readLine();
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
String tmp = g.substring(g.indexOf("order"));
tmp = tmp.substring(tmp.indexOf(" "),tmp.length()-1);
@@ -73,7 +69,7 @@ public GraphModel next(BufferedReader bri) {
try {
g += bri.readLine() + "\n";
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
return new GraphModel();
}
}
@@ -89,7 +85,7 @@ public static ProcessBuilder getShowGProcess(String file) {
try {
cur = new java.io.File(".").getCanonicalPath();
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
ProcessBuilder process;
@@ -110,7 +106,7 @@ public static BufferedReader showG(File file) {
Process p = process.start();
return new BufferedReader(new InputStreamReader(p.getInputStream()));
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
return null;
}
@@ -130,13 +126,14 @@ public static GraphModel parseGraph(Scanner sc) {
String tmp = sc.nextLine();
int first = Integer.parseInt(tmp.substring(0,tmp.indexOf(":")-1).trim());
tmp = tmp.substring(tmp.indexOf(":") + 1);
- Scanner sc2 = new Scanner(tmp.trim());
- while (sc2.hasNext()) {
- String num = sc2.next();
- if (num.contains(";")) num = num.substring(0, num.indexOf(";"));
- int id = Integer.parseInt(num.trim());
- if (!g.isEdge(g.getVertex(first), g.getVertex(id))) {
- g.addEdge(new Edge(g.getVertex(first), g.getVertex(id)));
+ try (Scanner sc2 = new Scanner(tmp.trim())) {
+ while (sc2.hasNext()) {
+ String num = sc2.next();
+ if (num.contains(";")) num = num.substring(0, num.indexOf(";"));
+ int id = Integer.parseInt(num.trim());
+ if (!g.isEdge(g.getVertex(first), g.getVertex(id))) {
+ g.addEdge(new Edge(g.getVertex(first), g.getVertex(id)));
+ }
}
}
}
diff --git a/src/graphtea/extensions/io/g6format/SaveGraph6Format.java b/src/graphtea/extensions/io/g6format/SaveGraph6Format.java
index d123aa2b..cdb28933 100755
--- a/src/graphtea/extensions/io/g6format/SaveGraph6Format.java
+++ b/src/graphtea/extensions/io/g6format/SaveGraph6Format.java
@@ -8,6 +8,7 @@
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.io.g6format;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.extensions.G6Format;
import graphtea.graph.graph.GraphModel;
@@ -32,16 +33,12 @@ public String getExtension() {
@Override
public void write(File file, GraphModel graph) throws GraphIOException {
- try {
- FileWriter fw = new FileWriter(file,isAppend);
- G6Format g6f = new G6Format();
+ try (FileWriter fw = new FileWriter(file, isAppend)) {
String s = G6Format.graphToG6(graph);
fw.write(s);
fw.write(System.lineSeparator());
- fw.close();
-
} catch (IOException e) {
- e.printStackTrace();
+ ExceptionHandler.catchException(e);
}
}
diff --git a/src/graphtea/extensions/io/specialjson/LoadSpecialjson.java b/src/graphtea/extensions/io/specialjson/LoadSpecialjson.java
index e0731cfc..37c5f6e0 100755
--- a/src/graphtea/extensions/io/specialjson/LoadSpecialjson.java
+++ b/src/graphtea/extensions/io/specialjson/LoadSpecialjson.java
@@ -8,6 +8,7 @@
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.io.specialjson;
+import graphtea.platform.core.exception.ExceptionHandler;
import graphtea.graph.graph.*;
import graphtea.plugins.main.saveload.SaveLoadPluginMethods;
@@ -19,9 +20,10 @@
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Scanner;
-import java.util.Vector;
import static graphtea.platform.Application.blackboard;
@@ -48,17 +50,17 @@ String between(String s, char c1, char c2) {
public GraphModel read(File file) {
GraphModel g = new GraphModel(false);
//2793
- Vector regions = new Vector<>();
- Vector sttlWithoutCoordinates = new Vector<>();
+ List regions = new ArrayList<>();
+ List sttlWithoutCoordinates = new ArrayList<>();
HashMap labelVertex = new HashMap<>();
- HashMap> regionVertices = new HashMap<>();
+ HashMap> regionVertices = new HashMap<>();
HashMap verticesRegion = new HashMap<>();
- try {
+ try (Scanner sc = new Scanner(file);
+ Scanner sc2 = new Scanner(file)) {
int i = 0;
- Scanner sc = new Scanner(file);
FastRenderer.defaultVertexRadius = 12;
RenderTable rt = new RenderTable();
- Vector titles = new Vector<>();
+ List titles = new ArrayList<>();
titles.add("Settlements");
titles.add("Vertex");
titles.add("processed");
@@ -81,7 +83,7 @@ public GraphModel read(File file) {
lng = Double.parseDouble(str_lng);
} else {
sttlWithoutCoordinates.add(id);
- Vector