diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java index 6b48bea0dd..0ab4f638f3 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java @@ -405,7 +405,7 @@ private static void checkUpdate(BatchVertexRequest req) { E.checkArgument(req.updateStrategies != null && !req.updateStrategies.isEmpty(), "Parameter 'update_strategies' can't be empty"); - E.checkArgument(req.createIfNotExist == true, + E.checkArgument(req.createIfNotExist, "Parameter 'create_if_not_exist' " + "dose not support false now"); } @@ -462,6 +462,7 @@ public Object[] properties() { } if (this.id != null) { newProps[appendIndex++] = T.id; + // Keep value++ to avoid code trap newProps[appendIndex++] = this.id; } return newProps; diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/KoutAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/KoutAPI.java index 40bab89193..3101d045a6 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/KoutAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/KoutAPI.java @@ -154,6 +154,7 @@ public String post(@Context GraphManager manager, if (request.withPath) { paths.addAll(results.paths(request.limit)); } + Iterator iter = QueryResults.emptyIterator(); if (request.withVertex && !request.countOnly) { Set ids = new HashSet<>(neighbors); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java index b28a0b1911..5d56169f0e 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java @@ -82,7 +82,7 @@ private String inputPassword() { String notEmptyPrompt = "The admin password can't be empty"; Console console = System.console(); while (true) { - String password = ""; + String password; if (console != null) { char[] chars = console.readPassword(inputPrompt); password = new String(chars); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java index 6b4b205ede..fe548149e9 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java @@ -933,7 +933,7 @@ public void drop() { */ this.close(); } catch (Throwable e) { - LOG.warn("Failed to close graph {}", e, this); + LOG.warn("Failed to close graph {} {}", this, e); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/EntityManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/EntityManager.java index 53b4ba152d..c4b668e619 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/EntityManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/EntityManager.java @@ -118,9 +118,7 @@ public boolean exists(Id id) { Iterator vertices = this.tx().queryVertices(id); if (vertices.hasNext()) { Vertex vertex = vertices.next(); - if (this.label.equals(vertex.label())) { - return true; - } + return this.label.equals(vertex.label()); } return false; } @@ -145,7 +143,7 @@ protected List toList(Iterator vertices) { } private Iterator queryById(List ids) { - Object[] idArray = ids.toArray(new Id[ids.size()]); + Object[] idArray = ids.toArray(new Id[0]); return this.tx().queryVertices(idArray); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeResource.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeResource.java index 027386bde3..e0b5e6993e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeResource.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeResource.java @@ -138,9 +138,7 @@ public boolean filter(ResourceObject resourceObject) { private boolean filter(AuthElement element) { assert this.type.match(element.type()); if (element instanceof Namifiable) { - if (!this.filter((Namifiable) element)) { - return false; - } + return this.filter((Namifiable) element); } return true; } @@ -149,10 +147,7 @@ private boolean filter(Namifiable element) { assert !(element instanceof Typifiable) || this.type.match( ResourceType.from(((Typifiable) element).type())); - if (!this.matchLabel(element.name())) { - return false; - } - return true; + return this.matchLabel(element.name()); } private boolean filter(HugeElement element) { @@ -193,10 +188,7 @@ private boolean matchLabel(String other) { return false; } // It's ok if wildcard match or regular match - if (!this.label.equals(ANY) && !other.matches(this.label)) { - return false; - } - return true; + return this.label.equals(ANY) || other.matches(this.label); } private boolean matchProperties(Map other) { @@ -229,10 +221,7 @@ protected boolean contains(HugeResource other) { if (!this.matchLabel(other.label)) { return false; } - if (!this.matchProperties(other.properties)) { - return false; - } - return true; + return this.matchProperties(other.properties); } @Override @@ -260,9 +249,7 @@ public static boolean allowed(ResourceObject resourceObject) { // Allowed to access system(hidden) schema by anyone if (resourceObject.type().isSchema()) { Namifiable schema = (Namifiable) resourceObject.operated(); - if (Hidden.isHidden(schema.name())) { - return true; - } + return Hidden.isHidden(schema.name()); } return false; @@ -339,19 +326,19 @@ public HugeResource deserialize(JsonParser parser, HugeResource res = new HugeResource(); while (parser.nextToken() != JsonToken.END_OBJECT) { String key = parser.getCurrentName(); - if (key.equals("type")) { + if ("type".equals(key)) { if (parser.nextToken() != JsonToken.VALUE_NULL) { res.type = ctxt.readValue(parser, ResourceType.class); } else { res.type = null; } - } else if (key.equals("label")) { + } else if ("label".equals(key)) { if (parser.nextToken() != JsonToken.VALUE_NULL) { res.label = parser.getValueAsString(); } else { res.label = null; } - } else if (key.equals("properties")) { + } else if ("properties".equals(key)) { if (parser.nextToken() != JsonToken.VALUE_NULL) { @SuppressWarnings("unchecked") Map prop = ctxt.readValue(parser, diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RelationshipManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RelationshipManager.java index 07adb6714b..1fb3232fd5 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RelationshipManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RelationshipManager.java @@ -122,9 +122,7 @@ public boolean exists(Id id) { Iterator edges = this.tx().queryEdges(id); if (edges.hasNext()) { Edge edge = edges.next(); - if (this.label.equals(edge.label())) { - return true; - } + return this.label.equals(edge.label()); } return false; } @@ -161,7 +159,7 @@ protected List toList(Iterator edges) { } private Iterator queryById(List ids) { - Object[] idArray = ids.toArray(new Id[ids.size()]); + Object[] idArray = ids.toArray(new Id[0]); return this.tx().queryEdges(idArray); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/LevelCache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/LevelCache.java index ab29371869..287f0b85a3 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/LevelCache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/LevelCache.java @@ -29,7 +29,7 @@ public final class LevelCache extends AbstractCache { // For multi-layer caches - private final AbstractCache caches[]; + private final AbstractCache[] caches; @SuppressWarnings("unchecked") public LevelCache(AbstractCache lavel1, diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java index 0e3295a76e..60111f57c2 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java @@ -134,12 +134,13 @@ public static String escape(char splitor, char escape, String... values) { public static String[] unescape(String id, String splitor, String escape) { /* - * Note that the `splitor`/`escape` maybe special characters in regular + * Note that the `splitter`/`escape` maybe special characters in regular * expressions, but this is a frequently called method, for faster * execution, we forbid the use of special characters as delimiter * or escape sign. + * * The `limit` param -1 in split method can ensure empty string be - * splited to a part. + * split to a part. */ String[] parts = id.split("(? { assert v2 != null; /* * TODO: we still have no way to determine accurately, since - * some backends may scan with token(column) like cassandra. + * some backends may scan with token(column) like cassandra. */ return true; }); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java index ac7a6124ca..a2fda90dad 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java @@ -60,6 +60,7 @@ public class ConditionQuery extends IdQuery { public static final String INDEX_SYM_EMPTY = "\u0002"; public static final char INDEX_SYM_MAX = '\u0003'; + // Note: here we use "new String" to distinguish normal string code public static final String INDEX_VALUE_NULL = new String(""); public static final String INDEX_VALUE_EMPTY = new String(""); @@ -74,7 +75,7 @@ public class ConditionQuery extends IdQuery { private static final List EMPTY_CONDITIONS = ImmutableList.of(); - // Conditions will be concated with `and` by default + // Conditions will be contacted with `and` by default private List conditions = EMPTY_CONDITIONS; private OptimizedType optimizedType = OptimizedType.NONE; @@ -659,8 +660,6 @@ public static String concatValues(Object value) { return concatValues((List) value); } else if (needConvertNumber(value)) { return LongEncoding.encodeNumber(value); - } else if (value == INDEX_VALUE_NULL) { - return INDEX_SYM_NULL; } else { return escapeSpecialValueIfNeeded(value.toString()); } @@ -677,6 +676,8 @@ private static String escapeSpecialValueIfNeeded(String value) { value = INDEX_SYM_EMPTY; } else if (value == INDEX_VALUE_EMPTY) { value = ""; + } else if (value == INDEX_VALUE_NULL) { + value = INDEX_SYM_NULL; } else { char ch = value.charAt(0); if (ch <= INDEX_SYM_MAX) { @@ -822,8 +823,8 @@ private static boolean numberEquals(Object number1, Object number2) { // Otherwise convert to BigDecimal to make two numbers comparable Number n1 = NumericUtil.convertToNumber(number1); Number n2 = NumericUtil.convertToNumber(number2); - BigDecimal b1 = new BigDecimal(n1.doubleValue()); - BigDecimal b2 = new BigDecimal(n2.doubleValue()); + BigDecimal b1 = BigDecimal.valueOf(n1.doubleValue()); + BigDecimal b2 = BigDecimal.valueOf(n2.doubleValue()); return b1.compareTo(b2) == 0; } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java index b33d6d3089..d112a73ec8 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java @@ -91,9 +91,7 @@ public static List flatten(ConditionQuery query, continue; } ConditionQuery cq = newQueryFromRelations(query, relations); - if (cq != null) { - queries.add(cq); - } + queries.add(cq); } return queries; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java index a46b92da07..103a27f0b7 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java @@ -42,6 +42,7 @@ public class Query implements Cloneable { + // TODO: we should better not use Long.Max as the unify limit number public static final long NO_LIMIT = Long.MAX_VALUE; public static final long COMMIT_BATCH = 500L; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java index 5e70f6ae31..c1cf47aa1a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java @@ -131,9 +131,7 @@ public Iterator keepInputOrderIfNeeded( ids = map.keySet(); } - return new MapperIterator<>(ids.iterator(), id -> { - return map.get(id); - }); + return new MapperIterator<>(ids.iterator(), map::get); } private boolean mustSortByInputIds() { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java index bbcd963622..6c33e6d802 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java @@ -191,10 +191,7 @@ public boolean equals(Object obj) { if (this.columns.size() != other.columns.size()) { return false; } - if (!this.columns.containsAll(other.columns)) { - return false; - } - return true; + return this.columns.containsAll(other.columns); } protected static final class BinaryId implements Id { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java index 19b6bfb684..abeea5f046 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java @@ -300,8 +300,7 @@ public BytesBuffer writeBytes(byte[] bytes) { public byte[] readBytes() { int length = this.readVInt(); assert length >= 0; - byte[] bytes = this.read(length); - return bytes; + return this.read(length); } public BytesBuffer writeBigBytes(byte[] bytes) { @@ -317,8 +316,7 @@ public BytesBuffer writeBigBytes(byte[] bytes) { public byte[] readBigBytes() { int length = this.readVInt(); assert length >= 0; - byte[] bytes = this.read(length); - return bytes; + return this.read(length); } public BytesBuffer writeStringRaw(String val) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java index f0a2d227f1..86e1fedaa7 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java @@ -34,12 +34,14 @@ public class SerializerFactory { public static AbstractSerializer serializer(String name) { name = name.toLowerCase(); - if ("binary".equals(name)) { - return new BinarySerializer(); - } else if ("binaryscatter".equals(name)) { - return new BinaryScatterSerializer(); - } else if ("text".equals(name)) { - return new TextSerializer(); + switch (name) { + case "binary": + return new BinarySerializer(); + case "binaryscatter": + return new BinaryScatterSerializer(); + case "text": + return new TextSerializer(); + default: } Class clazz = serializers.get(name); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java index 0c281de24c..a87c134fa2 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java @@ -130,8 +130,8 @@ public String toString() { private final List subRows; // NOTE: selfChanged is false when the row has not changed but subRows has. - private boolean selfChanged = true; - private boolean olap = false; + private boolean selfChanged; + private boolean olap; public TableBackendEntry(Id id) { this(null, id); @@ -149,6 +149,7 @@ public TableBackendEntry(Row row) { this.row = row; this.subRows = new ArrayList<>(); this.selfChanged = true; + this.olap = false; } @Override @@ -195,6 +196,7 @@ public void olap(boolean olap) { this.olap = olap; } + @Override public boolean olap() { return this.olap; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java index c5cd9fd9bb..98c428642d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java @@ -187,7 +187,7 @@ public void append(TextBackendEntry entry) { } // TODO: ensure the old value is a list and json format (for index) - if (oldValue.equals("[]")) { + if ("[]".equals(oldValue)) { this.column(col.getKey(), newValue); continue; } @@ -222,12 +222,11 @@ public void eliminate(TextBackendEntry entry) { } // TODO: ensure the old value is a list and json format (for index) - List values = new ArrayList<>(); @SuppressWarnings("unchecked") List oldValues = JsonUtil.fromJson(oldValue, List.class); @SuppressWarnings("unchecked") List newValues = JsonUtil.fromJson(newValue, List.class); - values.addAll(oldValues); + List values = new ArrayList<>(oldValues); values.removeAll(newValues); // Update the old value this.column(col.getKey(), JsonUtil.toJson(values)); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java index 1388f0a689..e78d341f7c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java @@ -278,6 +278,7 @@ public boolean matched(Query query) { for (Condition cond : cq.conditions()) { if (cond.equals(BOTH_COND)) { direction = Directions.BOTH; + break; } } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java index d01d1bf207..d497cb9e6a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java @@ -283,7 +283,7 @@ protected void updateIndex(Id ilId, HugeElement element, boolean removed) { break; case UNIQUE: value = ConditionQuery.concatValues(allPropValues); - assert !value.equals(""); + assert !"".equals(value); Id id = element.id(); // TODO: add lock for updating unique index if (!removed && this.existUniqueValue(indexLabel, value, id)) { @@ -665,7 +665,7 @@ private IdHolder doIndexQueryBatch(IndexLabel indexLabel, // Iterate one batch, and keep iterator position Set ids = InsertionOrderUtil.newSet(); - while ((ids.size() < batch || batch == Query.NO_LIMIT) && + while ((batch == Query.NO_LIMIT || ids.size() < batch) && entries.hasNext()) { HugeIndex index = this.serializer.readIndex(graph(), query, entries.next()); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java index 994476378d..0adbaa3124 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java @@ -2010,6 +2010,7 @@ private void traverseByLabel(SchemaLabel label, if (label.enableLabelIndex()) { // Support label index, query by label index by paging + assert query instanceof ConditionQuery; ((ConditionQuery) query).eq(HugeKeys.LABEL, label.id()); Iterator iter = fetcher.apply(query); try { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphIoRegistry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphIoRegistry.java index f6dac37bff..0ae0d59c86 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphIoRegistry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphIoRegistry.java @@ -24,11 +24,11 @@ public class HugeGraphIoRegistry extends AbstractIoRegistry { - private static final HugeGraphIoRegistry instance = + private static final HugeGraphIoRegistry INSTANCE = new HugeGraphIoRegistry(); public static HugeGraphIoRegistry instance() { - return instance; + return INSTANCE; } private HugeGraphIoRegistry() { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java index ffca6e66ac..338b45fb2e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java @@ -200,7 +200,7 @@ private boolean hasSameProperties(EdgeLabel existedEdgeLabel) { return false; } } else { // this false - if (existedEdgeLabel.enableLabelIndex() == true) { + if (existedEdgeLabel.enableLabelIndex()) { return false; } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java index fdeafbca11..75fb3285c1 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java @@ -200,15 +200,10 @@ private boolean hasSameProperties(VertexLabel existedVertexLabel) { // this.enableLabelIndex == null, it means true. if (this.enableLabelIndex == null || this.enableLabelIndex) { - if (!existedVertexLabel.enableLabelIndex()) { - return false; - } + return existedVertexLabel.enableLabelIndex(); } else { // this.enableLabelIndex is false - if (existedVertexLabel.enableLabelIndex() == true) { - return false; - } + return !existedVertexLabel.enableLabelIndex(); } - return true; } @Override diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java index 59d3645e8d..f3570c3ebc 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java @@ -279,13 +279,10 @@ public HugeEdge constructEdge(String label, HugeVertex vertex, if (elemKeys.id() != null) { throw Edge.Exceptions.userSuppliedIdsNotSupported(); } - Id id = HugeElement.getIdValue(elemKeys.id()); + Id id = null; // Check target vertex E.checkArgumentNotNull(vertex, "Target vertex can't be null"); - E.checkArgument(vertex instanceof HugeVertex, - "Target vertex must be an instance of HugeVertex"); - // Check label E.checkArgument(label != null && !label.isEmpty(), "Edge label can't be null or empty"); @@ -322,11 +319,7 @@ public HugeEdge constructEdge(String label, HugeVertex vertex, // Set properties ElementHelper.attachProperties(edge, keyValues); - // Set id if it not exists - if (id == null) { - edge.assignId(); - } - + edge.assignId(); return edge; } @@ -543,7 +536,6 @@ protected boolean ensureFilledProperties(boolean throwIfNotExist) { @Override public Iterator> properties(String... keys) { // TODO: Compatible with TinkerPop properties() (HugeGraph-742) - this.ensureFilledProperties(true); // Capacity should be about the following size @@ -612,7 +604,8 @@ public boolean valid() { public HugeVertex prepareRemoved() { // NOTE: clear edges/properties of the cloned vertex and return HugeVertex vertex = this.clone(); - vertex.removed(true); /* Remove self */ + // Remove self + vertex.removed(true); vertex.resetEdges(); vertex.resetProperties(); return vertex; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java index b7d6bd60a9..449877beaa 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java @@ -710,7 +710,7 @@ private Iterator> queryTask(Map conditions, private Iterator> queryTask(List ids) { return this.call(() -> { - Object[] idArray = ids.toArray(new Id[ids.size()]); + Object[] idArray = ids.toArray(new Id[0]); Iterator vertices = this.tx().queryVertices(idArray); Iterator> tasks = new MapperIterator<>(vertices, HugeTask::fromVertex); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskStatus.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskStatus.java index 3107e13ee3..ec5053d31f 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskStatus.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskStatus.java @@ -48,7 +48,7 @@ public enum TaskStatus implements SerialEnum { public static final Set COMPLETED_STATUSES = ImmutableSet.of( TaskStatus.SUCCESS, TaskStatus.CANCELLED, TaskStatus.FAILED); - private byte status = 0; + private byte status; private String name; static { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/steps/EdgeStep.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/steps/EdgeStep.java index b1d7ad1dad..2c27eece39 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/steps/EdgeStep.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/steps/EdgeStep.java @@ -72,6 +72,7 @@ public EdgeStep(HugeGraph g, Directions direction, List labels, public EdgeStep(HugeGraph g, Directions direction, List labels, Map properties, long degree, long skipDegree) { + E.checkArgumentNotNull(g, "The graph can't be null"); E.checkArgument(degree == NO_LIMIT || degree > 0L, "The max degree must be > 0 or == -1, but got: %s", degree); @@ -122,8 +123,7 @@ public long skipDegree() { public Id[] edgeLabels() { int elsSize = this.labels.size(); - Id[] edgeLabels = this.labels.keySet().toArray(new Id[elsSize]); - return edgeLabels; + return this.labels.keySet().toArray(new Id[elsSize]); } public void swithDirection() { @@ -131,8 +131,7 @@ public void swithDirection() { } public long limit() { - long limit = this.skipDegree > 0L ? this.skipDegree : this.degree; - return limit; + return this.skipDegree > 0L ? this.skipDegree : this.degree; } @Override 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 8ca8191c94..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 @@ -35,8 +35,11 @@ import com.baidu.hugegraph.HugeException; /** - * ScriptTraversal encapsulates a {@link ScriptEngine} and a script which is compiled into a {@link Traversal} at {@link Admin#applyStrategies()}. - * This is useful for serializing traversals as the compilation can happen on the remote end where the traversal will ultimately be processed. + * ScriptTraversal encapsulates a {@link ScriptEngine} and a script which is + * compiled into a {@link Traversal} at {@link Admin#applyStrategies()}. + * + * This is useful for serializing traversals as the compilation can happen on + * the remote end where the traversal will ultimately be processed. * * @author Marko A. Rodriguez (http://markorodriguez.com) */ 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 e9d9c49c54..311db733e1 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 @@ -453,8 +453,8 @@ public static Condition convIn2Relation(HugeGraph graph, String originKey = has.getKey(); if (values.size() > 1) { - E.checkArgument(!originKey.equals(T.key) && - !originKey.equals(T.value), + E.checkArgument(!originKey.equals(T.key.getAccessor()) && + !originKey.equals(T.value.getAccessor()), "Not support hasKey() or hasValue() with " + "multiple values"); } @@ -557,11 +557,8 @@ public static Iterator filterResult(Vertex vertex, Directions dir, Iterator edges) { return new FilterIterator<>(edges, edge -> { - if (dir == Directions.OUT && vertex.equals(edge.outVertex()) || - dir == Directions.IN && vertex.equals(edge.inVertex())) { - return true; - } - return false; + return dir == Directions.OUT && vertex.equals(edge.outVertex()) || + dir == Directions.IN && vertex.equals(edge.inVertex()); }); } @@ -672,8 +669,7 @@ private static V validPropertyValue(V value, PropertyKey pkey) { E.checkArgument(false, "Invalid data type of query value in %s, " + "expect %s for '%s', actual got %s", - value, pkey.dataType(), pkey.name(), - value == null ? null : classes); + value, pkey.dataType(), pkey.name(), classes); } @SuppressWarnings("unchecked") @@ -905,7 +901,7 @@ private static Number predicateNumber(String value) { } private static Number[] predicateNumbers(String value, int count) { - List values = predicateArgs(value); + List values = predicateArgs(value); if (values.size() != count) { throw new HugeException("Invalid numbers size %s, expect %s", values.size(), count); @@ -921,13 +917,13 @@ private static Number[] predicateNumbers(String value, int count) { // pass } if (v instanceof Number) { - values.set(i, (Number) v); + values.set(i, v); continue; } throw new HugeException( "Invalid value '%s', expect a list of number", value); } - return values.toArray(new Number[values.size()]); + return values.toArray(new Number[0]); } @SuppressWarnings("unchecked") diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java index f232c77bd5..9a67432de5 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java @@ -57,8 +57,8 @@ public class BaseApiTest { - private static String BASE_URL = "http://127.0.0.1:8080"; - private static String GRAPH = "hugegraph"; + private static final String BASE_URL = "http://127.0.0.1:8080"; + private static final String GRAPH = "hugegraph"; private static final String USERNAME = "admin"; private static final String PASSWORD = "pa"; @@ -643,7 +643,7 @@ public static T assertMapContains(Map map, String key) { break; } } - Assert.assertTrue(message, found != null); + Assert.assertNotNull(message, found); return found; } }