6 package com.vesoft.nebula.client.graph.data;
8 import com.vesoft.nebula.Tag;
9 import com.vesoft.nebula.Value;
10 import com.vesoft.nebula.Vertex;
11 import java.io.UnsupportedEncodingException;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
16 import java.util.Objects;
19 private final Vertex vertex;
22 List<String> tagNames =
new ArrayList<>();
29 public Node(Vertex vertex)
throws UnsupportedEncodingException {
31 throw new RuntimeException(
"Input an null vertex object");
33 vid =
new ValueWrapper(vertex.vid, getDecodeType(), getTimezoneOffset());
35 for (Tag tag : vertex.tags) {
36 this.tagNames.add(
new String(tag.name, getDecodeType()));
71 return tagNames.contains(tagName);
79 return tagNames.contains(tagName);
87 public List<ValueWrapper>
values(String tagName) {
88 int index = tagNames.indexOf(tagName);
90 throw new IllegalArgumentException(tagName +
" is not found");
92 List<ValueWrapper>
values =
new ArrayList<>();
93 for (Value val : vertex.tags.get(index).props.values()) {
105 public List<String>
keys(String tagName)
throws UnsupportedEncodingException {
106 int index = tagNames.indexOf(tagName);
108 throw new IllegalArgumentException(tagName +
" is not found");
111 List<String>
keys =
new ArrayList<>();
112 for (
byte[] name : vertex.tags.get(index).props.keySet()) {
113 keys.add(
new String(name, getDecodeType()));
124 public HashMap<String, ValueWrapper>
properties(String tagName)
125 throws UnsupportedEncodingException {
126 int index = tagNames.indexOf(tagName);
128 throw new IllegalArgumentException(tagName +
" is not found");
131 HashMap<String, ValueWrapper>
properties =
new HashMap();
132 for (
byte[] name : vertex.tags.get(index).props.keySet()) {
133 properties.put(
new String(name, getDecodeType()),
134 new ValueWrapper(vertex.tags.get(index).props.get(name),
136 getTimezoneOffset()));
142 public boolean equals(Object o) {
146 if (o ==
null || getClass() != o.getClass()) {
150 return Objects.equals(vid, node.vid);
154 public int hashCode() {
155 return Objects.hash(vertex, vid, getDecodeType(), getTimezoneOffset(), tagNames);
159 public String toString() {
161 List<String> tagsStr =
new ArrayList<>();
162 for (String name : tagNames()) {
163 List<String> propStrs =
new ArrayList<>();
164 Map<String, ValueWrapper> props =
properties(name);
165 for (String key : props.keySet()) {
166 propStrs.add(key +
": " + props.get(key).toString());
168 tagsStr.add(String.format(
":%s {%s}", name, String.join(
", ", propStrs)));
170 return String.format(
"(%s %s)",
getId(), String.join(
" ", tagsStr));
171 }
catch (UnsupportedEncodingException e) {
172 return e.getMessage();
List< String > tagNames()
get all tag name from the node
boolean hasLabel(String tagName)
Used to be compatible with older versions of interfaces.
ValueWrapper getId()
get vid from the node
List< ValueWrapper > values(String tagName)
get property values from the node
boolean hasTagName(String tagName)
determine if node contains the given tag
Node(Vertex vertex)
Node is a wrapper around the Vertex type returned by nebula-graph.
List< String > labels()
Used to be compatible with older versions of interfaces.
HashMap< String, ValueWrapper > properties(String tagName)
get property names and values from the node
List< String > keys(String tagName)
get property names from the node