Skip to content

Commit

Permalink
add source_label and target_label fields, modify toString method
Browse files Browse the repository at this point in the history
  • Loading branch information
Thespica committed Oct 17, 2024
1 parent 6156dee commit bb97008
Showing 1 changed file with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@

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;
import org.apache.hugegraph.structure.constant.HugeType;
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 {

Expand All @@ -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<Map<String, String>> links;
@JsonProperty("sort_keys")
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb97008

Please sign in to comment.