From 0b1c720d55d33bfa038e54a27ae0255c25904c3b Mon Sep 17 00:00:00 2001 From: diaohancai <550630588@qq.com> Date: Thu, 29 Feb 2024 13:24:13 +0800 Subject: [PATCH] chore: log improvement --- .../shortest/SingleSourceShortestPath.java | 28 ++----------------- .../computer/core/util/JsonUtilExt.java | 2 +- .../SingleSourceShortestPathTest.java | 5 ++-- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java b/computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java index 14d18538d..c9b49cfde 100644 --- a/computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java +++ b/computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java @@ -142,16 +142,15 @@ public void compute0(ComputationContext context, Vertex vertex) { // single target && source == target if (this.targetQuantityType == QuantityType.SINGLE && - this.sourceId.equals(this.targetIdSet.value().iterator().next())) { - LOG.debug("source vertex {} equals target vertex {}", - this.sourceId, this.targetIdSet.value().iterator().next()); + this.targetIdSet.contains(this.sourceId)) { + LOG.debug("source vertex equals target vertex: {}", this.sourceId); vertex.inactivate(); return; } if (vertex.numEdges() <= 0) { // isolated vertex - LOG.debug("source vertex {} is isolated", this.sourceId); + LOG.debug("The source vertex is isolated: {}", this.sourceId); vertex.inactivate(); return; } @@ -279,25 +278,4 @@ private boolean isAllTargetsReached(Vertex vertex) { } return false; } - - static class VertexInputJson { - private String id; - private String idType; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getIdType() { - return idType; - } - - public void setIdType(String idType) { - this.idType = idType; - } - } } diff --git a/computer-api/src/main/java/org/apache/hugegraph/computer/core/util/JsonUtilExt.java b/computer-api/src/main/java/org/apache/hugegraph/computer/core/util/JsonUtilExt.java index 5456cfeea..3304881e2 100644 --- a/computer-api/src/main/java/org/apache/hugegraph/computer/core/util/JsonUtilExt.java +++ b/computer-api/src/main/java/org/apache/hugegraph/computer/core/util/JsonUtilExt.java @@ -25,7 +25,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -// todo move to org.apache.hugegraph.util.JsonUtil later +// TODO: move to org.apache.hugegraph.util.JsonUtil later public class JsonUtilExt { private static final ObjectMapper MAPPER = new ObjectMapper(); diff --git a/computer-test/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPathTest.java b/computer-test/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPathTest.java index bd0b2cc1c..4b2b466a5 100644 --- a/computer-test/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPathTest.java +++ b/computer-test/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPathTest.java @@ -135,9 +135,10 @@ public String value(org.apache.hugegraph.computer.core.graph.vertex.Vertex verte if (vertex.id().value().toString().equals(TARGET_ID)) { Map map = JsonUtil.fromJson(json, Map.class); - LOG.info("source vertex {} to target vertex {}, " + + LOG.info("source vertex to target vertex: {}, {}, " + "shortest path: {}, total weight: {}", - SOURCE_ID, TARGET_ID, map.get("path"), map.get("total_weight")); + SOURCE_ID, TARGET_ID, + map.get("path"), map.get("total_weight")); Assert.assertEquals(map.get("path"), SHORTEST_PATH); Assert.assertEquals(map.get("total_weight"), TOTAL_WEIGHT); }