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