From c28f7c1b9ee6ac3f4d36a47279966fb460330c93 Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 27 Apr 2022 21:45:19 +0800 Subject: [PATCH 1/7] fix checkstyle of core-util issue --- .../traversal/algorithm/HugeTraverser.java | 16 +++++----- .../algorithm/JaccardSimilarTraverser.java | 3 +- .../traversal/algorithm/OltpTraverser.java | 4 +-- .../algorithm/ShortestPathTraverser.java | 6 ++-- .../records/ShortestPathRecords.java | 2 +- .../optimize/HugeScriptTraversal.java | 3 -- .../traversal/optimize/TraversalUtil.java | 9 +++--- .../com/baidu/hugegraph/type/HugeType.java | 2 +- .../hugegraph/type/define/SerialEnum.java | 14 ++++----- .../com/baidu/hugegraph/util/ConfigUtil.java | 13 ++++---- .../com/baidu/hugegraph/util/Consumers.java | 6 ++-- .../com/baidu/hugegraph/util/GZipUtil.java | 2 +- .../com/baidu/hugegraph/util/KryoUtil.java | 12 ++++---- .../com/baidu/hugegraph/util/Reflection.java | 30 +++++++++---------- .../hugegraph/util/collection/IntMap.java | 27 ++++++++++------- .../hugegraph/util/collection/IntSet.java | 23 +++++++------- 16 files changed, 85 insertions(+), 87 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java index 340838bf50..4192dfec48 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java @@ -360,10 +360,9 @@ public static void checkCapacity(long capacity, long access, public static void checkSkipDegree(long skipDegree, long degree, long capacity) { - E.checkArgument(skipDegree >= 0L && - skipDegree <= Query.DEFAULT_CAPACITY , - "The skipped degree must be in [0, %s], but got '%s'", - Query.DEFAULT_CAPACITY, skipDegree); + E.checkArgument(skipDegree >= 0L && skipDegree <= Query.DEFAULT_CAPACITY, + "The skipped degree must be in [0, %s], but got '%s'", + Query.DEFAULT_CAPACITY, skipDegree); if (capacity != NO_LIMIT) { E.checkArgument(degree != NO_LIMIT && degree < capacity, "The max degree must be < capacity"); @@ -378,10 +377,9 @@ public static void checkSkipDegree(long skipDegree, long degree, } } - public static > Map topN( - Map map, - boolean sorted, - long limit) { + public static > Map topN(Map map, boolean sorted, long limit) { + if (sorted) { map = CollectionUtil.sortByValue(map, false); } @@ -636,7 +634,7 @@ public String toString() { public static class PathSet implements Set { - public final static PathSet EMPTY = new PathSet(ImmutableSet.of()); + public static final PathSet EMPTY = new PathSet(ImmutableSet.of()); private final Set paths; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java index e06076d51e..81757214ac 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java @@ -41,9 +41,8 @@ public JaccardSimilarTraverser(HugeGraph graph) { super(graph); } - public double jaccardSimilarity(Id vertex, Id other, Directions dir, - String label, long degree) { + String label, long degree) { E.checkNotNull(vertex, "vertex id"); E.checkNotNull(other, "the other vertex id"); this.checkVertexExist(vertex, "vertex"); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java index fd84848f04..22b323e478 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java @@ -38,9 +38,7 @@ import com.baidu.hugegraph.iterator.FilterIterator; import com.baidu.hugegraph.util.Consumers; - -public abstract class OltpTraverser extends HugeTraverser - implements AutoCloseable { +public abstract class OltpTraverser extends HugeTraverser implements AutoCloseable { private static final String EXECUTOR_NAME = "oltp"; private static Consumers.ExecutorPool executors; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java index bb3e8460be..5a3d85921f 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java @@ -177,8 +177,7 @@ public PathSet forward(boolean all) { Id target = edge.id().otherVertexId(); PathSet paths = this.record.findPath(target, - t -> !this.superNode(t, this.direction), - all, false); + t -> !this.superNode(t, this.direction), all, false); if (paths.isEmpty()) { continue; @@ -217,8 +216,7 @@ public PathSet backward(boolean all) { Id target = edge.id().otherVertexId(); PathSet paths = this.record.findPath(target, - t -> !this.superNode(t, opposite), - all, false); + t -> !this.superNode(t, opposite), all,false); if (paths.isEmpty()) { continue; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/ShortestPathRecords.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/ShortestPathRecords.java index c55d1590d6..691b61902e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/ShortestPathRecords.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/ShortestPathRecords.java @@ -107,7 +107,7 @@ private Path linkPath(Stack all, int node) { List ids = new ArrayList<>(size); ids.add(this.id(node)); int value = node; - for (int i = size - 1; i > 0 ; i--) { + for (int i = size - 1; i > 0; i--) { IntMap layer = ((Int2IntRecord) all.elementAt(i)).layer(); value = layer.get(value); ids.add(this.id(value)); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java index 0889c08988..5bd45b303e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java @@ -25,9 +25,6 @@ import javax.script.ScriptEngine; import javax.script.ScriptException; -import com.baidu.hugegraph.auth.HugePermission; -import com.baidu.hugegraph.auth.ResourceType; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslator; import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java index 6755ee326e..549bb6680d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java @@ -30,7 +30,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.google.common.collect.Collections2; import org.apache.tinkerpop.gremlin.process.traversal.Compare; import org.apache.tinkerpop.gremlin.process.traversal.Contains; import org.apache.tinkerpop.gremlin.process.traversal.Order; @@ -65,6 +64,7 @@ import org.apache.tinkerpop.gremlin.structure.PropertyType; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.slf4j.Logger; import com.baidu.hugegraph.HugeException; import com.baidu.hugegraph.HugeGraph; @@ -91,10 +91,13 @@ import com.baidu.hugegraph.util.DateUtil; import com.baidu.hugegraph.util.E; import com.baidu.hugegraph.util.JsonUtil; +import com.baidu.hugegraph.util.Log; import com.google.common.collect.ImmutableList; public final class TraversalUtil { + private static final Logger LOG = Log.logger(HugeGraph.class); + public static final String P_CALL = "P."; public static HugeGraph getGraph(Step step) { @@ -287,9 +290,7 @@ public static void fillConditionQuery(ConditionQuery query, } } - public static Condition convHas2Condition(HasContainer has, - HugeType type, - HugeGraph graph) { + public static Condition convHas2Condition(HasContainer has, HugeType type, HugeGraph graph) { P p = has.getPredicate(); E.checkArgument(p != null, "The predicate of has(%s) is null", has); BiPredicate bp = p.getBiPredicate(); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/HugeType.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/HugeType.java index 2284a972d3..bfb146ecf6 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/HugeType.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/HugeType.java @@ -112,7 +112,7 @@ public boolean isSchema() { } public boolean isGraph() { - return this.isVertex() || this.isEdge() ; + return this.isVertex() || this.isEdge(); } public boolean isVertex() { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SerialEnum.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SerialEnum.java index 40b245b6e1..45b370558b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SerialEnum.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SerialEnum.java @@ -28,11 +28,11 @@ public interface SerialEnum { - public byte code(); + byte code(); - static Table, Byte, SerialEnum> table = HashBasedTable.create(); + Table, Byte, SerialEnum> TABLE = HashBasedTable.create(); - public static void register(Class clazz) { + static void register(Class clazz) { Object enums; try { enums = clazz.getMethod("values").invoke(null); @@ -40,13 +40,13 @@ public static void register(Class clazz) { throw new BackendException(e); } for (SerialEnum e : CollectionUtil.toList(enums)) { - table.put(clazz, e.code(), e); + TABLE.put(clazz, e.code(), e); } } - public static T fromCode(Class clazz, byte code) { + static T fromCode(Class clazz, byte code) { @SuppressWarnings("unchecked") - T value = (T) table.get(clazz, code); + T value = (T) TABLE.get(clazz, code); if (value == null) { E.checkArgument(false, "Can't construct %s from code %s", clazz.getSimpleName(), code); @@ -54,7 +54,7 @@ public static T fromCode(Class clazz, byte code) { return value; } - public static void registerInternalEnums() { + static void registerInternalEnums() { SerialEnum.register(Action.class); SerialEnum.register(AggregateType.class); SerialEnum.register(Cardinality.class); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java index 81cc1f02c7..e120df6f9e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java @@ -58,10 +58,9 @@ public static void checkGremlinConfig(String conf) { try { FileBasedConfigurationBuilder builder = - new FileBasedConfigurationBuilder(YAMLConfiguration.class) - .configure(params.fileBased().setFileName(conf)); - YAMLConfiguration config = (YAMLConfiguration) builder - .getConfiguration(); + new FileBasedConfigurationBuilder(YAMLConfiguration.class) + .configure(params.fileBased().setFileName(conf)); + YAMLConfiguration config = (YAMLConfiguration) builder.getConfiguration(); List> nodes = config.childConfigurationsAt( @@ -78,9 +77,9 @@ public static void checkGremlinConfig(String conf) { for (HierarchicalConfiguration node : nodes) { NodeModel nodeModel = node.getNodeModel(); E.checkArgument(nodeModel != null && - (nodeHandler = nodeModel.getNodeHandler()) != null && - (root = nodeHandler.getRootNode()) != null, - "Node '%s' must contain root", node); + (nodeHandler = nodeModel.getNodeHandler()) != null && + (root = nodeHandler.getRootNode()) != null, + "Node '%s' must contain root", node); } } catch (ConfigurationException e) { throw new HugeException("Failed to load yaml config file '%s'", diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java index 69e96ec43c..c00d9f48e3 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java @@ -147,7 +147,7 @@ private void done() { if (this.exception == null) { this.exception = e; } else { - LOG.warn("Error while calling done()", e);; + LOG.warn("Error while calling done()", e); } } } @@ -170,7 +170,7 @@ public void provide(V v) throws Throwable { try { this.queue.put(v); } catch (InterruptedException e) { - LOG.warn("Interrupted while enqueue", e);; + LOG.warn("Interrupted while enqueue", e); } } } @@ -262,7 +262,7 @@ public static RuntimeException wrapException(Throwable e) { public static class ExecutorPool { - private final static int POOL_CAPACITY = 2 * CoreOptions.CPUS; + private static final int POOL_CAPACITY = 2 * CoreOptions.CPUS; private final String threadNamePrefix; private final int executorWorkers; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/GZipUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/GZipUtil.java index 13d1fefbc8..5f5b00c48a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/GZipUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/GZipUtil.java @@ -35,7 +35,7 @@ public final class GZipUtil { private static final int BUF_SIZE = (int) (4 * Bytes.KB); - public static String md5(String input){ + public static String md5(String input) { return DigestUtils.md5Hex(input); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/KryoUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/KryoUtil.java index 4a49b645f6..1f5d66226b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/KryoUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/KryoUtil.java @@ -32,17 +32,17 @@ public final class KryoUtil { - private static final ThreadLocal kryos = new ThreadLocal<>(); + private static final ThreadLocal KRYOS = new ThreadLocal<>(); public static Kryo kryo() { - Kryo kryo = kryos.get(); + Kryo kryo = KRYOS.get(); if (kryo != null) { return kryo; } kryo = new Kryo(); registerSerializers(kryo); - kryos.set(kryo); + KRYOS.set(kryo); return kryo; } @@ -70,9 +70,9 @@ public static byte[] toKryoWithType(Object value) { kryo().writeClassAndObject(output, value); output.flush(); return bos.toByteArray(); - } catch (IOException e) { - throw new BackendException("Failed to serialize: %s", e, value); - } + } catch (IOException e) { + throw new BackendException("Failed to serialize: %s", e, value); + } } @SuppressWarnings("unchecked") diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java index 0016a996f7..ea0b2ba4fb 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java @@ -31,9 +31,9 @@ public class Reflection { private static final Logger LOG = Log.logger(Reflection.class); - private static final Class reflectionClazz; - private static final Method registerFieldsToFilterMethod; - private static final Method registerMethodsToFilterMethod; + private static final Class REFLECTION_CLAZZ; + private static final Method REGISTER_FILEDS_TO_FILTER_METHOD; + private static final Method REGISTER_METHODS_TO_FILTER_MOTHOD; public static final String JDK_INTERNAL_REFLECT_REFLECTION = "jdk.internal.reflect.Reflection"; @@ -55,12 +55,12 @@ public class Reflection { } } - reflectionClazz = reflectionClazzTemp; + REFLECTION_CLAZZ = reflectionClazzTemp; - if (reflectionClazz != null) { + if (REFLECTION_CLAZZ != null) { try { registerFieldsToFilterMethodTemp = - reflectionClazz.getMethod("registerFieldsToFilter", + REFLECTION_CLAZZ.getMethod("registerFieldsToFilter", Class.class, String[].class); } catch (Throwable e) { LOG.error("Can't find registerFieldsToFilter method", e); @@ -68,26 +68,26 @@ public class Reflection { try { registerMethodsToFilterMethodTemp = - reflectionClazz.getMethod("registerMethodsToFilter", + REFLECTION_CLAZZ.getMethod("registerMethodsToFilter", Class.class, String[].class); } catch (NoSuchMethodException e) { LOG.error("Can't find registerMethodsToFilter method", e); } } - registerFieldsToFilterMethod = registerFieldsToFilterMethodTemp; - registerMethodsToFilterMethod = registerMethodsToFilterMethodTemp; + REGISTER_FILEDS_TO_FILTER_METHOD = registerFieldsToFilterMethodTemp; + REGISTER_METHODS_TO_FILTER_MOTHOD = registerMethodsToFilterMethodTemp; } public static void registerFieldsToFilter(Class containingClass, String... fieldNames) { - if (registerFieldsToFilterMethod == null) { + if (REGISTER_FILEDS_TO_FILTER_METHOD == null) { throw new NotSupportException( "Reflection.registerFieldsToFilter()"); } try { - registerFieldsToFilterMethod.setAccessible(true); - registerFieldsToFilterMethod.invoke(reflectionClazz, + REGISTER_FILEDS_TO_FILTER_METHOD.setAccessible(true); + REGISTER_FILEDS_TO_FILTER_METHOD.invoke(REFLECTION_CLAZZ, containingClass, fieldNames); } catch (IllegalAccessException | InvocationTargetException e) { throw new HugeException( @@ -98,14 +98,14 @@ public static void registerFieldsToFilter(Class containingClass, public static void registerMethodsToFilter(Class containingClass, String... methodNames) { - if (registerMethodsToFilterMethod == null) { + if (REGISTER_METHODS_TO_FILTER_MOTHOD == null) { throw new NotSupportException( "Reflection.registerMethodsToFilterMethod()"); } try { - registerMethodsToFilterMethod.setAccessible(true); - registerMethodsToFilterMethod.invoke(reflectionClazz, + REGISTER_METHODS_TO_FILTER_MOTHOD.setAccessible(true); + REGISTER_METHODS_TO_FILTER_MOTHOD.invoke(REFLECTION_CLAZZ, containingClass, methodNames); } catch (IllegalAccessException | InvocationTargetException e) { throw new HugeException( diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java index 5c03326d51..58d72aeb90 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java @@ -35,18 +35,23 @@ public interface IntMap { - public boolean put(int key, int value); - public int get(int key); - public boolean remove(int key); - public boolean containsKey(int key); + boolean put(int key, int value); - public IntIterator keys(); - public IntIterator values(); + int get(int key); - public void clear(); - public int size(); + boolean remove(int key); - public boolean concurrent(); + boolean containsKey(int key); + + IntIterator keys(); + + IntIterator values(); + + void clear(); + + int size(); + + boolean concurrent(); /** * NOTE: IntMapBySegments(backend by IntMapByFixedAddr) is: @@ -55,7 +60,7 @@ public interface IntMap { * - faster 10x than ec IntIntHashMap-segment-lock for 4 threads; * - faster 20x than ec IntIntHashMap-global-lock for 4 threads; */ - public static final class IntMapBySegments implements IntMap { + final class IntMapBySegments implements IntMap { private final IntMap[] maps; private final long capacity; @@ -67,7 +72,7 @@ public static final class IntMapBySegments implements IntMap { private static final int DEFAULT_SEGMENTS = IntSet.CPUS * 100; private static final Function DEFAULT_CREATOR = - size -> new IntMapByFixedAddr(size); + size -> new IntMapByFixedAddr(size); @SuppressWarnings("static-access") private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java index b6dc5cc4fe..13de0d935f 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java @@ -32,21 +32,24 @@ public interface IntSet { - public boolean add(int key); - public boolean remove(int key); - public boolean contains(int key); + boolean add(int key); - public void clear(); - public int size(); + boolean remove(int key); - public boolean concurrent(); + boolean contains(int key); + + void clear(); + + int size(); + + boolean concurrent(); /** * NOTE: IntSetBySegments(backend by IntSetByFixedAddr) is: * - slower 2.5x than IntSetByFixedAddr for single thread; * - slower 2.0x than IntSetByFixedAddr for 4 threads; */ - public static final class IntSetBySegments implements IntSet { + final class IntSetBySegments implements IntSet { private final IntSet[] sets; private final long capacity; @@ -58,7 +61,7 @@ public static final class IntSetBySegments implements IntSet { private static final int DEFAULT_SEGMENTS = IntSet.CPUS * 100; private static final Function DEFAULT_CREATOR = - size -> new IntSetByFixedAddr4Unsigned(size); + size -> new IntSetByFixedAddr4Unsigned(size); @SuppressWarnings("static-access") private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET; @@ -208,7 +211,7 @@ public static final class IntSetByFixedAddr implements IntSet { public IntSetByFixedAddr(int numBits) { this.numBitsUnsigned = numBits; this.numBits = numBits * 2L; - this.bits = new long[IntSet.bits2words(this.numBits)];; + this.bits = new long[IntSet.bits2words(this.numBits)]; this.size = new AtomicInteger(); } @@ -305,7 +308,7 @@ public static final class IntSetByFixedAddr4Unsigned implements IntSet { public IntSetByFixedAddr4Unsigned(int numBits) { this.numBits = numBits; - this.bits = new long[IntSet.bits2words(numBits)];; + this.bits = new long[IntSet.bits2words(numBits)]; this.size = new AtomicInteger(); } From a5a949045fb3ea256de7961780a25e852933055b Mon Sep 17 00:00:00 2001 From: yuanbingze Date: Tue, 3 May 2022 15:50:23 +0800 Subject: [PATCH 2/7] fix switch issue --- .../traversal/optimize/TraversalUtil.java | 20 +++++++++++-------- .../com/baidu/hugegraph/util/ConfigUtil.java | 4 ++-- .../com/baidu/hugegraph/util/Consumers.java | 4 +++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java index 549bb6680d..402e86345b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java @@ -374,7 +374,6 @@ private static Relation convCompare2Relation(HugeGraph graph, convCompare2UserpropRelation(graph, type, has); } - private static Relation convCompare2SyspropRelation(HugeGraph graph, HugeType type, HasContainer has) { @@ -398,9 +397,9 @@ private static Relation convCompare2SyspropRelation(HugeGraph graph, return Condition.lte(key, value); case neq: return Condition.neq(key, value); + default: + throw newUnsupportedPredicate(has.getPredicate()); } - - throw newUnsupportedPredicate(has.getPredicate()); } private static Relation convCompare2UserpropRelation(HugeGraph graph, @@ -427,9 +426,9 @@ private static Relation convCompare2UserpropRelation(HugeGraph graph, return Condition.lte(pkeyId, value); case neq: return Condition.neq(pkeyId, value); + default: + throw newUnsupportedPredicate(has.getPredicate()); } - - throw newUnsupportedPredicate(has.getPredicate()); } private static Condition convRelationType2Relation(HugeGraph graph, @@ -470,6 +469,8 @@ public static Condition convIn2Relation(HugeGraph graph, return Condition.in(hugeKey, valueList); case without: return Condition.nin(hugeKey, valueList); + default: + throw newUnsupportedPredicate(has.getPredicate()); } } else { valueList = new ArrayList<>(values); @@ -481,10 +482,10 @@ public static Condition convIn2Relation(HugeGraph graph, return Condition.in(pkey.id(), valueList); case without: return Condition.nin(pkey.id(), valueList); + default: + throw newUnsupportedPredicate(has.getPredicate()); } } - - throw newUnsupportedPredicate(has.getPredicate()); } public static Condition convContains2Relation(HugeGraph graph, @@ -903,7 +904,10 @@ private static Number predicateNumber(String value) { value = JsonUtil.fromJson(value, String.class); } return DateUtil.parse(value).getTime(); - } catch (Exception ignored) {} + } catch (Exception ignored) { + // @todo + // ignored + } } throw new HugeException( diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java index e120df6f9e..5dea629106 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/ConfigUtil.java @@ -58,8 +58,8 @@ public static void checkGremlinConfig(String conf) { try { FileBasedConfigurationBuilder builder = - new FileBasedConfigurationBuilder(YAMLConfiguration.class) - .configure(params.fileBased().setFileName(conf)); + new FileBasedConfigurationBuilder(YAMLConfiguration.class) + .configure(params.fileBased().setFileName(conf)); YAMLConfiguration config = (YAMLConfiguration) builder.getConfiguration(); List> nodes = diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java index c00d9f48e3..d833ea0975 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Consumers.java @@ -115,7 +115,9 @@ private void run() { this.consume(); } assert this.ending; - while (this.consume()); + while (this.consume()){ + // ignore + } LOG.debug("Worker finished"); } From a76dc3a174c240eb04de52ca707b79c352dbed04 Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 4 May 2022 12:04:47 +0800 Subject: [PATCH 3/7] recover old style --- .../traversal/algorithm/HugeTraverser.java | 14 ++++++++------ .../algorithm/JaccardSimilarTraverser.java | 2 +- .../traversal/algorithm/OltpTraverser.java | 4 +++- .../traversal/algorithm/ShortestPathTraverser.java | 6 ++++-- .../traversal/optimize/TraversalUtil.java | 3 +-- .../baidu/hugegraph/util/collection/IntMap.java | 2 +- .../baidu/hugegraph/util/collection/IntSet.java | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java index 4192dfec48..612e2eddff 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java @@ -360,9 +360,10 @@ public static void checkCapacity(long capacity, long access, public static void checkSkipDegree(long skipDegree, long degree, long capacity) { - E.checkArgument(skipDegree >= 0L && skipDegree <= Query.DEFAULT_CAPACITY, - "The skipped degree must be in [0, %s], but got '%s'", - Query.DEFAULT_CAPACITY, skipDegree); + E.checkArgument(skipDegree >= 0L && + skipDegree <= Query.DEFAULT_CAPACITY , + "The skipped degree must be in [0, %s], but got '%s'", + Query.DEFAULT_CAPACITY, skipDegree); if (capacity != NO_LIMIT) { E.checkArgument(degree != NO_LIMIT && degree < capacity, "The max degree must be < capacity"); @@ -377,9 +378,10 @@ public static void checkSkipDegree(long skipDegree, long degree, } } - public static > Map topN(Map map, boolean sorted, long limit) { - + public static > Map topN( + Map map, + boolean sorted, + long limit) { if (sorted) { map = CollectionUtil.sortByValue(map, false); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java index 81757214ac..a0b3d2d9aa 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/JaccardSimilarTraverser.java @@ -42,7 +42,7 @@ public JaccardSimilarTraverser(HugeGraph graph) { } public double jaccardSimilarity(Id vertex, Id other, Directions dir, - String label, long degree) { + String label, long degree) { E.checkNotNull(vertex, "vertex id"); E.checkNotNull(other, "the other vertex id"); this.checkVertexExist(vertex, "vertex"); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java index 22b323e478..fd84848f04 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java @@ -38,7 +38,9 @@ import com.baidu.hugegraph.iterator.FilterIterator; import com.baidu.hugegraph.util.Consumers; -public abstract class OltpTraverser extends HugeTraverser implements AutoCloseable { + +public abstract class OltpTraverser extends HugeTraverser + implements AutoCloseable { private static final String EXECUTOR_NAME = "oltp"; private static Consumers.ExecutorPool executors; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java index 5a3d85921f..bb3e8460be 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java @@ -177,7 +177,8 @@ public PathSet forward(boolean all) { Id target = edge.id().otherVertexId(); PathSet paths = this.record.findPath(target, - t -> !this.superNode(t, this.direction), all, false); + t -> !this.superNode(t, this.direction), + all, false); if (paths.isEmpty()) { continue; @@ -216,7 +217,8 @@ public PathSet backward(boolean all) { Id target = edge.id().otherVertexId(); PathSet paths = this.record.findPath(target, - t -> !this.superNode(t, opposite), all,false); + t -> !this.superNode(t, opposite), + all, false); if (paths.isEmpty()) { continue; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java index 402e86345b..15e7629065 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java @@ -905,8 +905,7 @@ private static Number predicateNumber(String value) { } return DateUtil.parse(value).getTime(); } catch (Exception ignored) { - // @todo - // ignored + // TODO: improve to throw a exception here } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java index 58d72aeb90..3bd5a14199 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java @@ -72,7 +72,7 @@ final class IntMapBySegments implements IntMap { private static final int DEFAULT_SEGMENTS = IntSet.CPUS * 100; private static final Function DEFAULT_CREATOR = - size -> new IntMapByFixedAddr(size); + size -> new IntMapByFixedAddr(size); @SuppressWarnings("static-access") private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java index 13de0d935f..5a070f1ea9 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java @@ -61,7 +61,7 @@ final class IntSetBySegments implements IntSet { private static final int DEFAULT_SEGMENTS = IntSet.CPUS * 100; private static final Function DEFAULT_CREATOR = - size -> new IntSetByFixedAddr4Unsigned(size); + size -> new IntSetByFixedAddr4Unsigned(size); @SuppressWarnings("static-access") private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET; From 8e4461aff592d6cdf0eab75cdfa35528911fa27e Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 4 May 2022 12:24:02 +0800 Subject: [PATCH 4/7] delete empty line --- .../com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java | 2 +- .../com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java index 612e2eddff..70843a451b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java @@ -361,7 +361,7 @@ public static void checkCapacity(long capacity, long access, public static void checkSkipDegree(long skipDegree, long degree, long capacity) { E.checkArgument(skipDegree >= 0L && - skipDegree <= Query.DEFAULT_CAPACITY , + skipDegree <= Query.DEFAULT_CAPACITY, "The skipped degree must be in [0, %s], but got '%s'", Query.DEFAULT_CAPACITY, skipDegree); if (capacity != NO_LIMIT) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java index fd84848f04..c838337937 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/OltpTraverser.java @@ -38,7 +38,6 @@ import com.baidu.hugegraph.iterator.FilterIterator; import com.baidu.hugegraph.util.Consumers; - public abstract class OltpTraverser extends HugeTraverser implements AutoCloseable { From 4543b2908e5777a33ebfee397cfa08e380cd5cf6 Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 4 May 2022 12:50:39 +0800 Subject: [PATCH 5/7] udpate test code --- .../main/java/com/baidu/hugegraph/unit/core/SerialEnumTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SerialEnumTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SerialEnumTest.java index eb438bebb6..e3afc79471 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SerialEnumTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SerialEnumTest.java @@ -30,7 +30,7 @@ public class SerialEnumTest { @Test public void testRegister() { SerialEnum.register(Cardinality.class); - Assert.assertTrue(SerialEnum.table.containsRow(Cardinality.class)); + Assert.assertTrue(SerialEnum.TABLE.containsRow(Cardinality.class)); } @Test From 2fb4629c5444c285b770efe06b9c204561921a6c Mon Sep 17 00:00:00 2001 From: seagle Date: Mon, 9 May 2022 20:16:18 +0800 Subject: [PATCH 6/7] update alignment --- .../src/main/java/com/baidu/hugegraph/util/Reflection.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java index ea0b2ba4fb..bb29651e80 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java @@ -69,7 +69,7 @@ public class Reflection { try { registerMethodsToFilterMethodTemp = REFLECTION_CLAZZ.getMethod("registerMethodsToFilter", - Class.class, String[].class); + Class.class, String[].class); } catch (NoSuchMethodException e) { LOG.error("Can't find registerMethodsToFilter method", e); } @@ -88,7 +88,7 @@ public static void registerFieldsToFilter(Class containingClass, try { REGISTER_FILEDS_TO_FILTER_METHOD.setAccessible(true); REGISTER_FILEDS_TO_FILTER_METHOD.invoke(REFLECTION_CLAZZ, - containingClass, fieldNames); + containingClass, fieldNames); } catch (IllegalAccessException | InvocationTargetException e) { throw new HugeException( "Failed to register class '%s' fields to filter: %s", @@ -106,7 +106,7 @@ public static void registerMethodsToFilter(Class containingClass, try { REGISTER_METHODS_TO_FILTER_MOTHOD.setAccessible(true); REGISTER_METHODS_TO_FILTER_MOTHOD.invoke(REFLECTION_CLAZZ, - containingClass, methodNames); + containingClass, methodNames); } catch (IllegalAccessException | InvocationTargetException e) { throw new HugeException( "Failed to register class '%s' methods to filter: %s", From 1b6fe171cbe91006d98e604a4556d80cc3722f55 Mon Sep 17 00:00:00 2001 From: seagle Date: Mon, 9 May 2022 21:04:04 +0800 Subject: [PATCH 7/7] update alignment --- .../src/main/java/com/baidu/hugegraph/util/Reflection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java index bb29651e80..4838b4b462 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/Reflection.java @@ -61,7 +61,7 @@ public class Reflection { try { registerFieldsToFilterMethodTemp = REFLECTION_CLAZZ.getMethod("registerFieldsToFilter", - Class.class, String[].class); + Class.class, String[].class); } catch (Throwable e) { LOG.error("Can't find registerFieldsToFilter method", e); }