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..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) { @@ -636,7 +636,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..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 @@ -41,7 +41,6 @@ public JaccardSimilarTraverser(HugeGraph graph) { super(graph); } - public double jaccardSimilarity(Id vertex, Id other, Directions dir, String label, long degree) { E.checkNotNull(vertex, "vertex id"); 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 { 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..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 @@ -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(); @@ -373,7 +374,6 @@ private static Relation convCompare2Relation(HugeGraph graph, convCompare2UserpropRelation(graph, type, has); } - private static Relation convCompare2SyspropRelation(HugeGraph graph, HugeType type, HasContainer has) { @@ -397,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, @@ -426,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, @@ -469,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); @@ -480,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, @@ -902,7 +904,9 @@ private static Number predicateNumber(String value) { value = JsonUtil.fromJson(value, String.class); } return DateUtil.parse(value).getTime(); - } catch (Exception ignored) {} + } catch (Exception ignored) { + // TODO: improve to throw a exception here + } } throw new HugeException( 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..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,10 +58,9 @@ public static void checkGremlinConfig(String conf) { try { FileBasedConfigurationBuilder builder = - new FileBasedConfigurationBuilder(YAMLConfiguration.class) + new FileBasedConfigurationBuilder(YAMLConfiguration.class) .configure(params.fileBased().setFileName(conf)); - YAMLConfiguration config = (YAMLConfiguration) builder - .getConfiguration(); + 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..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"); } @@ -147,7 +149,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 +172,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 +264,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..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 @@ -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,40 +55,40 @@ public class Reflection { } } - reflectionClazz = reflectionClazzTemp; + REFLECTION_CLAZZ = reflectionClazzTemp; - if (reflectionClazz != null) { + if (REFLECTION_CLAZZ != null) { try { registerFieldsToFilterMethodTemp = - reflectionClazz.getMethod("registerFieldsToFilter", - Class.class, String[].class); + REFLECTION_CLAZZ.getMethod("registerFieldsToFilter", + Class.class, String[].class); } catch (Throwable e) { LOG.error("Can't find registerFieldsToFilter method", e); } try { registerMethodsToFilterMethodTemp = - reflectionClazz.getMethod("registerMethodsToFilter", - Class.class, String[].class); + 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, - containingClass, fieldNames); + REGISTER_FILEDS_TO_FILTER_METHOD.setAccessible(true); + REGISTER_FILEDS_TO_FILTER_METHOD.invoke(REFLECTION_CLAZZ, + containingClass, fieldNames); } catch (IllegalAccessException | InvocationTargetException e) { throw new HugeException( "Failed to register class '%s' fields to filter: %s", @@ -98,15 +98,15 @@ 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, - containingClass, methodNames); + REGISTER_METHODS_TO_FILTER_MOTHOD.setAccessible(true); + REGISTER_METHODS_TO_FILTER_MOTHOD.invoke(REFLECTION_CLAZZ, + containingClass, methodNames); } catch (IllegalAccessException | InvocationTargetException e) { throw new HugeException( "Failed to register class '%s' methods to filter: %s", 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..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 @@ -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; 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..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 @@ -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; @@ -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(); } 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