VGalaxies commented on code in PR #2662:
URL:
https://github.com/apache/incubator-hugegraph/pull/2662#discussion_r1756109366
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/EdgeLabel.java:
##########
@@ -78,53 +102,106 @@ public boolean directed() {
}
public String sourceLabelName() {
- return this.graph.vertexLabelOrNone(this.sourceLabel).name();
+ 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());
+ return
this.graph.vertexLabelOrNone(this.links.iterator().next().getLeft()).name();
+ }
+
+ public List<Id> linksIds() {
+ List<Id> ids = new ArrayList<>(this.links.size() * 2);
+ for (Pair<Id, Id> link : this.links) {
+ ids.add(link.getLeft());
+ ids.add(link.getRight());
+ }
+ return ids;
+ }
+
+ public void linksIds(Id[] ids) {
+ this.links = new HashSet<>(ids.length / 2);
+ for (int i = 0; i < ids.length; i += 2) {
+ this.links.add(Pair.of(ids[i], ids[i + 1]));
+ }
}
public Id sourceLabel() {
- return this.sourceLabel;
+ if (links.size() == 1) {
+ return links.iterator().next().getLeft();
+ }
+ return NONE_ID;
}
public void sourceLabel(Id id) {
- E.checkArgument(this.sourceLabel == NONE_ID,
- "Not allowed to set source label multi times " +
- "of edge label '%s'", this.name());
+ E.checkArgument(this.links.isEmpty(),
+ "Not allowed add source label to an edge label which "
+
+ "already has links");
this.sourceLabel = id;
}
public String targetLabelName() {
- return this.graph.vertexLabelOrNone(this.targetLabel).name();
+ 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());
+ return
this.graph.vertexLabelOrNone(this.links.iterator().next().getRight()).name();
}
public Id targetLabel() {
- return this.targetLabel;
+ if (links.size() == 1) {
+ return links.iterator().next().getRight();
+ }
+ return NONE_ID;
}
public void targetLabel(Id id) {
- E.checkArgument(this.targetLabel == NONE_ID,
- "Not allowed to set target label multi times " +
- "of edge label '%s'", this.name());
- this.targetLabel = id;
+ E.checkArgument(this.links.isEmpty(),
+ "Not allowed add source label to an edge label which "
+
+ "already has links");
+ E.checkArgument(this.sourceLabel != NONE_ID,
+ "Not allowed add target label to an edge label which "
+
+ "not has source label yet");
+ this.links.add(Pair.of(this.sourceLabel, id));
+ this.sourceLabel = NONE_ID;
}
public boolean linkWithLabel(Id id) {
- return this.sourceLabel.equals(id) || this.targetLabel.equals(id);
+ for (Pair<Id, Id> link : this.links) {
+ if (link.getLeft().equals(id) || link.getRight().equals(id)) {
+ return true;
+ }
+ }
+ return false;
}
public boolean linkWithVertexLabel(Id label, Directions dir) {
- if (dir.equals(Directions.IN)) {
- return this.targetLabel.equals(label);
- } else if (dir.equals(Directions.OUT)) {
- return this.sourceLabel.equals(label);
- } else if (dir.equals(Directions.BOTH)) {
- return this.targetLabel.equals(label) ||
this.sourceLabel.equals(label);
- }
- return false;
+ return this.links.stream().anyMatch(pair -> {
+ Id sourceLabel = pair.getLeft();
+ Id targetLabel = pair.getRight();
+ if (dir.equals(Directions.IN)) {
+ return targetLabel.equals(label);
+ } else if (dir.equals(Directions.OUT)) {
+ return sourceLabel.equals(label);
+ } else if (dir.equals(Directions.BOTH)) {
+ return targetLabel.equals(label) || sourceLabel.equals(label);
+ }
+ return false;
+ });
Review Comment:
mark, see #2408
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]