dsadasdasd
* added a method where you can get all the marks * implemented and tested * moved main * changed README * builded JavaDoc * builded jar
This commit is contained in:
@@ -50,6 +50,17 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
*/
|
||||
boolean isDAG();
|
||||
|
||||
/**
|
||||
* Check if the vertex passed is contained in the graph or not.<br>
|
||||
* The vertex V1 is contained in the graph G, if and only if:<br>
|
||||
* exist V2 in G such that V2.equals(V1)
|
||||
*
|
||||
* @param vertex the vertex to check
|
||||
* @return true if the vertex is contained, false otherwise
|
||||
* @throws NullPointerException if the vertex is null
|
||||
*/
|
||||
boolean contains(V vertex) throws NullPointerException;
|
||||
|
||||
/**
|
||||
* Get an instance of the vertex linked with this graph.<br>
|
||||
* For more info see {@link Vertex}
|
||||
@@ -72,7 +83,7 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
|
||||
/**
|
||||
* Add the specified vertex to the graph only if the graph doesn't contains it.<br>
|
||||
* The graph contains a vertex only if the method {@link #contains(V)} returns true.
|
||||
* The graph contains a vertex only if the method {@link #contains(Object)} returns true.
|
||||
*
|
||||
* @param vertex the vertex to add
|
||||
* @return true if the vertex is added, false if the graph contains the vertex and therefore the new one is not added
|
||||
@@ -107,16 +118,15 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
void removeAllVertex();
|
||||
|
||||
/**
|
||||
* Check if the vertex passed is contained in the graph or not.<br>
|
||||
* The vertex V1 is contained in the graph G, if and only if:<br>
|
||||
* exist V2 in G such that V2.equals(V1)
|
||||
*
|
||||
* @param vertex the vertex to check
|
||||
* @return true if the vertex is contained, false otherwise
|
||||
* @throws NullPointerException if the vertex is null
|
||||
* Get all the marks of this graph.<br>
|
||||
* Specifically it will return a collection of marks where every mark<br>
|
||||
* as associated at least one vertex of the graph.<br>
|
||||
* If the graph doesn't have vertex marked then it is returned an empty collection.
|
||||
*
|
||||
* @return a collection of marks
|
||||
*/
|
||||
boolean contains(V vertex) throws NullPointerException;
|
||||
|
||||
Collection<Object> marks();
|
||||
|
||||
/**
|
||||
* Add to the specified vertex the mark passed.<br>
|
||||
* A vertex can have multiple marker.
|
||||
@@ -469,6 +479,7 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
* @param source the source vertex of the visit
|
||||
* @param strategy the algorithm for visiting the graph
|
||||
* @param visit the function to apply at each vertex
|
||||
* @return an info of the visit
|
||||
* @throws NullPointerException if one of the parameter is null (except the consumer)
|
||||
* @throws IllegalArgumentException if the vertex is not in the graph
|
||||
*/
|
||||
@@ -477,8 +488,8 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
/**
|
||||
* This method will create a new Graph that is the transposed version of the original.<br>
|
||||
* At the end of this method the new graph will have all the edges inverted in orientation.<br>
|
||||
* Example: if the graph G contains (V1, V2, V3) as vertex, and (V1->V2, V3->V2) as edges,
|
||||
* the transpose graph G' will contain (V1, V2, V3) as vertex, and (V2->V1, V2->V3) as edges.
|
||||
* Example: if the graph G contains (V1, V2, V3) as vertex, and (V1->V2, V3->V2) as edges,
|
||||
* the transpose graph G' will contain (V1, V2, V3) as vertex, and (V2->V1, V2->V3) as edges.
|
||||
*
|
||||
* @return a transposed graph of this instance
|
||||
*/
|
||||
@@ -510,7 +521,7 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
* Of course the sub-graph will contain the edges that link the vertices, but only the one selected.
|
||||
*
|
||||
* @param source the source vertex
|
||||
* @param depth the maximum depth (must be a positive number, if >=0 a graph containing only the source is returned)
|
||||
* @param depth the maximum depth (must be a positive number, if >=0 a graph containing only the source is returned)
|
||||
* @return a sub-graph of the original
|
||||
* @throws NullPointerException if the vertex is null
|
||||
* @throws IllegalArgumentException if the vertex is not contained
|
||||
@@ -555,7 +566,8 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
* Save the Graph passed as input to a file inserted as parameter.<br>
|
||||
* The resulting file is a Json string representing all the graph.<br>
|
||||
* If the directory for getting through the file do not exist,<br>
|
||||
* then it is created.
|
||||
* then it is created.<br>
|
||||
* For now the marks are not included.
|
||||
*
|
||||
* @param graph the graph to save
|
||||
* @param file the name of the file
|
||||
@@ -570,6 +582,7 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
|
||||
* The resulting file is a Json string representing all the graph.<br>
|
||||
* If the directory for getting through the file do not exist,<br>
|
||||
* then it is created.<br>
|
||||
* For now the marks are not included.<br>
|
||||
* The additional parameter is used if you want to save other as well as the graph.
|
||||
*
|
||||
* @param graph the graph to save
|
||||
|
||||
@@ -57,7 +57,7 @@ public class AdjGraph<V, W extends Number> implements Graph<V, W> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeVertex(V vertex) throws IllegalArgumentException {
|
||||
public void removeVertex(V vertex) throws NullPointerException, IllegalArgumentException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@@ -74,6 +74,12 @@ public class AdjGraph<V, W extends Number> implements Graph<V, W> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> marks() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
|
||||
// TODO Auto-generated method stub
|
||||
@@ -309,5 +315,5 @@ public class AdjGraph<V, W extends Number> implements Graph<V, W> {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -108,6 +108,17 @@ public class MapGraph<V, W extends Number> implements Graph<V, W> {
|
||||
checkNull(vertex);
|
||||
return edges.containsKey(vertex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> marks() {
|
||||
Collection<Object> ret = new HashSet<>();
|
||||
markers.forEach((m, v) -> {
|
||||
if(v.size() > 0)
|
||||
ret.add(m);
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MatrixGraph<V, W extends Number> implements Graph<V, W> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeVertex(V vertex) throws IllegalArgumentException {
|
||||
public void removeVertex(V vertex) throws NullPointerException, IllegalArgumentException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@@ -74,6 +74,12 @@ public class MatrixGraph<V, W extends Number> implements Graph<V, W> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> marks() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
|
||||
// TODO Auto-generated method stub
|
||||
@@ -309,5 +315,5 @@ public class MatrixGraph<V, W extends Number> implements Graph<V, W> {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import berack96.lib.graph.view.edge.EdgeIntListener;
|
||||
import java.awt.BorderLayout;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import berack96.lib.graph.view.edge.EdgeListener;
|
||||
import berack96.lib.graph.view.edge.EdgeView;
|
||||
import berack96.lib.graph.view.vertex.VertexIntListener;
|
||||
import berack96.lib.graph.view.vertex.VertexListener;
|
||||
import berack96.lib.graph.view.vertex.VertexView;
|
||||
import berack96.lib.graph.visit.*;
|
||||
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;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class is the Window that appear for building the graph and playing around with it
|
||||
*
|
||||
@@ -26,22 +23,10 @@ public class GraphWindow<V, W extends Number> extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static void main(String[] args) {
|
||||
GraphPanel<Integer, Integer> panel = new GraphPanel<>(new VertexView<>(), new EdgeView<>(), Integer.class, Integer.class);
|
||||
GraphWindow<Integer, Integer> win = new GraphWindow<>(panel, new VertexIntListener(panel), new EdgeIntListener<>(panel));
|
||||
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); // full screen
|
||||
dim.setSize(dim.width / 2, dim.height / 2);
|
||||
win.setSize(dim);
|
||||
win.setLocationRelativeTo(null); //centered
|
||||
win.visitRefresh(500);
|
||||
|
||||
win.setVisible(true);
|
||||
}
|
||||
|
||||
private final GraphPanel<V, W> graphPanel;
|
||||
private final GraphInfo<V, W> infoPanel;
|
||||
|
||||
private GraphWindow(GraphPanel<V, W> graphPanel, VertexListener<V> vListener, EdgeListener<V, W> eListener) {
|
||||
public GraphWindow(GraphPanel<V, W> graphPanel, VertexListener<V> vListener, EdgeListener<V, W> eListener) {
|
||||
this.setTitle("Grafo");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
25
src/berack96/lib/graph/view/Main.java
Normal file
25
src/berack96/lib/graph/view/Main.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package berack96.lib.graph.view;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
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;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
GraphPanel<Integer, Integer> panel = new GraphPanel<>(new VertexView<>(), new EdgeView<>(), Integer.class, Integer.class);
|
||||
GraphWindow<Integer, Integer> win = new GraphWindow<>(panel, new VertexIntListener(panel), new EdgeIntListener<>(panel));
|
||||
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); // full screen
|
||||
dim.setSize(dim.width / 2, dim.height / 2);
|
||||
win.setSize(dim);
|
||||
win.setLocationRelativeTo(null); //centered
|
||||
win.visitRefresh(500);
|
||||
|
||||
win.setVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user