[英]Gremlin get all incoming and outgoing vertex, including their edges and directions
[英]Remove all edges touching a given vertex
因此,我试图删除SimpleGraph(无向图,JGraphT)的所有边缘,但是由于某些原因,我一直在获取ConcurrentModificationException。
这是我想做的事情:
首先,我有一个类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的顶点是Point的实例,并存储在2D数组中
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?
ConCurrentModificationException
表示您正在尝试修改项目,为什么不允许这样做,即在迭代时尝试修改Collection时发生
尝试检查堆栈跟踪以帮助您检测错误,很有可能发生在未附加的代码中。 我认为您在调用removeEdges()
可能会导致一些问题
第二件事,在您的Point.equal()
方法中,您能否解释一下为什么将点投射到单元格?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.