I need to sort nodes based on degree that are created by my program on the fly.
I tried to use Collections.sort() but it throws a null pointer exception. The nodeList parameter is list of nodes created by my program. I tried few different configurations, but it did not worked.
private void sortNodes(List<Node> nodeList){
Collections.sort(nodeList, new GraphModel());
}
public int compare(Node n1, Node n2) {
int n1Degree,n2Degree;
try ( Transaction tx = graphDb.beginTx() ) {
n1Degree = n1.getDegree();
n2Degree = n2.getDegree();
tx.success();
}
if(n1Degree<n2Degree){
return -1;
}
else if(n1Degree==n2Degree){
return 0;
}
else{
return 1;
}
}
Aucun commentaire:
Enregistrer un commentaire