javeme commented on code in PR #285:
URL: 
https://github.com/apache/incubator-hugegraph-computer/pull/285#discussion_r1510166016


##########
computer-test/src/main/java/org/apache/hugegraph/computer/core/util/IdUtilTest.java:
##########
@@ -26,16 +25,14 @@ public class IdUtilTest {
 
     @Test
     public void testParseId() {
-        String uuid = "3b676b77-c484-4ba6-b627-8c040bc42863";
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId("222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId("aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(uuid).idType());
-
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId(IdCategory.NUMBER, 
"222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, 
"aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(IdCategory.UUID, 
uuid).idType());
+        String utf81 = "\"abc\"";
+        String utf82 = "\"222\"";
+        String l = "222";

Review Comment:
   idLong



##########
computer-test/src/main/java/org/apache/hugegraph/computer/core/util/IdUtilTest.java:
##########
@@ -26,16 +25,14 @@ public class IdUtilTest {
 
     @Test
     public void testParseId() {
-        String uuid = "3b676b77-c484-4ba6-b627-8c040bc42863";
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId("222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId("aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(uuid).idType());
-
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId(IdCategory.NUMBER, 
"222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, 
"aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(IdCategory.UUID, 
uuid).idType());
+        String utf81 = "\"abc\"";

Review Comment:
   idUtf8WithString



##########
computer-test/src/main/java/org/apache/hugegraph/computer/core/util/IdUtilTest.java:
##########
@@ -26,16 +25,14 @@ public class IdUtilTest {
 
     @Test
     public void testParseId() {
-        String uuid = "3b676b77-c484-4ba6-b627-8c040bc42863";
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId("222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId("aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(uuid).idType());
-
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId(IdCategory.NUMBER, 
"222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, 
"aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(IdCategory.UUID, 
uuid).idType());
+        String utf81 = "\"abc\"";
+        String utf82 = "\"222\"";
+        String l = "222";
+        String uuid = "U\"3b676b77-c484-4ba6-b627-8c040bc42863\"";
 
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, 
"222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, 
uuid).idType());
+        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(utf81).idType());
+        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(utf82).idType());
+        Assert.assertEquals(IdType.LONG, IdUtil.parseId(l).idType());
+        Assert.assertEquals(IdType.UUID, IdUtil.parseId(uuid).idType());

Review Comment:
   can we also add some exception cases, like idEmpty/idDouble/uuidInvalid



##########
computer-test/src/main/java/org/apache/hugegraph/computer/core/util/IdUtilTest.java:
##########
@@ -26,16 +25,14 @@ public class IdUtilTest {
 
     @Test
     public void testParseId() {
-        String uuid = "3b676b77-c484-4ba6-b627-8c040bc42863";
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId("222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId("aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(uuid).idType());
-
-        Assert.assertEquals(IdType.LONG, IdUtil.parseId(IdCategory.NUMBER, 
"222").idType());
-        Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, 
"aaa222").idType());
-        Assert.assertEquals(IdType.UUID, IdUtil.parseId(IdCategory.UUID, 
uuid).idType());
+        String utf81 = "\"abc\"";
+        String utf82 = "\"222\"";

Review Comment:
   idUtf8WithNumber



##########
computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java:
##########
@@ -18,55 +18,37 @@
 package org.apache.hugegraph.computer.core.util;
 
 import java.util.UUID;
-import java.util.regex.Pattern;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hugegraph.computer.core.common.exception.ComputerException;
 import org.apache.hugegraph.computer.core.graph.id.Id;
-import org.apache.hugegraph.computer.core.graph.id.IdCategory;
 import org.apache.hugegraph.computer.core.graph.id.IdFactory;
 import org.apache.hugegraph.computer.core.graph.id.IdType;
+import org.apache.hugegraph.util.JsonUtil;
 
 public class IdUtil {
 
-    private static String UUID_REGEX = "^[0-9a-fA-F]{8}-" +
-                                       "[0-9a-fA-F]{4}-" +
-                                       "[0-9a-fA-F]{4}-" +
-                                       "[0-9a-fA-F]{4}-" +
-                                       "[0-9a-fA-F]{12}$";
-    private static Pattern P = Pattern.compile(UUID_REGEX);
-
     public static Id parseId(String idStr) {
         if (StringUtils.isBlank(idStr)) {
             throw new ComputerException("Can't parse Id for empty string");
         }
 
-        if (StringUtils.isNumeric(idStr)) {
-            return IdFactory.parseId(IdType.LONG, Long.valueOf(idStr));
-        } else if (P.matcher(idStr).matches()) {
-            return IdFactory.parseId(IdType.UUID, UUID.fromString(idStr));
-        } else {
-            return IdFactory.parseId(IdType.UTF8, idStr);
-        }
-    }
-
-    public static Id parseId(IdCategory idCategory, String idStr) {
-        if (StringUtils.isBlank(idStr)) {
-            throw new ComputerException("Can't parse Id for empty string");
-        }
-
-        if (idCategory == null) {
-            // automatic inference
-            return parseId(idStr);
+        if (idStr.startsWith("U\"")) {

Review Comment:
   also move to try-catch?



-- 
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]

Reply via email to