Path refactoring net.berack is now the corect pakage, update java to 23
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "interactive"
|
||||
}
|
||||
4
pom.xml
4
pom.xml
@@ -73,8 +73,8 @@
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
<maven.compiler.target>23</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,18 +0,0 @@
|
||||
package berack96.lib.graph;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Compare two arbitrary objects.<br>
|
||||
* It uses the method hashCode that every object has to compare two objects.<br>
|
||||
* This is a simple use
|
||||
*/
|
||||
public class ObjectsComparator implements Comparator<Object> {
|
||||
static public final ObjectsComparator instance = new ObjectsComparator();
|
||||
|
||||
private ObjectsComparator(){};
|
||||
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
return o1.hashCode() - o2.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package berack96.lib.graph;
|
||||
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
import berack96.lib.graph.visit.impl.BFS;
|
||||
import berack96.lib.graph.visit.impl.Dijkstra;
|
||||
import berack96.lib.graph.visit.impl.VisitInfo;
|
||||
package net.berack.upo;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.Vertex;
|
||||
import net.berack.upo.graph.VisitStrategy;
|
||||
import net.berack.upo.graph.visit.BFS;
|
||||
import net.berack.upo.graph.visit.Dijkstra;
|
||||
import net.berack.upo.graph.visit.VisitInfo;
|
||||
|
||||
/**
|
||||
* An abstract class for the graphs.<br>
|
||||
* This class is used for the graphs in general.<br>
|
||||
@@ -24,6 +26,12 @@ public abstract class Graph<V> implements Iterable<V> {
|
||||
public final static String NOT_CONNECTED = "The source vertex doesn't have a path that reach the destination";
|
||||
public final static String PARAM_NULL = "The parameter must not be null";
|
||||
public final static String VERTEX_NOT_CONTAINED = "The vertex must be contained in the graph";
|
||||
public final static Comparator<Object> OBJECT_COMPARATOR = new Comparator<Object>() {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
return o1.hashCode() - o2.hashCode();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the default map. All operations are O(log(n))<br>
|
||||
@@ -34,7 +42,7 @@ public abstract class Graph<V> implements Iterable<V> {
|
||||
* @return A newly created TreeMap instance with ObjectsComparator as comparator
|
||||
*/
|
||||
public final static <X, Y> Map<X, Y> getDefaultMap() {
|
||||
return new TreeMap<X, Y>(ObjectsComparator.instance);
|
||||
return new TreeMap<X, Y>(OBJECT_COMPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +54,7 @@ public abstract class Graph<V> implements Iterable<V> {
|
||||
* @return A newly created TreeSet instance with ObjectsComparator as comparator
|
||||
*/
|
||||
public final static <X> Set<X> getDefaultSet() {
|
||||
return new TreeSet<X>(ObjectsComparator.instance);
|
||||
return new TreeSet<X>(OBJECT_COMPARATOR);
|
||||
}
|
||||
|
||||
//------------------- INSTANCE -----------------
|
||||
@@ -359,7 +367,7 @@ public abstract class Graph<V> implements Iterable<V> {
|
||||
*/
|
||||
public final Set<Object> marks() {
|
||||
Set<Object> ret = getDefaultSet();
|
||||
markers.forEach((v, set) -> ret.addAll(set));
|
||||
markers.forEach((_, set) -> ret.addAll(set));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -376,7 +384,7 @@ public abstract class Graph<V> implements Iterable<V> {
|
||||
public final void mark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
|
||||
check(mark);
|
||||
checkVert(vertex);
|
||||
Set<Object> marks = markers.computeIfAbsent(vertex, v -> getDefaultSet());
|
||||
Set<Object> marks = markers.computeIfAbsent(vertex, _ -> getDefaultSet());
|
||||
marks.add(mark);
|
||||
}
|
||||
|
||||
@@ -391,7 +399,7 @@ public abstract class Graph<V> implements Iterable<V> {
|
||||
public final void unMark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
|
||||
check(mark);
|
||||
checkVert(vertex);
|
||||
markers.computeIfPresent(vertex, (v, set) -> {
|
||||
markers.computeIfPresent(vertex, (_, set) -> {
|
||||
set.remove(mark);
|
||||
if (set.size() > 0)
|
||||
return set;
|
||||
@@ -1,12 +1,13 @@
|
||||
package berack96.lib.graph;
|
||||
|
||||
import berack96.lib.graph.visit.VisitSCC;
|
||||
import berack96.lib.graph.visit.VisitTopological;
|
||||
import berack96.lib.graph.visit.impl.Tarjan;
|
||||
package net.berack.upo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.VisitSCC;
|
||||
import net.berack.upo.graph.VisitTopological;
|
||||
import net.berack.upo.graph.visit.Tarjan;
|
||||
|
||||
/**
|
||||
* This is a more specific interface for an implementation of a Undirected Graph.<br>
|
||||
* An Undirected Graph is a Graph where an arc or edge can be traversed in both ways.<br>
|
||||
@@ -1,10 +1,11 @@
|
||||
package berack96.lib.graph;
|
||||
|
||||
import berack96.lib.graph.visit.VisitMST;
|
||||
import berack96.lib.graph.visit.impl.Prim;
|
||||
package net.berack.upo;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.VisitMST;
|
||||
import net.berack.upo.graph.visit.Prim;
|
||||
|
||||
/**
|
||||
* This is a more specific interface for an implementation of a Directed Graph.<br>
|
||||
* A Directed Graph is a Graph where an arc or edge can be traversed in only one way.<br>
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -1,11 +1,11 @@
|
||||
package berack96.lib.graph.impl;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.GraphDirected;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphDirected;
|
||||
|
||||
/**
|
||||
* An implementation of the graph using an adjacent list for representing the edges
|
||||
*
|
||||
@@ -46,7 +46,7 @@ public class ListGraph<V> extends GraphDirected<V> {
|
||||
public void remove(V vertex) {
|
||||
checkVert(vertex);
|
||||
adj.remove(vertex);
|
||||
adj.forEach((v, list) -> list.remove(getAdj(list, vertex)));
|
||||
adj.forEach((_, list) -> list.remove(getAdj(list, vertex)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,12 +129,12 @@ public class ListGraph<V> extends GraphDirected<V> {
|
||||
public void removeAllEdge(V vertex) throws NullPointerException, IllegalArgumentException {
|
||||
checkVert(vertex);
|
||||
adj.get(vertex).clear();
|
||||
adj.forEach((v, list) -> list.remove(getAdj(list, vertex)));
|
||||
adj.forEach((_, list) -> list.remove(getAdj(list, vertex)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllEdge() {
|
||||
adj.forEach((v, list) -> list.clear());
|
||||
adj.forEach((_, list) -> list.clear());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,11 +1,11 @@
|
||||
package berack96.lib.graph.impl;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.GraphDirected;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphDirected;
|
||||
|
||||
/**
|
||||
* Graph that uses TreeMap for vertices and edges<br>
|
||||
* More specifically it utilizes a Map containing all the vertices mapped to all their edges<br>
|
||||
@@ -40,8 +40,8 @@ public class MapGraph<V> extends GraphDirected<V> {
|
||||
@Override
|
||||
public void add(V vertex) {
|
||||
check(vertex);
|
||||
edges.computeIfAbsent(vertex, v -> new TreeMap<>());
|
||||
edges.forEach((v, adj) -> adj.remove(vertex));
|
||||
edges.computeIfAbsent(vertex, _ -> new TreeMap<>());
|
||||
edges.forEach((_, adj) -> adj.remove(vertex));
|
||||
edges.get(vertex).clear();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class MapGraph<V> extends GraphDirected<V> {
|
||||
public void remove(V vertex) {
|
||||
checkVert(vertex);
|
||||
edges.remove(vertex);
|
||||
edges.forEach((v, map) -> map.remove(vertex));
|
||||
edges.forEach((_, map) -> map.remove(vertex));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,7 +109,7 @@ public class MapGraph<V> extends GraphDirected<V> {
|
||||
@Override
|
||||
public int numberOfEdges() {
|
||||
AtomicInteger sum = new AtomicInteger(0);
|
||||
edges.forEach((v, map) -> sum.getAndAdd(map.size()));
|
||||
edges.forEach((_, map) -> sum.getAndAdd(map.size()));
|
||||
|
||||
return sum.get();
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package berack96.lib.graph.impl;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.GraphDirected;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphDirected;
|
||||
|
||||
/**
|
||||
* An implementation of the graph using a matrix for representing the edges
|
||||
*
|
||||
@@ -59,7 +59,7 @@ public class MatrixGraph<V> extends GraphDirected<V> {
|
||||
}
|
||||
|
||||
matrix = newMatrix;
|
||||
map.replaceAll((vert, index) -> index > x ? index - 1 : index);
|
||||
map.replaceAll((_, index) -> index > x ? index - 1 : index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,7 +165,7 @@ public class MatrixGraph<V> extends GraphDirected<V> {
|
||||
check(vertices);
|
||||
for (V vert : vertices)
|
||||
if (vert != null)
|
||||
map.compute(vert, (v, i) -> {
|
||||
map.compute(vert, (_, i) -> {
|
||||
if (i == null)
|
||||
return map.size();
|
||||
removeAllEdge(vert);
|
||||
@@ -1,11 +1,10 @@
|
||||
package berack96.lib.graph.impl;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.GraphUndirected;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphUndirected;
|
||||
|
||||
public class MatrixUndGraph<V> extends GraphUndirected<V> {
|
||||
|
||||
Map<V, Integer> map = getDefaultMap();
|
||||
@@ -48,7 +47,7 @@ public class MatrixUndGraph<V> extends GraphUndirected<V> {
|
||||
newMatrix[i][j] = matrix[i + 1][j + (j < x ? 0 : 1)];
|
||||
|
||||
matrix = newMatrix;
|
||||
map.replaceAll((vert, index) -> index > x ? index - 1 : index);
|
||||
map.replaceAll((_, index) -> index > x ? index - 1 : index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,13 +1,13 @@
|
||||
package berack96.lib.graph;
|
||||
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
import berack96.lib.graph.visit.impl.VisitInfo;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.visit.VisitInfo;
|
||||
|
||||
/**
|
||||
* Class used for represent a vertex of the graph.<br>
|
||||
* The vertex contained is linked with the graph, so if any changes are made to
|
||||
@@ -1,10 +1,9 @@
|
||||
package berack96.lib.graph.visit;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.Graph;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
|
||||
/**
|
||||
* Interface that is helpful for implements visit that needs to retrieve the distance between a vertex to all the others
|
||||
*
|
||||
@@ -1,6 +1,4 @@
|
||||
package berack96.lib.graph.visit;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -1,6 +1,4 @@
|
||||
package berack96.lib.graph.visit;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.visit;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package berack96.lib.graph.visit;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.GraphDirected;
|
||||
import berack96.lib.graph.visit.impl.VisitInfo;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphDirected;
|
||||
import net.berack.upo.graph.visit.VisitInfo;
|
||||
|
||||
/**
|
||||
* This class is used for define some strategy for the visit of a graph.
|
||||
*
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.visit;
|
||||
package net.berack.upo.graph;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.models;
|
||||
package net.berack.upo.graph.savemodels;
|
||||
|
||||
/**
|
||||
* Support class used for saving a Graph in a file.
|
||||
@@ -1,13 +1,14 @@
|
||||
package berack96.lib.graph.models;
|
||||
package net.berack.upo.graph.savemodels;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.Graph;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.InstanceCreator;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.Edge;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ public class GraphSaveStructure<V> {
|
||||
*/
|
||||
public final void load(Graph<V> graph, String fileName, Class<V> classV) throws FileNotFoundException, NullPointerException {
|
||||
//this way i use this class for the load
|
||||
InstanceCreator<GraphSaveStructure<V>> creator = type -> this;
|
||||
InstanceCreator<GraphSaveStructure<V>> creator = _ -> this;
|
||||
Gson gson = new GsonBuilder().registerTypeAdapter(this.getClass(), creator).create();
|
||||
JsonReader reader = new JsonReader(new FileReader(fileName));
|
||||
gson.fromJson(reader, GraphSaveStructure.class);
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.models;
|
||||
package net.berack.upo.graph.savemodels;
|
||||
|
||||
/**
|
||||
* Support class used for saving a Graph in a file.
|
||||
@@ -1,12 +1,13 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.view.edge.EdgeListener;
|
||||
import berack96.lib.graph.view.vertex.VertexListener;
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.BevelBorder;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.VisitStrategy;
|
||||
import net.berack.upo.graph.view.edge.EdgeListener;
|
||||
import net.berack.upo.graph.view.vertex.VertexListener;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.io.IOException;
|
||||
@@ -91,7 +92,7 @@ public class GraphInfo<V> extends JPanel {
|
||||
JLabel vEdgesOutNumber = new JLabel();
|
||||
|
||||
JButton modVertex = new JButton("Modify Vertices");
|
||||
modVertex.addActionListener(a -> {
|
||||
modVertex.addActionListener(_ -> {
|
||||
comboBox.setSelectedIndex(0);
|
||||
listenerDescription.setText(vListener.getDescription());
|
||||
graphPanel.setGraphListener(vListener);
|
||||
@@ -101,7 +102,7 @@ public class GraphInfo<V> extends JPanel {
|
||||
});
|
||||
|
||||
JButton modEdge = new JButton("Modify Edges");
|
||||
modEdge.addActionListener(a -> {
|
||||
modEdge.addActionListener(_ -> {
|
||||
comboBox.setSelectedIndex(0);
|
||||
listenerDescription.setText(eListener.getDescription());
|
||||
graphPanel.setGraphListener(eListener);
|
||||
@@ -138,7 +139,7 @@ public class GraphInfo<V> extends JPanel {
|
||||
/* SAVE/LOAD */
|
||||
JTextField fileText = new JTextField();
|
||||
JButton saveB = new JButton("Save");
|
||||
saveB.addActionListener(a -> {
|
||||
saveB.addActionListener(_ -> {
|
||||
try {
|
||||
graphPanel.save(fileText.getText());
|
||||
textResult.setText("");
|
||||
@@ -147,7 +148,7 @@ public class GraphInfo<V> extends JPanel {
|
||||
}
|
||||
});
|
||||
JButton loadB = new JButton("Load");
|
||||
loadB.addActionListener(a -> {
|
||||
loadB.addActionListener(_ -> {
|
||||
try {
|
||||
graphPanel.load(fileText.getText());
|
||||
textResult.setText("");
|
||||
@@ -180,7 +181,7 @@ public class GraphInfo<V> extends JPanel {
|
||||
|
||||
modVertex.doClick();
|
||||
|
||||
graphPanel.addObserver((o, arg) -> {
|
||||
graphPanel.addObserver((_, arg) -> {
|
||||
Graph<V> graph = graphPanel.getGraph();
|
||||
if(arg.equals(graph)) {
|
||||
vNumber.setText(String.valueOf(graph.size()));
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.view;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseListener;
|
||||
@@ -1,10 +1,4 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.Vertex;
|
||||
import berack96.lib.graph.impl.MapGraph;
|
||||
import berack96.lib.graph.view.edge.EdgeComponent;
|
||||
import berack96.lib.graph.view.vertex.VertexComponent;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyListener;
|
||||
@@ -17,6 +11,12 @@ import java.util.HashSet;
|
||||
import java.util.Observer;
|
||||
import java.util.Set;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.MapGraph;
|
||||
import net.berack.upo.graph.Vertex;
|
||||
import net.berack.upo.graph.view.edge.EdgeComponent;
|
||||
import net.berack.upo.graph.view.vertex.VertexComponent;
|
||||
|
||||
@SuppressWarnings({"unchecked", "deprecation"})
|
||||
public class GraphPanel<V> extends Component {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.models.GraphSaveStructure;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.savemodels.GraphSaveStructure;
|
||||
|
||||
public class GraphPointsSave<V> extends GraphSaveStructure<V> {
|
||||
|
||||
final private GraphPanel<V> panel;
|
||||
@@ -1,14 +1,15 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import berack96.lib.graph.view.edge.EdgeListener;
|
||||
import berack96.lib.graph.view.vertex.VertexListener;
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
import berack96.lib.graph.visit.impl.BFS;
|
||||
import berack96.lib.graph.visit.impl.DFS;
|
||||
import berack96.lib.graph.visit.impl.Dijkstra;
|
||||
import berack96.lib.graph.visit.impl.Tarjan;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.berack.upo.graph.VisitStrategy;
|
||||
import net.berack.upo.graph.view.edge.EdgeListener;
|
||||
import net.berack.upo.graph.view.vertex.VertexListener;
|
||||
import net.berack.upo.graph.visit.BFS;
|
||||
import net.berack.upo.graph.visit.DFS;
|
||||
import net.berack.upo.graph.visit.Dijkstra;
|
||||
import net.berack.upo.graph.visit.Tarjan;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Serial;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.view;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import berack96.lib.graph.view.edge.EdgeIntListener;
|
||||
import berack96.lib.graph.view.edge.EdgeView;
|
||||
import berack96.lib.graph.view.vertex.VertexIntListener;
|
||||
import berack96.lib.graph.view.vertex.VertexView;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import net.berack.upo.graph.view.edge.EdgeIntListener;
|
||||
import net.berack.upo.graph.view.edge.EdgeView;
|
||||
import net.berack.upo.graph.view.vertex.VertexIntListener;
|
||||
import net.berack.upo.graph.view.vertex.VertexView;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -1,11 +1,12 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.view.vertex.VertexComponent;
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
import berack96.lib.graph.visit.impl.VisitInfo;
|
||||
package net.berack.upo.graph.view;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.VisitStrategy;
|
||||
import net.berack.upo.graph.view.vertex.VertexComponent;
|
||||
import net.berack.upo.graph.visit.VisitInfo;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.HashSet;
|
||||
@@ -59,7 +60,7 @@ public class VisitListener<V> implements GraphListener {
|
||||
|
||||
info.forEach(v -> {
|
||||
final boolean visited = v.timeVisited == count.get();
|
||||
Timer timer = new Timer(count.getAndIncrement() * refreshTime, e1 -> {
|
||||
Timer timer = new Timer(count.getAndIncrement() * refreshTime, _ -> {
|
||||
if (visited && v.parent !=null)
|
||||
graph.mark(v.vertex, v.parent);
|
||||
graph.mark(v.vertex, visited ? "visited" : "discovered");
|
||||
@@ -1,11 +1,11 @@
|
||||
package berack96.lib.graph.view.edge;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.view.vertex.VertexComponent;
|
||||
package net.berack.upo.graph.view.edge;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Serial;
|
||||
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.view.vertex.VertexComponent;
|
||||
|
||||
public class EdgeComponent<V> extends Component {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -1,7 +1,7 @@
|
||||
package berack96.lib.graph.view.edge;
|
||||
package net.berack.upo.graph.view.edge;
|
||||
|
||||
import berack96.lib.graph.Vertex;
|
||||
import berack96.lib.graph.view.GraphPanel;
|
||||
import net.berack.upo.graph.Vertex;
|
||||
import net.berack.upo.graph.view.GraphPanel;
|
||||
|
||||
public class EdgeIntListener<V> extends EdgeListener<V> {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package berack96.lib.graph.view.edge;
|
||||
|
||||
import berack96.lib.graph.Vertex;
|
||||
import berack96.lib.graph.view.GraphListener;
|
||||
import berack96.lib.graph.view.GraphPanel;
|
||||
import berack96.lib.graph.view.vertex.VertexComponent;
|
||||
package net.berack.upo.graph.view.edge;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import net.berack.upo.graph.Vertex;
|
||||
import net.berack.upo.graph.view.GraphListener;
|
||||
import net.berack.upo.graph.view.GraphPanel;
|
||||
import net.berack.upo.graph.view.vertex.VertexComponent;
|
||||
|
||||
public abstract class EdgeListener<V> implements GraphListener {
|
||||
|
||||
private final GraphPanel<V> graphPanel;
|
||||
@@ -1,12 +1,12 @@
|
||||
package berack96.lib.graph.view.edge;
|
||||
|
||||
import berack96.lib.graph.view.GraphicalView;
|
||||
import berack96.lib.graph.view.stuff.Arrow;
|
||||
package net.berack.upo.graph.view.edge;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.berack.upo.graph.view.GraphicalView;
|
||||
import net.berack.upo.graph.view.polygons.Arrow;
|
||||
|
||||
public class EdgeView<V> implements GraphicalView<EdgeComponent<V>> {
|
||||
|
||||
private static final Font FONT = new Font("Papyrus", Font.BOLD, 14);
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.view.stuff;
|
||||
package net.berack.upo.graph.view.polygons;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Serial;
|
||||
@@ -1,10 +1,10 @@
|
||||
package berack96.lib.graph.view.vertex;
|
||||
|
||||
import berack96.lib.graph.Vertex;
|
||||
package net.berack.upo.graph.view.vertex;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Serial;
|
||||
|
||||
import net.berack.upo.graph.Vertex;
|
||||
|
||||
public class VertexComponent<V> extends Component {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -1,10 +1,10 @@
|
||||
package berack96.lib.graph.view.vertex;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.view.GraphPanel;
|
||||
package net.berack.upo.graph.view.vertex;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.view.GraphPanel;
|
||||
|
||||
public class VertexIntListener extends VertexListener<Integer> {
|
||||
|
||||
public VertexIntListener(GraphPanel<Integer> panel) {
|
||||
@@ -1,13 +1,13 @@
|
||||
package berack96.lib.graph.view.vertex;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.view.GraphListener;
|
||||
import berack96.lib.graph.view.GraphPanel;
|
||||
package net.berack.upo.graph.view.vertex;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.view.GraphListener;
|
||||
import net.berack.upo.graph.view.GraphPanel;
|
||||
|
||||
public abstract class VertexListener<V> implements GraphListener {
|
||||
|
||||
protected final GraphPanel<V> panel;
|
||||
@@ -1,9 +1,9 @@
|
||||
package berack96.lib.graph.view.vertex;
|
||||
|
||||
import berack96.lib.graph.view.GraphicalView;
|
||||
package net.berack.upo.graph.view.vertex;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import net.berack.upo.graph.view.GraphicalView;
|
||||
|
||||
public class VertexView<V> implements GraphicalView<VertexComponent<V>> {
|
||||
|
||||
private static final Font FONT = new Font("Comic Sans MS", Font.BOLD, 17);
|
||||
@@ -1,11 +1,11 @@
|
||||
package berack96.lib.graph.visit.impl;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
package net.berack.upo.graph.visit;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.VisitStrategy;
|
||||
|
||||
/**
|
||||
* Breadth-first search<br>
|
||||
* The algorithm starts at the root node and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level.
|
||||
@@ -1,12 +1,12 @@
|
||||
package berack96.lib.graph.visit.impl;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
package net.berack.upo.graph.visit;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Stack;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.VisitStrategy;
|
||||
|
||||
/**
|
||||
* Depth-first search<br>
|
||||
* The algorithm starts at the root node and explores as far as possible along each branch before backtracking.
|
||||
@@ -1,12 +1,12 @@
|
||||
package berack96.lib.graph.visit.impl;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.visit.VisitDistance;
|
||||
package net.berack.upo.graph.visit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.VisitDistance;
|
||||
|
||||
/**
|
||||
* Class that implements the Dijkstra algorithm and uses it for getting all the distance from a source
|
||||
*
|
||||
@@ -1,15 +1,15 @@
|
||||
package berack96.lib.graph.visit.impl;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.GraphUndirected;
|
||||
import berack96.lib.graph.struct.QuickFind;
|
||||
import berack96.lib.graph.struct.UnionFind;
|
||||
import berack96.lib.graph.visit.VisitMST;
|
||||
package net.berack.upo.graph.visit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphUndirected;
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.VisitMST;
|
||||
import net.berack.upo.graph.visit.struct.QuickFind;
|
||||
import net.berack.upo.graph.visit.struct.UnionFind;
|
||||
|
||||
/**
|
||||
* Class that implement the algorithm discovered by Kruskal for the minimum spanning forest
|
||||
* for a given {@link GraphUndirected}
|
||||
@@ -1,13 +1,13 @@
|
||||
package berack96.lib.graph.visit.impl;
|
||||
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.GraphUndirected;
|
||||
import berack96.lib.graph.visit.VisitMST;
|
||||
package net.berack.upo.graph.visit;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphUndirected;
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.VisitMST;
|
||||
|
||||
/**
|
||||
* Class that implement the algorithm discovered by Prim for the minimum spanning forest
|
||||
* for a given {@link GraphUndirected}
|
||||
@@ -1,12 +1,12 @@
|
||||
package berack96.lib.graph.visit.impl;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.visit.VisitSCC;
|
||||
import berack96.lib.graph.visit.VisitTopological;
|
||||
package net.berack.upo.graph.visit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.graph.VisitSCC;
|
||||
import net.berack.upo.graph.VisitTopological;
|
||||
|
||||
/**
|
||||
* Class that implements the Tarjan algorithm and uses it for getting the SCC and the topological sort
|
||||
*
|
||||
@@ -1,10 +1,10 @@
|
||||
package berack96.lib.graph.visit.impl;
|
||||
|
||||
import berack96.lib.graph.visit.VisitStrategy;
|
||||
package net.berack.upo.graph.visit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.berack.upo.graph.VisitStrategy;
|
||||
|
||||
/**
|
||||
* The class used for getting the info of the visit.<br>
|
||||
* It could be used with the algorithm of the visit for set some useful data.
|
||||
@@ -167,7 +167,7 @@ public class VisitInfo<V> implements Iterable<VisitInfo<V>.VertexInfo> {
|
||||
* @param vertex the vertex that has been discovered
|
||||
*/
|
||||
synchronized void setDiscovered(V vertex) {
|
||||
VertexInfo info = vertices.computeIfAbsent(vertex, (v) -> new VertexInfo(vertex));
|
||||
VertexInfo info = vertices.computeIfAbsent(vertex, _ -> new VertexInfo(vertex));
|
||||
if(info.timeDiscovered != NOT_SET)
|
||||
return;
|
||||
|
||||
@@ -231,7 +231,7 @@ public class VisitInfo<V> implements Iterable<VisitInfo<V>.VertexInfo> {
|
||||
*/
|
||||
public void forEachDiscovered(Consumer<? super VertexInfo> consumer) {
|
||||
Queue<VertexInfo> queue = new PriorityQueue<>();
|
||||
vertices.forEach((v, info) -> {
|
||||
vertices.forEach((_, info) -> {
|
||||
if (info.timeDiscovered != NOT_SET)
|
||||
queue.offer(new VertexInfo(info, false));
|
||||
});
|
||||
@@ -248,7 +248,7 @@ public class VisitInfo<V> implements Iterable<VisitInfo<V>.VertexInfo> {
|
||||
*/
|
||||
public void forEachVisited(Consumer<? super VertexInfo> consumer) {
|
||||
Queue<VertexInfo> queue = new PriorityQueue<>();
|
||||
vertices.forEach((v, info) -> {
|
||||
vertices.forEach((_, info) -> {
|
||||
if (info.timeVisited != NOT_SET)
|
||||
queue.offer(new VertexInfo(info, true));
|
||||
});
|
||||
@@ -260,7 +260,7 @@ public class VisitInfo<V> implements Iterable<VisitInfo<V>.VertexInfo> {
|
||||
@Override
|
||||
public Iterator<VertexInfo> iterator() {
|
||||
List<VertexInfo> list = new ArrayList<>(vertices.size() * 2);
|
||||
vertices.forEach((v, info) -> {
|
||||
vertices.forEach((_, info) -> {
|
||||
if (info.timeDiscovered != NOT_SET)
|
||||
list.add(new VertexInfo(info, false));
|
||||
if (info.timeVisited != NOT_SET)
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.struct;
|
||||
package net.berack.upo.graph.visit.struct;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@@ -6,7 +6,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
import berack96.lib.graph.Graph;
|
||||
import net.berack.upo.Graph;
|
||||
|
||||
/**
|
||||
* Simple implementation of the {@link UnionFind} interface with priority to the find function.
|
||||
@@ -1,4 +1,4 @@
|
||||
package berack96.lib.graph.struct;
|
||||
package net.berack.upo.graph.visit.struct;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
package berack96.test.lib;
|
||||
package net.berack.upo.graph.test;
|
||||
|
||||
import berack96.lib.graph.*;
|
||||
import berack96.lib.graph.impl.ListGraph;
|
||||
import berack96.lib.graph.impl.MapGraph;
|
||||
import berack96.lib.graph.impl.MatrixGraph;
|
||||
import berack96.lib.graph.impl.MatrixUndGraph;
|
||||
import berack96.lib.graph.models.GraphSaveStructure;
|
||||
import berack96.lib.graph.struct.QuickFind;
|
||||
import berack96.lib.graph.struct.UnionFind;
|
||||
import berack96.lib.graph.visit.impl.BFS;
|
||||
import berack96.lib.graph.visit.impl.DFS;
|
||||
import berack96.lib.graph.visit.impl.VisitInfo;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import net.berack.upo.Graph;
|
||||
import net.berack.upo.GraphDirected;
|
||||
import net.berack.upo.GraphUndirected;
|
||||
import net.berack.upo.graph.Edge;
|
||||
import net.berack.upo.graph.ListGraph;
|
||||
import net.berack.upo.graph.MapGraph;
|
||||
import net.berack.upo.graph.MatrixGraph;
|
||||
import net.berack.upo.graph.MatrixUndGraph;
|
||||
import net.berack.upo.graph.Vertex;
|
||||
import net.berack.upo.graph.savemodels.GraphSaveStructure;
|
||||
import net.berack.upo.graph.visit.BFS;
|
||||
import net.berack.upo.graph.visit.DFS;
|
||||
import net.berack.upo.graph.visit.VisitInfo;
|
||||
import net.berack.upo.graph.visit.struct.QuickFind;
|
||||
import net.berack.upo.graph.visit.struct.UnionFind;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
Reference in New Issue
Block a user