Skip to content

Commit

Permalink
not delay link of soruce label and target label to avoid null links
Browse files Browse the repository at this point in the history
  • Loading branch information
Thespica committed Oct 2, 2024
1 parent cd26708 commit 5b8570f
Showing 1 changed file with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class EdgeLabel extends SchemaLabel {
public EdgeLabel(@JsonProperty("name") String name) {
super(name);
this.frequency = Frequency.DEFAULT;
this.links = new HashSet<>();
this.sortKeys = new CopyOnWriteArrayList<>();
this.ttl = 0L;
this.ttlStartTime = null;
Expand Down Expand Up @@ -112,7 +113,7 @@ public Set<Map<String, String>> links() {
}

public boolean linkedVertexLabel(String vertexLabel) {
if (this.edgeLabelType.parent() || this.links == null) {
if (this.edgeLabelType.parent() || this.links == null || this.links.isEmpty()) {
return false;
}

Expand Down Expand Up @@ -214,7 +215,6 @@ public EdgeLabel build() {

@Override
public EdgeLabel create() {
this.checkThenLinkSourceAndTarget();
return this.manager.addEdgeLabel(this.edgeLabel);
}

Expand Down Expand Up @@ -259,11 +259,6 @@ public Builder nullableKeys(String... keys) {

@Override
public Builder link(String sourceLabel, String targetLabel) {
if (this.edgeLabel.links == null) {
this.edgeLabel.links = new HashSet<>();
this.sourceLabel = sourceLabel;
this.targetLabel = targetLabel;
}
HashMap<String, String> map = new HashMap<>();
map.put(sourceLabel, targetLabel);
this.edgeLabel.links.add(map);
Expand Down Expand Up @@ -292,8 +287,7 @@ public Builder asGeneral() {

@Override
public Builder sourceLabel(String label) {
E.checkArgument(this.edgeLabel.links == null ||
this.edgeLabel.links.isEmpty(),
E.checkArgument(this.edgeLabel.links.isEmpty(),
"Not allowed add source label to an edge label which " +
"already has links");
this.sourceLabel = label;
Expand All @@ -302,14 +296,14 @@ public Builder sourceLabel(String label) {

@Override
public Builder targetLabel(String label) {
E.checkArgument(this.edgeLabel.links == null ||
this.edgeLabel.links.isEmpty(),
E.checkArgument(this.edgeLabel.links.isEmpty(),
"Not allowed add source label to an edge label which " +
"already has links");
E.checkArgument(this.sourceLabel != null,
"Not allowed add target label to an edge label which " +
"not has source label yet");
this.targetLabel = label;
link(this.sourceLabel, this.targetLabel);
return this;
}

Expand Down Expand Up @@ -372,14 +366,6 @@ private void checkFrequency() {
"Not allowed to change frequency for " +
"edge label '%s'", this.edgeLabel.name);
}

private void checkThenLinkSourceAndTarget() {
E.checkArgument((this.sourceLabel != null && this.targetLabel != null) ||
(this.sourceLabel == null && this.targetLabel == null),
"Not allowed to add edge label with only one " +
"source/target label");
this.link(this.sourceLabel, this.targetLabel);
}
}

public static class EdgeLabelV53 extends SchemaLabel {
Expand Down

0 comments on commit 5b8570f

Please sign in to comment.