0
所以我试图删除SimpleGraph(无向图,JGraphT)的所有边缘,但由于某些原因我不断收到ConcurrentModificationException。删除接触给定顶点的所有边缘
这里就是我想要做的事:
首先,我作为fowllowed一类Point:
class Point
{
private int x;
private int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
//getters and setters
public boolean equals (Object rhs)
{
if (rhs == null || !(rhs instanceof Point))
return false;
else
{
Point rhsPoint = (Point) rhs;
return rhsPoint.x == this.x && rhsPoint.y == this.y;
}
}
public int hashCode()
{
int hash = 3;
hash = 83 * hash + (int) (this.col^(this.col >>> 32));
hash = 83 * hash + (int) (this.row^(this.row >>> 32));
return hash;
}
}
而且其顶点是点的实例,并存储在一个二维图G array
Point[][] pointContainer = new Point[100][100];
SimpleGraph<Point, DefaultEdge.class> g = new SimpleGraph<Point, DefaultEdge.class>();
public void initGraph()
{
for (int row = 0; row < 100; ++row)
for (int col = 0; col < 100; ++col)
{
Point p = new Point(col, row);
pointContainer[row][col] = p;
g.addVertex(p);
}
//Then I added edges between any adjacent vertices
//so except for those vertices near the edges of the grid, each vertex has 8 edges
}
public void removeEdges(int row, int col)
{
Set edges = g.edgesOf(pointContainer[row][col]);
g.removeAllEdges(edges);
}
谁能告诉我我在这里做错了什么?为什么我不断收到ConCurrentModificationException?
对不起,这是一个错字。我打算把rhs投给Point。 – 0x56794E