You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2022/11/09 10:25:36 UTC

[incubator-hugegraph] 33/33: adapt the latest version & clean code

This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit b1b12098feb726e46c781a2f171c77558db05fc1
Author: imbajin <ji...@apache.org>
AuthorDate: Tue Nov 1 18:05:04 2022 +0800

    adapt the latest version & clean code
    
    also fix the sec alert
---
 .../com/baidu/hugegraph/api/job/AlgorithmAPI.java  | 18 +++++------
 .../hugegraph/job/algorithm/AbstractAlgorithm.java | 11 +++----
 .../baidu/hugegraph/job/algorithm/Algorithm.java   |  8 ++---
 .../hugegraph/job/algorithm/AlgorithmPool.java     |  4 +--
 .../hugegraph/job/algorithm/BfsTraverser.java      |  4 +--
 .../baidu/hugegraph/job/algorithm/Consumers.java   |  5 +--
 .../job/algorithm/SubgraphStatAlgorithm.java       | 18 +++++------
 .../job/algorithm/cent/AbstractCentAlgorithm.java  | 11 +++----
 .../cent/BetweennessCentralityAlgorithm.java       |  2 +-
 .../cent/ClosenessCentralityAlgorithm.java         |  2 +-
 .../cent/ClosenessCentralityAlgorithmV2.java       |  2 +-
 .../algorithm/cent/DegreeCentralityAlgorithm.java  |  4 +--
 .../cent/EigenvectorCentralityAlgorithm.java       |  2 +-
 .../algorithm/cent/StressCentralityAlgorithm.java  |  2 +-
 ...rithm.java => ClusterCoefficientAlgorithm.java} | 13 ++++----
 .../job/algorithm/comm/LouvainTraverser.java       | 37 +++++++++-------------
 .../hugegraph/job/algorithm/comm/LpaAlgorithm.java |  2 +-
 .../hugegraph/job/computer/AbstractComputer.java   |  5 ++-
 .../com/baidu/hugegraph/job/schema/SchemaJob.java  |  4 +--
 .../job/system/DeleteExpiredIndexJob.java          |  2 +-
 .../baidu/hugegraph/job/system/JobCounters.java    | 11 +++----
 21 files changed, 75 insertions(+), 92 deletions(-)

diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/AlgorithmAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/AlgorithmAPI.java
index c965e02a5..b0e0d0692 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/AlgorithmAPI.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/AlgorithmAPI.java
@@ -21,15 +21,6 @@ package com.baidu.hugegraph.api.job;
 
 import java.util.Map;
 
-import javax.inject.Singleton;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.NotFoundException;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-
 import org.slf4j.Logger;
 
 import com.baidu.hugegraph.HugeGraph;
@@ -46,6 +37,15 @@ import com.baidu.hugegraph.util.Log;
 import com.codahale.metrics.annotation.Timed;
 import com.google.common.collect.ImmutableMap;
 
