From bb9700832a926cc4981bc38157826f271d7c39ae Mon Sep 17 00:00:00 2001 From: Thespica Date: Thu, 17 Oct 2024 10:44:45 +0800 Subject: [PATCH] add source_label and target_label fields, modify toString method --- .../hugegraph/structure/schema/EdgeLabel.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java index b2746ada0..f949decdb 100644 --- a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java @@ -17,14 +17,8 @@ package org.apache.hugegraph.structure.schema; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; - +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.hugegraph.driver.SchemaManager; import org.apache.hugegraph.structure.constant.EdgeLabelType; import org.apache.hugegraph.structure.constant.Frequency; @@ -32,8 +26,13 @@ import org.apache.hugegraph.util.CollectionUtil; import org.apache.hugegraph.util.E; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; public class EdgeLabel extends SchemaLabel { @@ -43,6 +42,10 @@ public class EdgeLabel extends SchemaLabel { private String parentLabel; @JsonProperty("frequency") private Frequency frequency; + @JsonProperty("source_label") + private String sourceLabel; + @JsonProperty("target_label") + private String targetLabel; @JsonProperty("links") private Set> links; @JsonProperty("sort_keys") @@ -89,16 +92,16 @@ public Frequency frequency() { public String sourceLabel() { E.checkState(this.links.size() == 1, - "Only edge label has single vertex label pair can call " + - "sourceLabelName(), but current edge label got %s", - this.links.size()); + "Only edge label has single vertex label pair can call " + + "sourceLabelName(), but current edge label got %s", + this.links.size()); return this.links.iterator().next().keySet().iterator().next(); } public String targetLabel() { E.checkState(this.links.size() == 1, - "Only edge label has single vertex label pair can call " + - "targetLabelName(), but current edge label got %s", this.links.size()); + "Only edge label has single vertex label pair can call " + + "targetLabelName(), but current edge label got %s", this.links.size()); return this.links.iterator().next().values().iterator().next(); } @@ -136,11 +139,12 @@ public String ttlStartTime() { @Override public String toString() { - return String.format("{name=%s, " + "edgeLabel_type=%s, " + "parent_label=%s" + - "links=%s, sortKeys=%s, indexLabels=%s, " + - "nullableKeys=%s, properties=%s, ttl=%s, " + - "ttlStartTime=%s, status=%s}", - this.name, + return String.format("{name=%s, sourceLabel=%s, targetLabel=%s, " + "edgeLabel_type=%s, " + "parent_label=%s" + + "links=%s, sortKeys=%s, indexLabels=%s, " + + "nullableKeys=%s, properties=%s, ttl=%s, " + + "ttlStartTime=%s, status=%s}", + // TODO(@Thespica): call field or call method? + this.name, this.sourceLabel(), this.targetLabel(), this.edgeLabelType, this.parentLabel, this.links, this.sortKeys, this.indexLabels, this.nullableKeys, this.properties, this.ttl, @@ -313,7 +317,7 @@ public Builder sourceLabel(String label) { @Override public Builder targetLabel(String label) { E.checkArgument(this.edgeLabel.links.isEmpty(), - "Not allowed add source label to an edge label " + + "Not allowed add source label to an edge label " + "which already has links"); if (this.sourceLabel != null) { link(this.sourceLabel, label); @@ -380,8 +384,8 @@ public Builder ifNotExist() { private void checkFrequency() { E.checkArgument(this.edgeLabel.frequency == Frequency.DEFAULT, - "Not allowed to change frequency for edge label '%s'", - this.edgeLabel.name); + "Not allowed to change frequency for edge label '%s'", + this.edgeLabel.name); } } @@ -436,10 +440,10 @@ public String targetLabel() { @Override public String toString() { return String.format("{name=%s, sourceLabel=%s, targetLabel=%s, " + - "sortKeys=%s, nullableKeys=%s, properties=%s}", - this.name, this.sourceLabel, this.targetLabel, - this.sortKeys, this.nullableKeys, - this.properties); + "sortKeys=%s, nullableKeys=%s, properties=%s}", + this.name, this.sourceLabel, this.targetLabel, + this.sortKeys, this.nullableKeys, + this.properties); } @Override