6 package com.vesoft.nebula.client.graph.data;
8 import com.vesoft.nebula.Edge;
9 import com.vesoft.nebula.Path;
10 import com.vesoft.nebula.Step;
11 import com.vesoft.nebula.Value;
12 import com.vesoft.nebula.client.graph.exception.InvalidValueException;
13 import java.io.UnsupportedEncodingException;
14 import java.util.ArrayList;
15 import java.util.List;
17 import java.util.Objects;
20 private List<Segment> segments =
new ArrayList<>();
21 private List<Node> nodes =
new ArrayList<>();
22 private List<Relationship> relationships =
new ArrayList<>();
23 private Path path =
null;
25 public static class Segment {
40 this.startNode = startNode;
41 this.relationShip = relationShip;
42 this.endNode = endNode;
67 public boolean equals(Object o) {
71 if (o ==
null || getClass() != o.getClass()) {
74 Segment segment = (Segment) o;
75 return Objects.equals(startNode, segment.startNode)
76 && Objects.equals(relationShip, segment.relationShip)
77 && Objects.equals(endNode, segment.endNode);
81 public int hashCode() {
82 return Objects.hash(startNode, relationShip, endNode);
86 public String toString() {
88 +
"startNode=" + startNode
89 +
", relationShip=" + relationShip
90 +
", endNode=" + endNode
100 if (nodes ==
null || nodes.isEmpty()) {
111 if (nodes ==
null || nodes.isEmpty()) {
114 return nodes.get(nodes.size() - 1);
123 return nodes.contains(node);
132 return relationships.contains(relationship);
148 return relationships;
164 return segments.size();
175 this.nodes =
new ArrayList<>();
176 this.relationships =
new ArrayList<>();
177 this.segments =
new ArrayList<>();
182 .setDecodeType(getDecodeType())
183 .setTimezoneOffset(getTimezoneOffset()));
184 List<Value> vids =
new ArrayList<>();
185 vids.add(path.src.vid);
188 for (Step step : path.steps) {
191 int type = step.type;
193 startNode = nodes.get(nodes.size() - 1);
195 .setDecodeType(getDecodeType())
196 .setTimezoneOffset(getTimezoneOffset());
198 srcId = vids.get(vids.size() - 1);
199 dstId = step.dst.vid;
202 startNode = (
Node)
new Node(step.dst)
203 .setDecodeType(getDecodeType())
204 .setTimezoneOffset(getTimezoneOffset());
205 endNode = nodes.get(nodes.size() - 1);
206 nodes.add(startNode);
207 dstId = vids.get(vids.size() - 1);
208 srcId = step.dst.vid;
210 vids.add(step.dst.vid);
211 Edge edge =
new Edge(srcId,
218 .setDecodeType(getDecodeType())
219 .setTimezoneOffset(getTimezoneOffset());
220 relationships.add(relationShip);
221 Segment segment =
new Segment(startNode, relationShip, endNode);
222 if (segment.getStartNode() != nodes.get(nodes.size() - 1)
223 && segment.getEndNode() != nodes.get(nodes.size() - 1)) {
225 String.format(
"Relationship [%s] does not connect to the last node",
226 relationShip.toString()));
228 segments.add(segment);
233 public String toString() {
235 List<String> edgeStrs =
new ArrayList<>();
236 for (
int i = 0; i < relationships.size(); i++) {
238 List<String> propStrs =
new ArrayList<>();
239 Map<String, ValueWrapper> props = relationship.
properties();
240 for (String key : props.keySet()) {
241 propStrs.add(key +
": " + props.get(key).toString());
243 Step step = path.steps.get(i);
244 Node node = (Node)
new Node(step.dst)
245 .setDecodeType(getDecodeType())
246 .setTimezoneOffset(getTimezoneOffset());
248 edgeStrs.add(String.format(
"-[:%s@%d{%s}]->%s",
251 String.join(
", ", propStrs),
254 edgeStrs.add(String.format(
"<-[:%s@%d{%s}]-%s",
257 String.join(
", ", propStrs),
261 return String.format(
"%s%s",
263 }
catch (UnsupportedEncodingException e) {
264 return e.getMessage();
269 public boolean equals(Object o) {
273 if (o ==
null || getClass() != o.getClass()) {
277 return Objects.equals(segments, segments1.segments)
278 && Objects.equals(nodes, segments1.nodes)
279 && Objects.equals(relationships, segments1.relationships);
283 public int hashCode() {
284 return Objects.hash(segments, nodes, relationships);
List< Relationship > getRelationships()
get all relationship from the path
List< Node > getNodes()
get all nodes from the path
List< Segment > getSegments()
get all segments from the path
int length()
get the length of the path
Node getEndNode()
get the end node from the path
PathWrapper(Path path)
PathWrapper is a wrapper around the Path type returned by nebula-graph.
boolean containRelationship(Relationship relationship)
determine if path contains the given relationShip
Node getStartNode()
get the start node from the path
boolean containNode(Node node)
determine if path contains the given node
long ranking()
get ranking from the relationship
HashMap< String, ValueWrapper > properties()
get property names and values from the relationship
String edgeName()
get edge name from the relationship