+import jakarta.inject.Singleton;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.NotFoundException;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.Context;
+
 @Path("graphs/{graph}/jobs/algorithm")
 @Singleton
 public class AlgorithmAPI extends API {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java
index 943debb4b..dbe3f7e2b 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java
@@ -57,8 +57,7 @@ import com.baidu.hugegraph.util.CollectionUtil;
 import com.baidu.hugegraph.util.E;
 import com.baidu.hugegraph.util.JsonUtil;
 import com.baidu.hugegraph.util.ParameterUtil;
-
-import jersey.repackaged.com.google.common.base.Objects;
+import com.google.common.base.Objects;
 
 @SuppressWarnings("deprecation") // StringEscapeUtils
 public abstract class AbstractAlgorithm implements Algorithm {
@@ -382,9 +381,7 @@ public abstract class AbstractAlgorithm implements Algorithm {
             ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
             query.capacity(Query.NO_CAPACITY);
             query.limit(limit);
-            if (label != null) {
-                query.eq(HugeKeys.LABEL, this.getVertexLabelId(label));
-            }
+            query.eq(HugeKeys.LABEL, this.getVertexLabelId(label));
             return this.graph().vertices(query);
         }
 
@@ -544,8 +541,8 @@ public abstract class AbstractAlgorithm implements Algorithm {
             this(4 * (int) Bytes.KB);
         }
 
-        public JsonMap(int initCapaticy) {
-            this.json = new StringBuilder(initCapaticy);
+        public JsonMap(int initCapacity) {
+            this.json = new StringBuilder(initCapacity);
         }
 
         public void startObject() {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Algorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Algorithm.java
index b1cb53144..856e38dbc 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Algorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Algorithm.java
@@ -25,11 +25,11 @@ import com.baidu.hugegraph.job.UserJob;
 
 public interface Algorithm {
 
-    public String name();
+    String name();
 
-    public String category();
+    String category();
 
-    public Object call(UserJob<Object> job, Map<String, Object> parameters);
+    Object call(UserJob<Object> job, Map<String, Object> parameters);
 
-    public void checkParameters(Map<String, Object> parameters);
+    void checkParameters(Map<String, Object> parameters);
 }
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java
index 02ac4c24e..7031318ac 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java
@@ -30,7 +30,7 @@ import com.baidu.hugegraph.job.algorithm.cent.DegreeCentralityAlgorithm;
 import com.baidu.hugegraph.job.algorithm.cent.EigenvectorCentralityAlgorithm;
 import com.baidu.hugegraph.job.algorithm.cent.StressCentralityAlgorithm;
 import com.baidu.hugegraph.job.algorithm.cent.StressCentralityAlgorithmV2;
-import com.baidu.hugegraph.job.algorithm.comm.ClusterCoeffcientAlgorithm;
+import com.baidu.hugegraph.job.algorithm.comm.ClusterCoefficientAlgorithm;
 import com.baidu.hugegraph.job.algorithm.comm.KCoreAlgorithm;
 import com.baidu.hugegraph.job.algorithm.comm.LouvainAlgorithm;
 import com.baidu.hugegraph.job.algorithm.comm.LpaAlgorithm;
@@ -56,7 +56,7 @@ public class AlgorithmPool {
         INSTANCE.register(new EigenvectorCentralityAlgorithm());
 
         INSTANCE.register(new TriangleCountAlgorithm());
-        INSTANCE.register(new ClusterCoeffcientAlgorithm());
+        INSTANCE.register(new ClusterCoefficientAlgorithm());
         INSTANCE.register(new LpaAlgorithm());
         INSTANCE.register(new LouvainAlgorithm());
         INSTANCE.register(new WeakConnectedComponent());
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/BfsTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/BfsTraverser.java
index 3b0920855..a85cef022 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/BfsTraverser.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/BfsTraverser.java
@@ -36,7 +36,7 @@ public abstract class BfsTraverser<T extends BfsTraverser.Node>
                 extends AbstractAlgorithm.AlgoTraverser
                 implements AutoCloseable {
 
-    private Stack<Id> traversedVertices = new Stack<>();
+    private final Stack<Id> traversedVertices = new Stack<>();
 
     public BfsTraverser(UserJob<Object> job) {
         super(job);
@@ -113,7 +113,7 @@ public abstract class BfsTraverser<T extends BfsTraverser.Node>
 
         private Id[] parents;
         private int pathCount;
-        private int distance;
+        private final int distance;
 
         public Node(Node parentNode) {
             this(0, parentNode.distance + 1);
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Consumers.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Consumers.java
index 1c68413fc..9a60e3031 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Consumers.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/Consumers.java
@@ -92,7 +92,7 @@ public class Consumers<V> {
             this.run();
             this.done();
         } catch (Throwable e) {
-            // Only the first exception of one thread can be stored
+            // Only the first exception to one thread can be stored
             this.exception = e;
             if (!(e instanceof StopExecution)) {
                 LOG.error("Error when running task", e);
@@ -110,7 +110,8 @@ public class Consumers<V> {
             this.consume();
         }
         assert this.ending;
-        while (this.consume());
+        while (this.consume()) {
+        }
 
         LOG.debug("Worker finished");
     }
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java
index d91748e41..814277b2a 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java
@@ -22,7 +22,7 @@ package com.baidu.hugegraph.job.algorithm;
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration2.PropertiesConfiguration;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.slf4j.Logger;
@@ -90,7 +90,6 @@ public class SubgraphStatAlgorithm extends AbstractAlgorithm {
         PropertiesConfiguration config = new PropertiesConfiguration();
         config.setProperty(CoreOptions.BACKEND.name(), "memory");
         config.setProperty(CoreOptions.STORE.name(), name);
-        config.setDelimiterParsingDisabled(true);
         /*
          * NOTE: this temp graph don't need to init backend because no task info
          * required, also not set started because no task to be scheduled.
@@ -129,12 +128,11 @@ public class SubgraphStatAlgorithm extends AbstractAlgorithm {
 
     private static class Traverser extends AlgoTraverser {
 
-        private static Map<String, Object> PARAMS = ImmutableMap.of(
-                                                    "depth", 10L,
-                                                    "degree", -1L,
-                                                    "sample", -1L,
-                                                    "top", -1L /* sorted */,
-                                                    "workers", 0);
+        private static final Map<String, Object> PARAMS = ImmutableMap.of("depth", 10L,
+                                                                          "degree", -1L,
+                                                                          "sample", -1L,
+                                                                          "top", -1L /* sorted */,
+                                                                          "workers", 0);
 
         public Traverser(UserJob<Object> job) {
             super(job);
@@ -166,8 +164,8 @@ public class SubgraphStatAlgorithm extends AbstractAlgorithm {
 
             results.put("page_ranks", pageRanks(job));
 
-            algo = pool.get("cluster_coeffcient");
-            results.put("cluster_coeffcient", algo.call(job, parameters));
+            algo = pool.get("cluster_coefficient");
+            results.put("cluster_coefficient", algo.call(job, parameters));
 
             algo = pool.get("rings");
             parameters = ImmutableMap.<String, Object>builder()
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java
index 066234873..6a7ba396a 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java
@@ -86,8 +86,7 @@ public abstract class AbstractCentAlgorithm extends AbstractAlgorithm {
 
             t = t.filter(it -> {
                 this.updateProgress(++this.progress);
-                return sourceCLabel == null ? true :
-                       match(it.get(), sourceCLabel);
+                return sourceCLabel == null || match(it.get(), sourceCLabel);
             });
 
             if (sourceSample > 0L) {
@@ -164,9 +163,7 @@ public abstract class AbstractCentAlgorithm extends AbstractAlgorithm {
                     triples.put(key, len);
                 } else {
                     assert len == shortest;
-                    if (keepOneShortestPath) {
-                        return false;
-                    }
+                    return !keepOneShortestPath;
                 }
                 return true;
             });
@@ -182,7 +179,7 @@ public abstract class AbstractCentAlgorithm extends AbstractAlgorithm {
                     @SuppressWarnings("unchecked")
                     Iterator<HugeVertex> items = (Iterator<HugeVertex>)
                                                  path.iterator();
-                    return new MapperIterator<>(items, v -> v.id());
+                    return new MapperIterator<>(items, HugeVertex::id);
                 }
                 int len = path.size();
                 if (len < 3) {
@@ -195,7 +192,7 @@ public abstract class AbstractCentAlgorithm extends AbstractAlgorithm {
                 @SuppressWarnings("unchecked")
                 Iterator<HugeVertex> items = (Iterator<HugeVertex>)
                                              path.iterator();
-                return new MapperIterator<>(items, v -> v.id());
+                return new MapperIterator<>(items, HugeVertex::id);
             });
         }
 
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/BetweennessCentralityAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/BetweennessCentralityAlgorithm.java
index 46f4d4a40..25e1451cf 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/BetweennessCentralityAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/BetweennessCentralityAlgorithm.java
@@ -95,7 +95,7 @@ public class BetweennessCentralityAlgorithm extends AbstractCentAlgorithm {
             tg = this.computeBetweenness(tg);
             GraphTraversal<Vertex, ?> tLimit = topN(tg, topN);
 
-            return this.execute(tLimit, () -> tLimit.next());
+            return this.execute(tLimit, tLimit::next);
         }
 
         protected GraphTraversal<Vertex, ?> groupPathByEndpoints(
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithm.java
index 6a95794a0..81979dc01 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithm.java
@@ -102,7 +102,7 @@ public class ClosenessCentralityAlgorithm extends AbstractCentAlgorithm {
                                 .math("_-1").sack(Operator.div).sack().sum());
             GraphTraversal<Vertex, ?> tLimit = topN(tg, topN);
 
-            return this.execute(tLimit, () -> tLimit.next());
+            return this.execute(tLimit, tLimit::next);
         }
     }
 }
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithmV2.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithmV2.java
index 1651c8943..55dc93ad9 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithmV2.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/ClosenessCentralityAlgorithmV2.java
@@ -61,7 +61,7 @@ public class ClosenessCentralityAlgorithmV2 extends AbstractCentAlgorithm {
 
     private static class Traverser extends BfsTraverser<BfsTraverser.Node> {
 
-        private Map<Id, Float> globalCloseness;
+        private final Map<Id, Float> globalCloseness;
 
         private float startVertexCloseness;
 
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java
index 6592c119d..6032b56e2 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java
@@ -19,7 +19,7 @@
 
 package com.baidu.hugegraph.job.algorithm.cent;
 
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -155,7 +155,7 @@ public class DegreeCentralityAlgorithm extends AbstractCentAlgorithm {
         }
 
         private long degree(Id source, String label) {
-            List<String> labels = label == null ? null : Arrays.asList(label);
+            List<String> labels = label == null ? null : Collections.singletonList(label);
             EdgeStep step = new EdgeStep(this.graph(), Directions.BOTH,
                                          labels, null, NO_LIMIT, 0);
             return this.edgesCount(source, step);
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/EigenvectorCentralityAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/EigenvectorCentralityAlgorithm.java
index 15748ec72..d396f3cf3 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/EigenvectorCentralityAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/EigenvectorCentralityAlgorithm.java
@@ -96,7 +96,7 @@ public class EigenvectorCentralityAlgorithm extends AbstractCentAlgorithm {
             GraphTraversal<Vertex, Object> tCap = t.cap("m");
             GraphTraversal<Vertex, ?> tLimit = topN(tCap, topN);
 
-            return this.execute(tLimit, () -> tLimit.next());
+            return this.execute(tLimit, tLimit::next);
         }
     }
 }
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/StressCentralityAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/StressCentralityAlgorithm.java
index 87f1471d4..6f4189255 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/StressCentralityAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/StressCentralityAlgorithm.java
@@ -100,7 +100,7 @@ public class StressCentralityAlgorithm extends AbstractCentAlgorithm {
                                                .groupCount();
             GraphTraversal<Vertex, ?> tLimit = topN(tg, topN);
 
-            return this.execute(tLimit, () -> tLimit.next());
+            return this.execute(tLimit, tLimit::next);
         }
     }
 }
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/ClusterCoeffcientAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/ClusterCoefficientAlgorithm.java
similarity index 84%
rename from hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/ClusterCoeffcientAlgorithm.java
rename to hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/ClusterCoefficientAlgorithm.java
index 2a0cf1a42..b7a3895a3 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/ClusterCoeffcientAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/ClusterCoefficientAlgorithm.java
@@ -26,9 +26,9 @@ import com.baidu.hugegraph.type.define.Directions;
 import com.baidu.hugegraph.util.E;
 import com.baidu.hugegraph.util.InsertionOrderUtil;
 
-public class ClusterCoeffcientAlgorithm extends AbstractCommAlgorithm {
+public class ClusterCoefficientAlgorithm extends AbstractCommAlgorithm {
 
-    public static final String ALGO_NAME = "cluster_coeffcient";
+    public static final String ALGO_NAME = "cluster_coefficient";
 
     @Override
     public String name() {
@@ -46,8 +46,7 @@ public class ClusterCoeffcientAlgorithm extends AbstractCommAlgorithm {
     public Object call(UserJob<Object> job, Map<String, Object> parameters) {
         int workers = workersWhenBoth(parameters);
         try (Traverser traverser = new Traverser(job, workers)) {
-            return traverser.clusterCoeffcient(direction(parameters),
-                                               degree(parameters));
+            return traverser.clusterCoefficient(direction(parameters), degree(parameters));
         }
     }
 
@@ -67,18 +66,18 @@ public class ClusterCoeffcientAlgorithm extends AbstractCommAlgorithm {
             super(job, ALGO_NAME, workers);
         }
 
-        public Object clusterCoeffcient(Directions direction, long degree) {
+        public Object clusterCoefficient(Directions direction, long degree) {
             Map<String, Long> results = this.triangles(direction, degree);
             results = InsertionOrderUtil.newMap(results);
 
             long triangles = results.remove(KEY_TRIANGLES);
             long triads = results.remove(KEY_TRIADS);
             assert triangles <= triads;
-            double coeffcient = triads == 0L ? 0d : 1d * triangles / triads;
+            double coefficient = triads == 0L ? 0d : 1d * triangles / triads;
 
             @SuppressWarnings({ "unchecked", "rawtypes" })
             Map<String, Double> converted = (Map) results;
-            converted.put("cluster_coeffcient", coeffcient);
+            converted.put("cluster_coefficient", coefficient);
 
             return results;
         }
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java
index 4359d46b8..d6f647baf 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java
@@ -20,11 +20,12 @@
 package com.baidu.hugegraph.job.algorithm.comm;
 
 import java.io.BufferedOutputStream;
-import java.io.FileOutputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -238,10 +239,7 @@ public class LouvainTraverser extends AlgoTraverser {
             }
         }
         // skip the vertex with unmatched clabel
-        if (this.sourceCLabel != null && !match(v, this.sourceCLabel)) {
-            return true;
-        }
-        return false;
+        return this.sourceCLabel != null && !match(v, this.sourceCLabel);
     }
 
     private Iterator<Vertex> sourceVertices(int pass) {
@@ -321,9 +319,7 @@ public class LouvainTraverser extends AlgoTraverser {
         return comm;
     }
 
-    private Collection<Pair<Community, MutableInt>> nbCommunities(
-                                                    int pass,
-                                                    List<Edge> edges) {
+    private Collection<Pair<Community, MutableInt>> nbCommunities(int pass, List<Edge> edges) {
         // comms is a map of cid:[community,weight]
         Map<Id, Pair<Community, MutableInt>> comms = new HashMap<>();
         for (Edge edge : edges) {
@@ -512,7 +508,7 @@ public class LouvainTraverser extends AlgoTraverser {
                 if (cvertices.contains(otherV.id())) {
                     // inner edges of this community, will be calc twice
                     // due to both e-in and e-out are in vertices,
-                    kin += weightOfEdge(edge);
+                    kin += (int) weightOfEdge(edge);
                     continue;
                 }
                 assert this.cache.vertex2Community(otherV.id()) != null;
@@ -579,11 +575,10 @@ public class LouvainTraverser extends AlgoTraverser {
         int times = maxTimes;
         int movedTimes = 0;
         double movedPercent = 0d;
-        double lastMovedPercent = 0d;
+        double lastMovedPercent;
 
         for (int i = 0; i < maxTimes; i++) {
             boolean finished = true;
-            movedPercent = 0d;
             lastMovedPercent = 1d;
             int tinyChanges = 0;
             while ((movedPercent = this.moveCommunities(i)) > 0d) {
@@ -654,7 +649,7 @@ public class LouvainTraverser extends AlgoTraverser {
 
     public Collection<Object> showCommunity(String community) {
         final String C_PASS0 = labelOfPassN(0);
-        Collection<Object> comms = Arrays.asList(community);
+        Collection<Object> comms = Collections.singletonList(community);
         boolean reachPass0 = false;
         while (comms.size() > 0 && !reachPass0) {
             Iterator<Vertex> subComms = this.vertices(comms.iterator());
@@ -679,7 +674,7 @@ public class LouvainTraverser extends AlgoTraverser {
         String label = labelOfPassN(pass);
         GraphTraversal<Vertex, Vertex> t = this.g.V().hasLabel(label);
         this.execute(t, () -> {
-            try (OutputStream os = new FileOutputStream(exportFile);
+            try (OutputStream os = Files.newOutputStream(Paths.get(exportFile));
                  BufferedOutputStream bos = new BufferedOutputStream(os)) {
                 while (t.hasNext()) {
                     String comm = t.next().id().toString();
@@ -712,7 +707,7 @@ public class LouvainTraverser extends AlgoTraverser {
             List<String> els = this.cpassEdgeLabels();
             if (els.size() > 0) {
                 String first = els.remove(0);
-                te = te.hasLabel(first, els.toArray(new String[els.size()]));
+                te = te.hasLabel(first, els.toArray(new String[0]));
                 this.drop(te);
             }
             // drop schema
@@ -736,7 +731,7 @@ public class LouvainTraverser extends AlgoTraverser {
             List<String> vls = this.cpassVertexLabels();
             if (vls.size() > 0) {
                 String first = vls.remove(0);
-                tv = tv.hasLabel(first, vls.toArray(new String[vls.size()]));
+                tv = tv.hasLabel(first, vls.toArray(new String[0]));
                 this.drop(tv);
             }
             // drop schema
@@ -895,7 +890,7 @@ public class LouvainTraverser extends AlgoTraverser {
             // gen id for merge-community vertex
             String id = cid.toString();
             if (pass == 0) {
-                // conncat pass with cid
+                // concat pass with cid
                 id = pass + "~" + id;
             } else {
                 // replace last pass with current pass
@@ -915,11 +910,9 @@ public class LouvainTraverser extends AlgoTraverser {
                 if (c.empty()) {
                     continue;
                 }
-                Pair<Community, Set<Id>> pair = comms.get(c.cid);
-                if (pair == null) {
-                    pair = Pair.of(c, new HashSet<>());
-                    comms.put(c.cid, pair);
-                }
+                Pair<Community, Set<Id>> pair = comms.computeIfAbsent(c.cid, k -> {
+                    return Pair.of(c, new HashSet<>());
+                });
                 // collect members joined to the community [current pass]
                 pair.getRight().add(e.getKey());
             }
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java
index f25201bea..59d53245f 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java
@@ -184,7 +184,7 @@ public class LpaAlgorithm extends AbstractCommAlgorithm {
             Iterator<Id> neighbors = this.adjacentVertices(source, dir,
                                                            labelId, degree);
 
-            // whether or not include vertex itself, greatly affects the result.
+            // whether include vertex itself, greatly affects the result.
             // get a larger number of small communities if include itself
             //neighbors.inject(v);
 
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/AbstractComputer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/AbstractComputer.java
index ca08ec9a3..3ef49c751 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/AbstractComputer.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/AbstractComputer.java
@@ -174,7 +174,7 @@ public abstract class AbstractComputer implements Computer {
                         "'%s' must be contained in config '%s'", sub);
 
         ImmutableNode root = null;
-        NodeHandler<ImmutableNode> nodeHandler = null;
+        NodeHandler<ImmutableNode> nodeHandler;
         Map<String, Object> results = new HashMap<>(nodes.size());
         for (HierarchicalConfiguration<ImmutableNode> node : nodes) {
             NodeModel<ImmutableNode> nodeModel = node.getNodeModel();
@@ -191,8 +191,7 @@ public abstract class AbstractComputer implements Computer {
     private String[] constructShellCommands(Map<String, Object> configs) {
         String hadoopHome = System.getenv(HADOOP_HOME);
         String commandPrefix = String.format(MAIN_COMMAND, hadoopHome);
-        List<String> command = new ArrayList<>();
-        command.addAll(Arrays.asList(commandPrefix.split(SPACE)));
+        List<String> command = new ArrayList<>(Arrays.asList(commandPrefix.split(SPACE)));
         command.add(this.name());
         for (Map.Entry<String, Object> entry : configs.entrySet()) {
             command.add(MINUS_C);
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/SchemaJob.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/SchemaJob.java
index afa6c3069..4841ac484 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/SchemaJob.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/SchemaJob.java
@@ -106,8 +106,8 @@ public abstract class SchemaJob extends SysJob<Object> {
     /**
      * Use reflection to call SchemaTransaction.updateSchema(),
      * which is protected
-     * @param tx        The update operation actual executer
-     * @param schema    the schema to be update
+     * @param tx        The update operation actual execute
+     * @param schema    the schema to be updated
      */
     protected static void updateSchema(SchemaTransaction tx,
                                        SchemaElement schema) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/DeleteExpiredIndexJob.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/DeleteExpiredIndexJob.java
index ede9a03bb..d7889a3be 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/DeleteExpiredIndexJob.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/DeleteExpiredIndexJob.java
@@ -34,7 +34,7 @@ public class DeleteExpiredIndexJob<V> extends DeleteExpiredJob<V> {
 
     private static final String JOB_TYPE = "delete_expired_index";
 
-    private Set<HugeIndex> indexes;
+    private final Set<HugeIndex> indexes;
 
     public DeleteExpiredIndexJob(Set<HugeIndex> indexes) {
         E.checkArgument(indexes != null && !indexes.isEmpty(),
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/JobCounters.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/JobCounters.java
index afbe89090..9f4bb1cae 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/JobCounters.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/system/JobCounters.java
@@ -30,8 +30,7 @@ import com.baidu.hugegraph.structure.HugeIndex;
 
 public class JobCounters {
 
-    private ConcurrentHashMap<String, JobCounter> jobCounters =
-                                                  new ConcurrentHashMap<>();
+    private final ConcurrentHashMap<String, JobCounter> jobCounters = new ConcurrentHashMap<>();
 
     public JobCounter jobCounter(HugeGraph g) {
         int batch = g.option(CoreOptions.TASK_TTL_DELETE_BATCH);
@@ -44,10 +43,10 @@ public class JobCounters {
 
     public static class JobCounter {
 
-        private AtomicInteger jobs;
+        private final AtomicInteger jobs;
         private Set<HugeElement> elements;
         private Set<HugeIndex> indexes;
-        private int batchSize;
+        private final int batchSize;
 
         public JobCounter(int batchSize) {
             this.jobs = new AtomicInteger(0);
@@ -94,7 +93,7 @@ public class JobCounters {
         /**
          * Try to add element in collection waiting to be deleted
          * @param element
-         * @return true if should create a new delete job, false otherwise
+         * @return true if we should create a new delete job, false otherwise
          */
         public boolean addElementAndTriggerDelete(HugeElement element) {
             if (this.elements.size() >= this.batchSize) {
@@ -107,7 +106,7 @@ public class JobCounters {
         /**
          * Try to add edge in collection waiting to be deleted
          * @param index
-         * @return true if should create a new delete job, false otherwise
+         * @return true if we should create a new delete job, false otherwise
          */
         public boolean addIndexAndTriggerDelete(HugeIndex index) {
             if (this.indexes.size() >= this.batchSize) {