* after loading a window the vertices can be doubled
* fixed acient bug where the number will keep increase
This commit is contained in:
2019-06-14 22:04:48 +02:00
parent 1a06692f02
commit a8596331e7
2 changed files with 15 additions and 8 deletions

View File

@@ -19,10 +19,11 @@ public class VertexComponent<V> extends Component {
return "[" + vertex + " {" + getX() + "," + getY() + "}]"; return "[" + vertex + " {" + getX() + "," + getY() + "}]";
} }
@Override @SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
try { try {
return obj.getClass().equals(getClass()) && obj.toString().equals(toString()); return obj.getClass().equals(getClass()) && ((VertexComponent<V>)obj).vertex.equals(vertex);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }

View File

@@ -1,12 +1,12 @@
package berack96.sim.util.graph.view.vertex; package berack96.sim.util.graph.view.vertex;
import java.util.Arrays;
import berack96.sim.util.graph.Graph; import berack96.sim.util.graph.Graph;
import berack96.sim.util.graph.view.GraphPanel; import berack96.sim.util.graph.view.GraphPanel;
public class VertexIntListener extends VertexListener<Integer> { public class VertexIntListener extends VertexListener<Integer> {
private Integer counter = 0;
public VertexIntListener(GraphPanel<Integer, ?> panel) { public VertexIntListener(GraphPanel<Integer, ?> panel) {
super(panel); super(panel);
} }
@@ -16,9 +16,15 @@ public class VertexIntListener extends VertexListener<Integer> {
@Override @Override
protected Integer buildNewVertex(Graph<Integer, ?> graph) { protected Integer buildNewVertex(Graph<Integer, ?> graph) {
if(graph.numberOfVertices() == 0) int counter = 0;
counter = 0; Integer[] vertices = graph.vertices().toArray(new Integer[graph.numberOfVertices()]);
counter++; Arrays.sort(vertices);
return counter - 1;
for(int i = 0; i<vertices.length; i++) {
if(!vertices[i].equals(counter))
return counter;
counter++;
}
return counter;
} }
} }