yangxk1 commented on code in PR #743:
URL: https://github.com/apache/incubator-graphar/pull/743#discussion_r2323948116
##########
maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java:
##########
@@ -20,9 +20,7 @@
package org.apache.graphar.info;
import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
Review Comment:
Import specific classes, rather than using *.
##########
maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java:
##########
@@ -51,6 +49,174 @@ public class EdgeInfo {
private final PropertyGroups propertyGroups;
private final VersionInfo version;
+ public static final class EdgeInfoBuilder {
+ private EdgeTriplet edgeTriplet;
+ private long chunkSize;
+ private long srcChunkSize;
+ private long dstChunkSize;
+ private boolean directed;
+ private String prefix;
+ private Map<AdjListType, AdjacentList> adjacentLists;
+ private PropertyGroups propertyGroups;
+ private VersionInfo version;
+
+ private List<AdjacentList> adjacentListsAsListTemp;
+ private List<PropertyGroup> propertyGroupsAsListTemp;
+
+ private String srcType;
+ private String edgeType;
+ private String dstType;
+
+ public static EdgeInfoBuilder builder() {
Review Comment:
move the `builder()` method to `EdgeInfo` class
##########
maven-projects/info/src/test/java/org/apache/graphar/info/TestUtil.java:
##########
@@ -111,19 +111,19 @@ public static GraphInfo getLdbcSampleDataSet() {
new AdjacentList(AdjListType.ordered_by_dest, FileType.CSV,
"ordered_by_dest/");
Property creationDate = new Property("creationDate", DataType.STRING,
false, false);
PropertyGroup pg3 = new PropertyGroup(List.of(creationDate),
FileType.CSV, "creationDate/");
+
EdgeInfo knows =
- new EdgeInfo(
- "person",
- "knows",
- "person",
- 1024,
- 100,
- 100,
- false,
- "edge/person_knows_person/",
- "gar/v1",
- List.of(orderedBySource, orderedByDest),
- List.of(pg3));
+ EdgeInfo.EdgeInfoBuilder.builder()
Review Comment:
add some cases for verification failed
##########
maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java:
##########
@@ -51,6 +49,174 @@ public class EdgeInfo {
private final PropertyGroups propertyGroups;
private final VersionInfo version;
+ public static final class EdgeInfoBuilder {
+ private EdgeTriplet edgeTriplet;
+ private long chunkSize;
+ private long srcChunkSize;
+ private long dstChunkSize;
+ private boolean directed;
+ private String prefix;
+ private Map<AdjListType, AdjacentList> adjacentLists;
+ private PropertyGroups propertyGroups;
+ private VersionInfo version;
+
+ private List<AdjacentList> adjacentListsAsListTemp;
+ private List<PropertyGroup> propertyGroupsAsListTemp;
+
+ private String srcType;
+ private String edgeType;
+ private String dstType;
+
+ public static EdgeInfoBuilder builder() {
+ return new EdgeInfoBuilder();
+ }
+
+ private EdgeInfoBuilder() {}
+
+
+ public EdgeInfoBuilder srcType(String srcType) {
+ this.srcType = srcType;
+ return this;
+ }
+
+ public EdgeInfoBuilder edgeType(String edgeType) {
+ this.edgeType = edgeType;
+ return this;
+ }
+ public EdgeInfoBuilder dstType(String dstType) {
+ this.dstType = dstType;
+ return this;
+ }
+
+ public EdgeInfoBuilder edgeTriplet(String srcType, String edgeType,
String dstType) {
+ this.edgeTriplet = new EdgeTriplet(srcType, edgeType, dstType);
+ return this;
+ }
+
+
+ private EdgeInfoBuilder edgeTriplet(EdgeTriplet edgeTriplet) {
+ this.edgeTriplet = edgeTriplet;
+ return this;
+ }
+
+ public EdgeInfoBuilder chunkSize(long chunkSize) {
+ this.chunkSize = chunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder srcChunkSize(long srcChunkSize) {
+ this.srcChunkSize = srcChunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder dstChunkSize(long dstChunkSize) {
+ this.dstChunkSize = dstChunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder directed(boolean directed) {
+ this.directed = directed;
+ return this;
+ }
+
+ public EdgeInfoBuilder prefix(String prefix) {
+ this.prefix = prefix;
+ return this;
+ }
+
+ public EdgeInfoBuilder addAdjacentList(AdjacentList adjacentList) {
+ if(adjacentListsAsListTemp == null)
+ adjacentListsAsListTemp = new ArrayList<>();
+ adjacentListsAsListTemp.add(adjacentList);
+ return this;
+ }
+
+ public EdgeInfoBuilder adjacentLists(List<AdjacentList>
adjacentListsAsList) {
+ if(adjacentListsAsListTemp == null)
+ adjacentListsAsListTemp = new ArrayList<>();
+ this.adjacentListsAsListTemp.addAll(adjacentListsAsList);
+ return this;
+ }
+
+ private EdgeInfoBuilder adjacentLists(Map<AdjListType, AdjacentList>
adjacentLists) {
+ this.adjacentLists = adjacentLists;
+ return this;
+ }
+
+ public EdgeInfoBuilder addPropertyGroups(PropertyGroup propertyGroup) {
+ if(propertyGroupsAsListTemp == null)
+ propertyGroupsAsListTemp = new ArrayList<>();
+ propertyGroupsAsListTemp.add(propertyGroup);
+ return this;
+ }
+
+ public EdgeInfoBuilder propertyGroups(List<PropertyGroup>
propertyGroups) {
Review Comment:
rename to `addPropertyGroups` may be better
##########
maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java:
##########
@@ -51,6 +49,174 @@ public class EdgeInfo {
private final PropertyGroups propertyGroups;
private final VersionInfo version;
+ public static final class EdgeInfoBuilder {
+ private EdgeTriplet edgeTriplet;
+ private long chunkSize;
+ private long srcChunkSize;
+ private long dstChunkSize;
+ private boolean directed;
+ private String prefix;
+ private Map<AdjListType, AdjacentList> adjacentLists;
+ private PropertyGroups propertyGroups;
+ private VersionInfo version;
+
+ private List<AdjacentList> adjacentListsAsListTemp;
+ private List<PropertyGroup> propertyGroupsAsListTemp;
+
+ private String srcType;
+ private String edgeType;
+ private String dstType;
+
+ public static EdgeInfoBuilder builder() {
+ return new EdgeInfoBuilder();
+ }
+
+ private EdgeInfoBuilder() {}
+
+
+ public EdgeInfoBuilder srcType(String srcType) {
+ this.srcType = srcType;
+ return this;
+ }
+
+ public EdgeInfoBuilder edgeType(String edgeType) {
+ this.edgeType = edgeType;
+ return this;
+ }
+ public EdgeInfoBuilder dstType(String dstType) {
+ this.dstType = dstType;
+ return this;
+ }
+
+ public EdgeInfoBuilder edgeTriplet(String srcType, String edgeType,
String dstType) {
+ this.edgeTriplet = new EdgeTriplet(srcType, edgeType, dstType);
+ return this;
+ }
+
+
+ private EdgeInfoBuilder edgeTriplet(EdgeTriplet edgeTriplet) {
+ this.edgeTriplet = edgeTriplet;
+ return this;
+ }
+
+ public EdgeInfoBuilder chunkSize(long chunkSize) {
+ this.chunkSize = chunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder srcChunkSize(long srcChunkSize) {
+ this.srcChunkSize = srcChunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder dstChunkSize(long dstChunkSize) {
+ this.dstChunkSize = dstChunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder directed(boolean directed) {
+ this.directed = directed;
+ return this;
+ }
+
+ public EdgeInfoBuilder prefix(String prefix) {
+ this.prefix = prefix;
+ return this;
+ }
+
+ public EdgeInfoBuilder addAdjacentList(AdjacentList adjacentList) {
+ if(adjacentListsAsListTemp == null)
Review Comment:
pls do not omit `{}`
##########
maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java:
##########
@@ -51,6 +49,174 @@ public class EdgeInfo {
private final PropertyGroups propertyGroups;
private final VersionInfo version;
+ public static final class EdgeInfoBuilder {
+ private EdgeTriplet edgeTriplet;
+ private long chunkSize;
+ private long srcChunkSize;
+ private long dstChunkSize;
+ private boolean directed;
+ private String prefix;
+ private Map<AdjListType, AdjacentList> adjacentLists;
+ private PropertyGroups propertyGroups;
+ private VersionInfo version;
+
+ private List<AdjacentList> adjacentListsAsListTemp;
+ private List<PropertyGroup> propertyGroupsAsListTemp;
+
+ private String srcType;
+ private String edgeType;
+ private String dstType;
+
+ public static EdgeInfoBuilder builder() {
+ return new EdgeInfoBuilder();
+ }
+
+ private EdgeInfoBuilder() {}
+
+
+ public EdgeInfoBuilder srcType(String srcType) {
+ this.srcType = srcType;
+ return this;
+ }
+
+ public EdgeInfoBuilder edgeType(String edgeType) {
+ this.edgeType = edgeType;
+ return this;
+ }
+ public EdgeInfoBuilder dstType(String dstType) {
+ this.dstType = dstType;
+ return this;
+ }
+
+ public EdgeInfoBuilder edgeTriplet(String srcType, String edgeType,
String dstType) {
+ this.edgeTriplet = new EdgeTriplet(srcType, edgeType, dstType);
+ return this;
+ }
+
+
+ private EdgeInfoBuilder edgeTriplet(EdgeTriplet edgeTriplet) {
+ this.edgeTriplet = edgeTriplet;
+ return this;
+ }
+
+ public EdgeInfoBuilder chunkSize(long chunkSize) {
+ this.chunkSize = chunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder srcChunkSize(long srcChunkSize) {
+ this.srcChunkSize = srcChunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder dstChunkSize(long dstChunkSize) {
+ this.dstChunkSize = dstChunkSize;
+ return this;
+ }
+
+ public EdgeInfoBuilder directed(boolean directed) {
+ this.directed = directed;
+ return this;
+ }
+
+ public EdgeInfoBuilder prefix(String prefix) {
+ this.prefix = prefix;
+ return this;
+ }
+
+ public EdgeInfoBuilder addAdjacentList(AdjacentList adjacentList) {
+ if(adjacentListsAsListTemp == null)
+ adjacentListsAsListTemp = new ArrayList<>();
+ adjacentListsAsListTemp.add(adjacentList);
+ return this;
+ }
+
+ public EdgeInfoBuilder adjacentLists(List<AdjacentList>
adjacentListsAsList) {
+ if(adjacentListsAsListTemp == null)
+ adjacentListsAsListTemp = new ArrayList<>();
+ this.adjacentListsAsListTemp.addAll(adjacentListsAsList);
+ return this;
+ }
+
+ private EdgeInfoBuilder adjacentLists(Map<AdjListType, AdjacentList>
adjacentLists) {
+ this.adjacentLists = adjacentLists;
+ return this;
+ }
+
+ public EdgeInfoBuilder addPropertyGroups(PropertyGroup propertyGroup) {
+ if(propertyGroupsAsListTemp == null)
+ propertyGroupsAsListTemp = new ArrayList<>();
+ propertyGroupsAsListTemp.add(propertyGroup);
+ return this;
+ }
+
+ public EdgeInfoBuilder propertyGroups(List<PropertyGroup>
propertyGroups) {
+ if(propertyGroupsAsListTemp == null)
+ propertyGroupsAsListTemp = new ArrayList<>();
+ propertyGroupsAsListTemp.addAll(propertyGroups);
+ return this;
+ }
+
+ private EdgeInfoBuilder propertyGroups(PropertyGroups propertyGroups) {
+ this.propertyGroups = propertyGroups;
+ return this;
+ }
+
+ public EdgeInfoBuilder version(String version) {
+ this.version = VersionParser.getVersion(version);
+ return this;
+ }
+
+ public EdgeInfoBuilder version(VersionInfo version) {
+ this.version = version;
+ return this;
+ }
+
+ public EdgeInfo build() {
+ if(adjacentLists == null)
+ adjacentLists = new HashMap<>();
+
+ if(adjacentListsAsListTemp != null)
+ adjacentLists.putAll(
+ adjacentListsAsListTemp.stream()
+ .collect(
+ Collectors.toUnmodifiableMap(
+ AdjacentList::getType,
Function.identity())));
+
+ if(propertyGroups == null)
+ propertyGroups = new PropertyGroups(propertyGroupsAsListTemp);
+ else {
+ if(propertyGroupsAsListTemp != null)
+ propertyGroups = propertyGroupsAsListTemp.stream()
+ .map(propertyGroups::addPropertyGroupAsNew)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .reduce((first, second) -> second)
+ .orElse(new PropertyGroups(new ArrayList<>()));
+ else
+ propertyGroups = new PropertyGroups(new ArrayList<>());
+ }
+
+ if(edgeTriplet == null && srcType != null && edgeType != null &&
dstType != null)
+ edgeTriplet = new EdgeTriplet(srcType, edgeType, dstType);
Review Comment:
we should add some verification, e.g., throw exception when `edgeTriplet ==
null && srcType == null`
--
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]