所以我试图删除 SimpleGraph(无向图,JGraphT)的所有边,但由于某种原因,我不断收到 ConcurrentModificationException。
这是我正在尝试做的事情:
首先,我有一个类点如下:
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,其顶点是 Point 的实例并存储在二维数组中
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?