diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java index 34db91d4b..befc7cf83 100644 --- a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java @@ -25,8 +25,8 @@ public enum EdgeLabelType { SUB(2, "SUB"); - private byte code = 0; - private String name = null; + private final byte code; + private final String name; EdgeLabelType(int code, String name) { assert code < 256; 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..1ef60037d 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 @@ -43,6 +43,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") @@ -56,6 +60,8 @@ public class EdgeLabel extends SchemaLabel { public EdgeLabel(@JsonProperty("name") String name) { super(name); this.frequency = Frequency.DEFAULT; + this.sourceLabel = null; + this.targetLabel = null; this.links = new HashSet<>(); this.sortKeys = new CopyOnWriteArrayList<>(); this.ttl = 0L; @@ -108,7 +114,7 @@ public Set> links() { public boolean linkedVertexLabel(String vertexLabel) { if (this.edgeLabelType.parent() || this.links == null || - this.links.isEmpty()) { + this.links.isEmpty()) { return false; } @@ -136,15 +142,14 @@ 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, - this.edgeLabelType, this.parentLabel, - this.links, this.sortKeys, this.indexLabels, - this.nullableKeys, this.properties, this.ttl, - this.ttlStartTime, this.status); + 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}", + this.name, this.sourceLabel(), this.targetLabel(), + this.edgeLabelType, this.parentLabel, + this.links, this.sortKeys, this.indexLabels, + this.nullableKeys, this.properties, this.ttl, + this.ttlStartTime, this.status); } public EdgeLabelV53 switchV53() { @@ -167,18 +172,12 @@ public interface Builder extends SchemaBuilder { /** * Set the source label of the edge label - * - * @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair */ - @Deprecated Builder sourceLabel(String label); /** * Set the target label of the edge label - * - * @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair */ - @Deprecated Builder targetLabel(String label); Builder frequency(Frequency frequency); @@ -202,13 +201,9 @@ public static class BuilderImpl implements Builder { private final EdgeLabel edgeLabel; private final SchemaManager manager; - private String sourceLabel; - private String targetLabel; public BuilderImpl(String name, SchemaManager manager) { this.edgeLabel = new EdgeLabel(name); - this.sourceLabel = null; - this.targetLabel = null; this.manager = manager; } @@ -246,10 +241,10 @@ public Builder properties(String... properties) { @Override public Builder sortKeys(String... keys) { E.checkArgument(this.edgeLabel.sortKeys.isEmpty(), - "Not allowed to assign sort keys multi times"); + "Not allowed to assign sort keys multi times"); List sortKeys = Arrays.asList(keys); E.checkArgument(CollectionUtil.allUnique(sortKeys), - "Invalid sort keys %s, which contains some " + + "Invalid sort keys %s, which contains some " + "duplicate properties", sortKeys); this.edgeLabel.sortKeys.addAll(sortKeys); return this; @@ -266,8 +261,6 @@ public Builder link(String sourceLabel, String targetLabel) { HashMap map = new HashMap<>(); map.put(sourceLabel, targetLabel); this.edgeLabel.links.add(map); - this.sourceLabel = null; - this.targetLabel = null; return this; } @@ -286,40 +279,34 @@ public Builder withBase(String parentLabel) { /** * Set the source label of the edge label - * - * @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair */ - @Deprecated @Override public Builder sourceLabel(String label) { E.checkArgument(this.edgeLabel.links.isEmpty(), - "Not allowed add source label to an edge label which " + + "Not allowed add source label to an edge label which " + "already has links"); - if (this.targetLabel != null) { - link(label, this.targetLabel); - this.targetLabel = null; + if (this.edgeLabel.targetLabel != null) { + link(label, this.edgeLabel.targetLabel); + this.edgeLabel.targetLabel = null; } else { - this.sourceLabel = label; + this.edgeLabel.sourceLabel = label; } return this; } /** * Set the target label of the edge label - * - * @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair */ - @Deprecated @Override public Builder targetLabel(String label) { E.checkArgument(this.edgeLabel.links.isEmpty(), "Not allowed add source label to an edge label " + "which already has links"); - if (this.sourceLabel != null) { - link(this.sourceLabel, label); - this.sourceLabel = null; + if (this.edgeLabel.sourceLabel != null) { + link(this.edgeLabel.sourceLabel, label); + this.edgeLabel.sourceLabel = null; } else { - this.targetLabel = label; + this.edgeLabel.targetLabel = label; } return this; }