yangxk1 commented on code in PR #764:
URL: https://github.com/apache/incubator-graphar/pull/764#discussion_r2425128599
##########
maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java:
##########
@@ -37,6 +38,102 @@ public class VertexInfo {
private final URI baseUri;
private final VersionInfo version;
+ public static VertexInfoBuilder builder() {
+ return new VertexInfoBuilder();
+ }
+
+ public static class VertexInfoBuilder {
+ private String type;
+ private long chunkSize;
+ private PropertyGroups propertyGroups;
+ private URI baseUri;
+ private VersionInfo version;
+ private List<PropertyGroup> propertyGroupsAsListTemp;
+
+ private VertexInfoBuilder() {}
+
+ public VertexInfoBuilder type(String type) {
+ this.type = type;
+ return this;
+ }
+
+ public VertexInfoBuilder chunkSize(long chunkSize) {
+ this.chunkSize = chunkSize;
+ return this;
+ }
+
+ public VertexInfoBuilder baseUri(URI baseUri) {
+ this.baseUri = baseUri;
+
+ return this;
+ }
+
+ public VertexInfoBuilder baseUri(String baseUri) {
+ this.baseUri = URI.create(baseUri);
+
+ return this;
+ }
+
+ public VertexInfoBuilder version(VersionInfo version) {
+ this.version = version;
+
+ return this;
+ }
+
+ public VertexInfoBuilder version(String version) {
+ this.version = VersionParser.getVersion(version);
+
+ return this;
+ }
+
+ public VertexInfoBuilder addPropertyGroup(PropertyGroup propertyGroup)
{
+ if (propertyGroupsAsListTemp == null) propertyGroupsAsListTemp =
new ArrayList<>();
Review Comment:
Add {} to the if body to increase readability
##########
maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java:
##########
@@ -37,6 +38,102 @@ public class VertexInfo {
private final URI baseUri;
private final VersionInfo version;
+ public static VertexInfoBuilder builder() {
+ return new VertexInfoBuilder();
+ }
+
+ public static class VertexInfoBuilder {
+ private String type;
+ private long chunkSize;
+ private PropertyGroups propertyGroups;
+ private URI baseUri;
+ private VersionInfo version;
+ private List<PropertyGroup> propertyGroupsAsListTemp;
+
+ private VertexInfoBuilder() {}
+
+ public VertexInfoBuilder type(String type) {
+ this.type = type;
+ return this;
+ }
+
+ public VertexInfoBuilder chunkSize(long chunkSize) {
+ this.chunkSize = chunkSize;
+ return this;
+ }
+
+ public VertexInfoBuilder baseUri(URI baseUri) {
+ this.baseUri = baseUri;
+
+ return this;
+ }
+
+ public VertexInfoBuilder baseUri(String baseUri) {
+ this.baseUri = URI.create(baseUri);
+
+ return this;
+ }
+
+ public VertexInfoBuilder version(VersionInfo version) {
+ this.version = version;
+
+ return this;
+ }
+
+ public VertexInfoBuilder version(String version) {
+ this.version = VersionParser.getVersion(version);
+
+ return this;
+ }
+
+ public VertexInfoBuilder addPropertyGroup(PropertyGroup propertyGroup)
{
+ if (propertyGroupsAsListTemp == null) propertyGroupsAsListTemp =
new ArrayList<>();
+ propertyGroupsAsListTemp.add(propertyGroup);
+ return this;
+ }
+
+ public VertexInfoBuilder addPropertyGroups(List<PropertyGroup>
propertyGroups) {
+ if (propertyGroupsAsListTemp == null) propertyGroupsAsListTemp =
new ArrayList<>();
Review Comment:
same here
##########
maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoTest.java:
##########
@@ -20,14 +20,67 @@
package org.apache.graphar.info;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Arrays;
+import java.util.List;
import org.apache.graphar.info.type.DataType;
import org.apache.graphar.info.type.FileType;
import org.junit.Assert;
import org.junit.Test;
public class VertexInfoTest {
+ private VertexInfo.VertexInfoBuilder b =
+ VertexInfo.builder()
+ .baseUri("test")
+ .type("test")
+ .chunkSize(24)
+ .version("gar/v1")
+ .propertyGroups(new PropertyGroups(List.of(TestUtil.pg3)));
+
+ @Test
+ public void testVertexInfoBasicBuilder() {
+ VertexInfo v = b.build();
+ }
+
+ @Test
+ public void testVertexInfoBuilderDoubleDeclaration() throws
URISyntaxException {
+ VertexInfo v = b.baseUri(new URI("world")).build();
+
+ Assert.assertEquals(new URI("world"), v.getBaseUri());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void URInullTest() {
+ VertexInfo v =
+ VertexInfo.builder()
+ .type("test")
+ .chunkSize(24)
+ .version("gar/v1")
+ .propertyGroups(new
PropertyGroups(List.of(TestUtil.pg3)))
+ .build();
+ }
+
+ @Test
+ public void propertyGroupAppendTest() {
+ VertexInfo v = b.addPropertyGroup(TestUtil.pg2).build();
+
+ Assert.assertEquals(2, v.getPropertyGroups().size());
+ }
+
+ @Test
+ public void propertyGroupAddOnlyTest() {
+ VertexInfo v =
b.propertyGroups(null).addPropertyGroup(TestUtil.pg2).build();
+
+ Assert.assertEquals(1, v.getPropertyGroups().size());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void invalidChunkSizeTest() {
+ b.chunkSize(-1);
Review Comment:
It will be clearer using assertThrows, refer #770
--
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]