Hi so i am using thee following code :
public Graph graph ;
private HashMap<String, Node> nodes ;
private HashMap<Node, Double> inDegree = new HashMap<Node, Double>();
private HashMap<Node, Double> outDegree = new HashMap<Node, Double>();
private GraphTraversalSource g ;
public TinkerTopGraph(Graph graph) {
this.graph = graph;
this.nodes = new HashMap<String, Node>();
graph = TinkerGraph.open();
g = traversal().withEmbedded(graph);
}
public void addEdge(Node sourceNode, Node destinationNode){
}
}
Inside the function "addEdge" i tried making this :
g.V().hasLabel(sourceNode.toString()).tryNext().orElse(g.addV().next());
g.V().hasLabel(destinationNode.toString()).tryNext().orElse(g.addV(destinationNode.toString()).next());
The problem is that when there is already a vertex inside the GraphTraversalSource with the same string with one of the nodes it doesnt detect it . I tried different technics that i found here .For example i have also tried :
g.V().has(sourceNode.toString()).tryNext().orElse(g.addV().next());
g.V().has(destinationNode.toString()).tryNext().orElse(g.addV(destinationNode.toString()).next());
which i think is the same with the above one since i use only labels.I also tried this :
g.V().has(sourceNode.toString()).fold().coalesce(unfold(),addV(sourceNode.toString()))
g.V().has(destinationNode.toString()).fold().coalesce(unfold(),addV(destinationNode.toString()))
but the problem with this one is it throws a warning and doesnt add any vertices at all. I also tired using :
g.V().has(node.toString).tryNext().orElseGet{
g.addV(node.toString()).next()}
but in this case the command orElseGet{} doesnt work and asks for a supplier type inside it.How can i change a vertex type command into a supplier one?
What can i do in order to check if a vertice with a label already exists and then if it doesnt , to add it?