From e79f1a5e73876b98caefad115a6ba3dcc0e5e83a Mon Sep 17 00:00:00 2001 From: M <87920097+msgui@users.noreply.github.com> Date: Thu, 22 Feb 2024 17:26:15 +0800 Subject: [PATCH] fix(server): clean up the code (#2456) - replace `size() == 0` with `isEmpty()` - remove unnecessary unboxing - remove unnecessary boxing - replace for loop with enhanced for loop - replace lambda with method reference --- .../api/filter/LoadDetectFilter.java | 2 +- .../apache/hugegraph/server/RestServer.java | 2 +- .../store/cassandra/CassandraStore.java | 2 +- .../store/cassandra/CassandraTables.java | 2 +- .../hugegraph/auth/StandardAuthManager.java | 2 +- .../backend/cache/CachedGraphTransaction.java | 2 +- .../org/apache/hugegraph/backend/id/Id.java | 2 +- .../hugegraph/backend/query/Condition.java | 4 +-- .../backend/query/ConditionQuery.java | 10 +++--- .../hugegraph/backend/query/QueryResults.java | 2 +- .../backend/serializer/BinarySerializer.java | 2 +- .../backend/serializer/TableSerializer.java | 2 +- .../backend/serializer/TextSerializer.java | 4 +-- .../backend/store/memory/InMemoryDBTable.java | 4 +-- .../store/memory/InMemoryDBTables.java | 2 +- .../hugegraph/backend/store/ram/RamTable.java | 6 ++-- .../backend/tx/GraphIndexTransaction.java | 2 +- .../backend/tx/GraphTransaction.java | 22 ++++++------- .../job/algorithm/comm/LouvainTraverser.java | 8 ++--- .../job/algorithm/comm/LpaAlgorithm.java | 2 +- .../job/algorithm/rank/PageRankAlgorithm.java | 2 +- .../apache/hugegraph/schema/EdgeLabel.java | 2 +- .../schema/builder/VertexLabelBuilder.java | 2 +- .../hugegraph/structure/HugeElement.java | 2 +- .../hugegraph/structure/HugeVertex.java | 2 +- .../algorithm/NeighborRankTraverser.java | 2 +- .../traversal/optimize/HugeVertexStep.java | 2 +- .../optimize/HugeVertexStepByBatch.java | 6 ++-- .../optimize/HugeVertexStepStrategy.java | 8 ++--- .../hugegraph/util/collection/IntMap.java | 4 +-- .../hugegraph/util/collection/IntSet.java | 4 +-- .../backend/store/hbase/HbaseSerializer.java | 2 +- .../backend/store/hbase/HbaseSessions.java | 2 +- .../backend/store/hbase/HbaseStore.java | 9 ++--- .../backend/store/mysql/MysqlTables.java | 2 +- .../backend/store/palo/PaloTables.java | 2 +- .../postgresql/PostgresqlSerializer.java | 4 +-- .../store/rocksdbsst/RocksDBSstSessions.java | 2 +- .../store/scylladb/ScyllaDBTablesWithMV.java | 2 +- .../traversers/JaccardSimilarityApiTest.java | 8 ++--- .../apache/hugegraph/core/VertexCoreTest.java | 2 +- .../hugegraph/unit/core/DirectionsTest.java | 4 +-- .../org/apache/hugegraph/unit/id/IdTest.java | 30 +++++------------ .../serializer/TableBackendEntryTest.java | 8 ++--- .../unit/util/collection/IdSetTest.java | 5 +-- .../unit/util/collection/IntMapTest.java | 33 +++++++------------ 46 files changed, 101 insertions(+), 134 deletions(-) diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java index 7bda2b7562..7ee5e7c0f7 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java @@ -95,7 +95,7 @@ public void filter(ContainerRequestContext context) { public static boolean isWhiteAPI(ContainerRequestContext context) { List segments = context.getUriInfo().getPathSegments(); - E.checkArgument(segments.size() > 0, "Invalid request uri '%s'", + E.checkArgument(!segments.isEmpty(), "Invalid request uri '%s'", context.getUriInfo().getPath()); String rootPath = segments.get(0).getPath(); return WHITE_API_LIST.contains(rootPath); diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/RestServer.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/RestServer.java index 90e4e19f4c..403c788632 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/RestServer.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/RestServer.java @@ -97,7 +97,7 @@ private HttpServer configHttpServer(URI uri, ResourceConfig rc) { } Collection listeners = server.getListeners(); - E.checkState(listeners.size() > 0, + E.checkState(!listeners.isEmpty(), "Http Server should have some listeners, but now is none"); NetworkListener listener = listeners.iterator().next(); diff --git a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraStore.java b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraStore.java index 8e5fe4d9dc..85a592945e 100644 --- a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraStore.java +++ b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraStore.java @@ -538,7 +538,7 @@ private static Map parseReplica(HugeConfig conf) { private static int convertFactor(String factor) { try { - return Integer.valueOf(factor); + return Integer.parseInt(factor); } catch (NumberFormatException e) { throw new BackendException( "Expect int factor value for SimpleStrategy, " + diff --git a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java index 5f7490cb1f..40b7e5a19d 100644 --- a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java +++ b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java @@ -447,7 +447,7 @@ public void delete(CassandraSessionPool.Session session, // Let super class do delete if not deleting edge by label List idParts = this.idColumnValue(entry.id()); - if (idParts.size() > 1 || entry.columns().size() > 0) { + if (idParts.size() > 1 || !entry.columns().isEmpty()) { super.delete(session, entry); return; } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java index 60aaf9aab2..6f84cbf290 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java @@ -180,7 +180,7 @@ public HugeUser findUser(String name) { } List users = this.users.query(P.NAME, name, 2L); - if (users.size() > 0) { + if (!users.isEmpty()) { assert users.size() == 1; user = users.get(0); this.usersCache.update(username, user); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedGraphTransaction.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedGraphTransaction.java index 89f047baed..83ab7f51ad 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedGraphTransaction.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedGraphTransaction.java @@ -350,7 +350,7 @@ protected Iterator queryEdgesFromBackend(Query query) { edges.add(rs.next()); } - if (edges.size() == 0) { + if (edges.isEmpty()) { this.edgesCache.update(cacheKey, Collections.emptyList()); } else if (edges.size() <= MAX_CACHE_EDGES_PER_QUERY) { this.edgesCache.update(cacheKey, edges); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/Id.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/Id.java index 4d615565aa..b0e5613495 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/Id.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/Id.java @@ -67,7 +67,7 @@ public char prefix() { } public static IdType valueOfPrefix(String id) { - E.checkArgument(id != null && id.length() > 0, + E.checkArgument(id != null && !id.isEmpty(), "Invalid id '%s'", id); switch (id.charAt(0)) { case 'L': diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java index 579b349c85..5b2fb1d841 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java @@ -52,9 +52,7 @@ public enum ConditionType { public enum RelationType implements BiPredicate { - EQ("==", (v1, v2) -> { - return equals(v1, v2); - }), + EQ("==", RelationType::equals), GT(">", (v1, v2) -> { return compare(v1, v2) > 0; diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java index f306d38798..2f950c28fa 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java @@ -241,12 +241,12 @@ public T condition(Object key) { if (valuesEQ.isEmpty() && valuesIN.isEmpty()) { return null; } - if (valuesEQ.size() == 1 && valuesIN.size() == 0) { + if (valuesEQ.size() == 1 && valuesIN.isEmpty()) { @SuppressWarnings("unchecked") T value = (T) valuesEQ.get(0); return value; } - if (valuesEQ.size() == 0 && valuesIN.size() == 1) { + if (valuesEQ.isEmpty() && valuesIN.size() == 1) { @SuppressWarnings("unchecked") T value = (T) valuesIN.get(0); return value; @@ -273,7 +273,7 @@ public T condition(Object key) { } } - if (intersectValues.size() == 0) { + if (intersectValues.isEmpty()) { return null; } E.checkState(intersectValues.size() == 1, @@ -516,7 +516,7 @@ public boolean hasNeqCondition() { public boolean matchUserpropKeys(List keys) { Set conditionKeys = this.userpropKeys(); - return keys.size() > 0 && conditionKeys.containsAll(keys); + return !keys.isEmpty() && conditionKeys.containsAll(keys); } @Override @@ -808,7 +808,7 @@ public boolean checkRangeIndex(HugeElement element, Condition cond) { */ boolean hasRightValue = removeFieldValue(fieldValues, property.value()); - if (fieldValues.size() > 0) { + if (!fieldValues.isEmpty()) { this.addLeftIndex(element.id(), propId, fieldValues); } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/QueryResults.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/QueryResults.java index ca457a63a7..a03e5c9aee 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/QueryResults.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/QueryResults.java @@ -59,7 +59,7 @@ private QueryResults(Iterator results) { } public void setQuery(Query query) { - if (this.queries.size() > 0) { + if (!this.queries.isEmpty()) { this.queries.clear(); } this.addQuery(query); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java index 515a6cfda3..9c95dbf233 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java @@ -527,7 +527,7 @@ public HugeEdge readEdge(HugeGraph graph, BackendEntry bytesEntry) { @Override public BackendEntry writeIndex(HugeIndex index) { BinaryBackendEntry entry; - if (index.fieldValues() == null && index.elementIds().size() == 0) { + if (index.fieldValues() == null && index.elementIds().isEmpty()) { /* * When field-values is null and elementIds size is 0, it is * meaningful for deletion of index data by index label. diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java index fbca2a9a19..f5c31d26fd 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java @@ -308,7 +308,7 @@ public BackendEntry writeIndex(HugeIndex index) { * When field-values is null and elementIds size is 0, it is * meaningful for deletion of index data in secondary/range index. */ - if (index.fieldValues() == null && index.elementIds().size() == 0) { + if (index.fieldValues() == null && index.elementIds().isEmpty()) { entry.column(HugeKeys.INDEX_LABEL_ID, index.indexLabel().longId()); } else { entry.column(HugeKeys.FIELD_VALUES, index.fieldValues()); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TextSerializer.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TextSerializer.java index b3e1737212..a1ef38cffd 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TextSerializer.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TextSerializer.java @@ -355,7 +355,7 @@ public HugeEdge readEdge(HugeGraph graph, BackendEntry backendEntry) { @Override public BackendEntry writeIndex(HugeIndex index) { TextBackendEntry entry = newBackendEntry(index.type(), index.id()); - if (index.fieldValues() == null && index.elementIds().size() == 0) { + if (index.fieldValues() == null && index.elementIds().isEmpty()) { /* * When field-values is null and elementIds size is 0, it is * meaningful for deletion of index data in secondary/range index. @@ -497,7 +497,7 @@ private Query writeQueryEdgePrefixCondition(ConditionQuery cq) { } } - if (condParts.size() > 0) { + if (!condParts.isEmpty()) { // Conditions to id String id = EdgeId.concat(condParts.toArray(new String[0])); return new IdPrefixQuery(cq, IdGenerator.of(id)); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTable.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTable.java index fb6ef7c021..4768080905 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTable.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTable.java @@ -232,7 +232,7 @@ private Iterator queryByRange(ConditionQuery query) { protected Map queryById(Collection ids, Map entries) { - assert ids.size() > 0; + assert !ids.isEmpty(); Map rs = InsertionOrderUtil.newMap(); for (Id id : ids) { @@ -262,7 +262,7 @@ protected Map queryByIdRange(Id start, protected Map queryByFilter( Collection conditions, Map entries) { - assert conditions.size() > 0; + assert !conditions.isEmpty(); Map rs = new HashMap<>(); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTables.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTables.java index 0fdd36f09c..19321a5514 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTables.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/memory/InMemoryDBTables.java @@ -181,7 +181,7 @@ protected Map queryByIdRange( private Map queryEdgeById( Collection ids, boolean prefix, Map entries) { - assert ids.size() > 0; + assert !ids.isEmpty(); Map rs = InsertionOrderUtil.newMap(); for (Id id : ids) { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java index f71c44acd1..0e2c58bddc 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java @@ -306,9 +306,7 @@ public Iterator query(Query query) { ConditionQuery cq = cqs.get(0); return this.query(cq); } - return new FlatMapperIterator<>(cqs.iterator(), cq -> { - return this.query(cq); - }); + return new FlatMapperIterator<>(cqs.iterator(), this::query); } private Iterator query(ConditionQuery query) { @@ -540,7 +538,7 @@ protected long load(Iterator vertices) { private void addVertex(Id vertex) { Id lastId = IdGenerator.ZERO; - if (this.vertices.size() > 0) { + if (!this.vertices.isEmpty()) { lastId = this.vertices.get(this.vertices.size() - 1); } LOG.info("scan from hbase source {} lastId value: {} compare {} size {}", diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java index c11b80fb37..e7f6114400 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java @@ -1704,7 +1704,7 @@ public String toString() { } private static Query parent(Collection queries) { - if (queries.size() > 0) { + if (!queries.isEmpty()) { // Chose the first one as origin query (any one is OK) return queries.iterator().next(); } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java index 26d22e4f4d..b25b705725 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java @@ -180,23 +180,23 @@ public boolean hasUpdate() { public boolean hasUpdate(HugeType type, Action action) { if (type.isVertex()) { if (action == Action.DELETE) { - if (this.removedVertices.size() > 0) { + if (!this.removedVertices.isEmpty()) { return true; } } else { - if (this.addedVertices.size() > 0 || - this.updatedVertices.size() > 0) { + if (!this.addedVertices.isEmpty() || + !this.updatedVertices.isEmpty()) { return true; } } } else if (type.isEdge()) { if (action == Action.DELETE) { - if (this.removedEdges.size() > 0) { + if (!this.removedEdges.isEmpty()) { return true; } } else { - if (this.addedEdges.size() > 0 || - this.updatedEdges.size() > 0) { + if (!this.addedEdges.isEmpty() || + !this.updatedEdges.isEmpty()) { return true; } } @@ -300,16 +300,16 @@ protected final boolean removingEdgeOwner(HugeEdge edge) { @Override protected BackendMutation prepareCommit() { // Serialize and add updates into super.deletions - if (this.removedVertices.size() > 0 || this.removedEdges.size() > 0) { + if (!this.removedVertices.isEmpty() || !this.removedEdges.isEmpty()) { this.prepareDeletions(this.removedVertices, this.removedEdges); } - if (this.addedProps.size() > 0 || this.removedProps.size() > 0) { + if (!this.addedProps.isEmpty() || !this.removedProps.isEmpty()) { this.prepareUpdates(this.addedProps, this.removedProps); } // Serialize and add updates into super.additions - if (this.addedVertices.size() > 0 || this.addedEdges.size() > 0) { + if (!this.addedVertices.isEmpty() || !this.addedEdges.isEmpty()) { this.prepareAdditions(this.addedVertices, this.addedEdges); } @@ -690,7 +690,7 @@ public void removeVertex(HugeVertex vertex) { // Override vertices in local `addedVertices` this.addedVertices.remove(vertex.id()); // Force load vertex to ensure all properties are loaded (refer to #2181) - if (vertex.schemaLabel().indexLabels().size() > 0) { + if (!vertex.schemaLabel().indexLabels().isEmpty()) { vertex.forceLoad(); } // Collect the removed vertex @@ -710,7 +710,7 @@ public Iterator queryAdjacentVertices(Iterator edges) { for (Edge edge : batchEdges) { vertexIds.add(((HugeEdge) edge).otherVertex().id()); } - assert vertexIds.size() > 0; + assert !vertexIds.isEmpty(); return this.queryAdjacentVertices(vertexIds.toArray()); }); } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LouvainTraverser.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LouvainTraverser.java index 6b125d6895..d30e798d41 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LouvainTraverser.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LouvainTraverser.java @@ -536,7 +536,7 @@ private boolean allMembersExist(Collection>> comms, for (Pair> comm : comms) { all.removeAll(comm.getRight()); } - if (all.size() > 0) { + if (!all.isEmpty()) { LOG.warn("Lost members of last pass: {}", all); } return all.isEmpty(); @@ -649,7 +649,7 @@ public Collection showCommunity(String community) { final String C_PASS0 = labelOfPassN(0); Collection comms = Collections.singletonList(community); boolean reachPass0 = false; - while (comms.size() > 0 && !reachPass0) { + while (!comms.isEmpty() && !reachPass0) { Iterator subComms = this.vertices(comms.iterator()); comms = new HashSet<>(); while (subComms.hasNext()) { @@ -703,7 +703,7 @@ public long clearPass(int pass) { if (pass < 0) { // drop edges of all pass List els = this.cpassEdgeLabels(); - if (els.size() > 0) { + if (!els.isEmpty()) { String first = els.remove(0); te = te.hasLabel(first, els.toArray(new String[0])); this.drop(te); @@ -727,7 +727,7 @@ public long clearPass(int pass) { if (pass < 0) { // drop vertices of all pass List vls = this.cpassVertexLabels(); - if (vls.size() > 0) { + if (!vls.isEmpty()) { String first = vls.remove(0); tv = tv.hasLabel(first, vls.toArray(new String[0])); this.drop(tv); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LpaAlgorithm.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LpaAlgorithm.java index 6e92921284..289ebca04c 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LpaAlgorithm.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/comm/LpaAlgorithm.java @@ -203,7 +203,7 @@ private String voteCommunityOfVertex(Vertex vertex, String edgeLabel, } // isolated vertex - if (labels.size() == 0) { + if (labels.isEmpty()) { return this.labelOfVertex(vertex); } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/rank/PageRankAlgorithm.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/rank/PageRankAlgorithm.java index 5c11c37e1f..a7a189ea31 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/rank/PageRankAlgorithm.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/job/algorithm/rank/PageRankAlgorithm.java @@ -196,7 +196,7 @@ private long initRankMap() { private void contributeToAdjacentVertices(Id sourceVertexId, List adjacentVertices) { - if (adjacentVertices.size() == 0) { + if (adjacentVertices.isEmpty()) { return; } DoublePair sourcePair = this.vertexRankMap.get(sourceVertexId); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/EdgeLabel.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/EdgeLabel.java index 3aaf6e141d..ca2986d55a 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/EdgeLabel.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/EdgeLabel.java @@ -105,7 +105,7 @@ public boolean checkLinkEqual(Id sourceLabel, Id targetLabel) { } public boolean existSortKeys() { - return this.sortKeys.size() > 0; + return !this.sortKeys.isEmpty(); } public List sortKeys() { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/builder/VertexLabelBuilder.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/builder/VertexLabelBuilder.java index edd34c4715..db73c5491e 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/builder/VertexLabelBuilder.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/builder/VertexLabelBuilder.java @@ -476,7 +476,7 @@ private void checkNullableKeys(Action action) { private void checkIdStrategy() { IdStrategy strategy = this.idStrategy; - boolean hasPrimaryKey = this.primaryKeys.size() > 0; + boolean hasPrimaryKey = !this.primaryKeys.isEmpty(); switch (strategy) { case DEFAULT: if (hasPrimaryKey) { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeElement.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeElement.java index f727dc2fcb..137e623d86 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeElement.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeElement.java @@ -252,7 +252,7 @@ public boolean hasProperty(Id key) { } public boolean hasProperties() { - return this.properties.size() > 0; + return !this.properties.isEmpty(); } public int sizeOfProperties() { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeVertex.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeVertex.java index f81d8ab99e..aca200700a 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeVertex.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeVertex.java @@ -224,7 +224,7 @@ protected List primaryValues() { } public boolean existsEdges() { - return this.edges.size() > 0; + return !this.edges.isEmpty(); } public Collection getEdges() { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/NeighborRankTraverser.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/NeighborRankTraverser.java index 3e915c7dd9..914309a780 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/NeighborRankTraverser.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/NeighborRankTraverser.java @@ -214,7 +214,7 @@ private Ranks contributeNewLayer(List adjacencies, private List> topRanks(List ranks, List steps) { - assert ranks.size() > 0; + assert !ranks.isEmpty(); List> results = newList(ranks.size()); // The first layer is root node so skip i=0 results.add(ranks.get(0)); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStep.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStep.java index 1a3fc58bea..c35305e2b8 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStep.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStep.java @@ -151,7 +151,7 @@ protected ConditionQuery constructEdgesQuery( withEdgeCond = false; } else { // Partial sysprop conditions are in sort-keys - assert query.userpropKeys().size() > 0; + assert !query.userpropKeys().isEmpty(); } } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepByBatch.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepByBatch.java index 9517847331..112052e725 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepByBatch.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepByBatch.java @@ -93,7 +93,7 @@ protected void closeIterator() { @SuppressWarnings("unchecked") private Iterator flatMap(List> traversers) { - if (this.head == null && traversers.size() > 0) { + if (this.head == null && !traversers.isEmpty()) { this.head = traversers.get(0); } boolean queryVertex = this.returnsVertex(); @@ -110,14 +110,14 @@ private Iterator flatMap(List> traversers) { private Iterator vertices( List> traversers) { - assert traversers.size() > 0; + assert !traversers.isEmpty(); Iterator edges = this.edges(traversers); return this.queryAdjacentVertices(edges); } private Iterator edges(List> traversers) { - assert traversers.size() > 0; + assert !traversers.isEmpty(); BatchConditionQuery batchQuery = new BatchConditionQuery( HugeType.EDGE, traversers.size()); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepStrategy.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepStrategy.java index a7dd687348..6e9eac6092 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepStrategy.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeVertexStepStrategy.java @@ -97,8 +97,8 @@ public void apply(final Traversal.Admin traversal) { * @return the traversal or its parents contain at least one Path step */ protected static boolean containsPath(Traversal.Admin traversal) { - boolean hasPath = TraversalHelper.getStepsOfClass( - PathStep.class, traversal).size() > 0; + boolean hasPath = !TraversalHelper.getStepsOfClass( + PathStep.class, traversal).isEmpty(); if (hasPath) { return true; } else if (traversal instanceof EmptyTraversal) { @@ -116,8 +116,8 @@ protected static boolean containsPath(Traversal.Admin traversal) { * @return the traversal or its parents contain at least one Tree step */ protected static boolean containsTree(Traversal.Admin traversal) { - boolean hasTree = TraversalHelper.getStepsOfClass( - TreeStep.class, traversal).size() > 0; + boolean hasTree = !TraversalHelper.getStepsOfClass( + TreeStep.class, traversal).isEmpty(); if (hasTree) { return true; } else if (traversal instanceof EmptyTraversal) { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMap.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMap.java index fe8f20b78e..8bb5434825 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMap.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntMap.java @@ -69,7 +69,7 @@ final class IntMapBySegments implements IntMap { private static final int DEFAULT_SEGMENTS = (IntSet.CPUS + 8) * 32; private static final Function DEFAULT_CREATOR = - size -> new IntMapByFixedAddr(size); + IntMapByFixedAddr::new; @SuppressWarnings("static-access") private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET; @@ -232,7 +232,7 @@ private IntMap segment(int key) { private IntMap segmentAt(int index) { // volatile get this.maps[index] - long offset = (index << SHIFT) + BASE_OFFSET; + long offset = ((long) index << SHIFT) + BASE_OFFSET; IntMap map = (IntMap) UNSAFE.getObjectVolatile(this.maps, offset); return map; } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntSet.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntSet.java index ce37bda8ef..c40b731d8c 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntSet.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/collection/IntSet.java @@ -58,7 +58,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); + IntSetByFixedAddr4Unsigned::new; @SuppressWarnings("static-access") private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET; @@ -184,7 +184,7 @@ private IntSet segment(int key) { private IntSet segmentAt(int index) { // volatile get this.sets[index] - long offset = (index << SHIFT) + BASE_OFFSET; + long offset = ((long) index << SHIFT) + BASE_OFFSET; IntSet set = (IntSet) UNSAFE.getObjectVolatile(this.sets, offset); return set; } diff --git a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSerializer.java b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSerializer.java index 5b528daf82..0cfc928ab8 100644 --- a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSerializer.java +++ b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSerializer.java @@ -33,7 +33,7 @@ public class HbaseSerializer extends BinarySerializer { private final short edgeLogicPartitions; public HbaseSerializer(HugeConfig config) { - super(false, true, config.get(HbaseOptions.HBASE_ENABLE_PARTITION).booleanValue()); + super(false, true, config.get(HbaseOptions.HBASE_ENABLE_PARTITION)); this.vertexLogicPartitions = config.get(HbaseOptions.HBASE_VERTEX_PARTITION).shortValue(); this.edgeLogicPartitions = config.get(HbaseOptions.HBASE_EDGE_PARTITION).shortValue(); LOG.debug("vertexLogicPartitions: " + vertexLogicPartitions); diff --git a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSessions.java index 1b9c4afe7e..3255d092d6 100644 --- a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseSessions.java @@ -534,7 +534,7 @@ public boolean closed() { */ @Override public boolean hasChanges() { - return this.batch.size() > 0; + return !this.batch.isEmpty(); } /** diff --git a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java index cb5ff31138..aca712a882 100644 --- a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java +++ b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java @@ -39,6 +39,7 @@ import org.apache.hugegraph.backend.store.BackendFeatures; import org.apache.hugegraph.backend.store.BackendMutation; import org.apache.hugegraph.backend.store.BackendStoreProvider; +import org.apache.hugegraph.backend.store.BackendTable; import org.apache.hugegraph.config.HugeConfig; import org.apache.hugegraph.exception.ConnectionException; import org.apache.hugegraph.type.HugeType; @@ -109,7 +110,7 @@ protected HbaseSessions.Session session(HugeType type) { } protected List tableNames() { - return this.tables.values().stream().map(t -> t.table()) + return this.tables.values().stream().map(BackendTable::table) .collect(Collectors.toList()); } @@ -450,7 +451,7 @@ public static class HbaseSchemaStore extends HbaseStore { public HbaseSchemaStore(HugeConfig config, BackendStoreProvider provider, String namespace, String store) { super(provider, namespace, store, - config.get(HbaseOptions.HBASE_ENABLE_PARTITION).booleanValue()); + config.get(HbaseOptions.HBASE_ENABLE_PARTITION)); this.counters = new HbaseTables.Counters(); @@ -500,8 +501,8 @@ public static class HbaseGraphStore extends HbaseStore { public HbaseGraphStore(HugeConfig config, BackendStoreProvider provider, String namespace, String store) { super(provider, namespace, store, - config.get(HbaseOptions.HBASE_ENABLE_PARTITION).booleanValue()); - this.enablePartition = config.get(HbaseOptions.HBASE_ENABLE_PARTITION).booleanValue(); + config.get(HbaseOptions.HBASE_ENABLE_PARTITION)); + this.enablePartition = config.get(HbaseOptions.HBASE_ENABLE_PARTITION); registerTableManager(HugeType.VERTEX, new HbaseTables.Vertex(store, enablePartition)); diff --git a/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlTables.java b/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlTables.java index dccbfedd4a..cf0a1e08e3 100644 --- a/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlTables.java +++ b/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlTables.java @@ -374,7 +374,7 @@ public List idColumnValue(Id id) { public void delete(MysqlSessions.Session session, MysqlBackendEntry.Row entry) { // Let super class do delete if not deleting edge by label List idParts = this.idColumnValue(entry.id()); - if (idParts.size() > 1 || entry.columns().size() > 0) { + if (idParts.size() > 1 || !entry.columns().isEmpty()) { super.delete(session, entry); return; } diff --git a/hugegraph-server/hugegraph-palo/src/main/java/org/apache/hugegraph/backend/store/palo/PaloTables.java b/hugegraph-server/hugegraph-palo/src/main/java/org/apache/hugegraph/backend/store/palo/PaloTables.java index 51c3dcea93..268c0d232f 100644 --- a/hugegraph-server/hugegraph-palo/src/main/java/org/apache/hugegraph/backend/store/palo/PaloTables.java +++ b/hugegraph-server/hugegraph-palo/src/main/java/org/apache/hugegraph/backend/store/palo/PaloTables.java @@ -240,7 +240,7 @@ public void delete(MysqlSessions.Session session, MysqlBackendEntry.Row entry) { // Let super class do delete if not deleting edge by label List idParts = this.idColumnValue(entry.id()); - if (idParts.size() > 1 || entry.columns().size() > 0) { + if (idParts.size() > 1 || !entry.columns().isEmpty()) { super.delete(session, entry); return; } diff --git a/hugegraph-server/hugegraph-postgresql/src/main/java/org/apache/hugegraph/backend/store/postgresql/PostgresqlSerializer.java b/hugegraph-server/hugegraph-postgresql/src/main/java/org/apache/hugegraph/backend/store/postgresql/PostgresqlSerializer.java index c0bd23a7e2..918c32caa6 100644 --- a/hugegraph-server/hugegraph-postgresql/src/main/java/org/apache/hugegraph/backend/store/postgresql/PostgresqlSerializer.java +++ b/hugegraph-server/hugegraph-postgresql/src/main/java/org/apache/hugegraph/backend/store/postgresql/PostgresqlSerializer.java @@ -39,11 +39,11 @@ public BackendEntry writeIndex(HugeIndex index) { * When field-values is null and elementIds size is 0, it is * meaningful for deletion of index data in secondary/range index. */ - if (index.fieldValues() == null && index.elementIds().size() == 0) { + if (index.fieldValues() == null && index.elementIds().isEmpty()) { entry.column(HugeKeys.INDEX_LABEL_ID, index.indexLabel().longId()); } else { Object value = index.fieldValues(); - if (value != null && "\u0000".equals(value)) { + if ("\u0000".equals(value)) { value = Strings.EMPTY; } entry.column(HugeKeys.FIELD_VALUES, value); diff --git a/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java b/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java index 70eec3cc55..b85ae5312b 100644 --- a/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java +++ b/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdbsst/RocksDBSstSessions.java @@ -247,7 +247,7 @@ public void close() { */ @Override public boolean hasChanges() { - return this.batch.size() > 0; + return !this.batch.isEmpty(); } /** diff --git a/hugegraph-server/hugegraph-scylladb/src/main/java/org/apache/hugegraph/backend/store/scylladb/ScyllaDBTablesWithMV.java b/hugegraph-server/hugegraph-scylladb/src/main/java/org/apache/hugegraph/backend/store/scylladb/ScyllaDBTablesWithMV.java index 61dfe88dff..9846a18446 100644 --- a/hugegraph-server/hugegraph-scylladb/src/main/java/org/apache/hugegraph/backend/store/scylladb/ScyllaDBTablesWithMV.java +++ b/hugegraph-server/hugegraph-scylladb/src/main/java/org/apache/hugegraph/backend/store/scylladb/ScyllaDBTablesWithMV.java @@ -242,7 +242,7 @@ public static class Edge extends CassandraTables.Edge { private static final String LABEL = CassandraTable.formatKey(HugeKeys.LABEL); private final List keys = this.idColumnName().stream() .filter(k -> k != HugeKeys.LABEL) - .map(k -> CassandraTable.formatKey(k)) + .map(CassandraTable::formatKey) .collect(Collectors.toList()); private final String prKeys = this.keys.stream() .collect(Collectors.joining(",")); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/JaccardSimilarityApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/JaccardSimilarityApiTest.java index 031ad9c93c..053271154b 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/JaccardSimilarityApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/JaccardSimilarityApiTest.java @@ -53,7 +53,7 @@ public void testGet() { String content = assertResponseStatus(200, r); Double jaccardSimilarity = assertJsonContains(content, "jaccard_similarity"); - Assert.assertEquals(0.25, jaccardSimilarity.doubleValue(), 0.0001); + Assert.assertEquals(0.25, jaccardSimilarity, 0.0001); } @Test @@ -77,10 +77,10 @@ public void testPost() { Double rippleJaccardSimilarity = assertMapContains(jaccardSimilarity, rippleId); Double peterJaccardSimilarity = assertMapContains(jaccardSimilarity, peterId); Double jsonJaccardSimilarity = assertMapContains(jaccardSimilarity, jsonId); - Assert.assertEquals(0.3333, rippleJaccardSimilarity.doubleValue(), + Assert.assertEquals(0.3333, rippleJaccardSimilarity, 0.0001); - Assert.assertEquals(0.25, peterJaccardSimilarity.doubleValue(), 0.0001); - Assert.assertEquals(0.3333, jsonJaccardSimilarity.doubleValue(), + Assert.assertEquals(0.25, peterJaccardSimilarity, 0.0001); + Assert.assertEquals(0.3333, jsonJaccardSimilarity, 0.0001); } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java index 4ae3b5fe68..585734cf40 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java @@ -4106,7 +4106,7 @@ public void testQueryByDoubleProperty() { schema.indexLabel("numberByDouble").range() .onV("number").by("double").create(); - final double max7 = Double.valueOf(String.valueOf(Float.MAX_VALUE)); + final double max7 = Double.parseDouble(String.valueOf(Float.MAX_VALUE)); /* * The double precision type typically has a range of around 1E-307 to diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/DirectionsTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/DirectionsTest.java index 8d2ad42b1a..0f6b69e8fc 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/DirectionsTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/DirectionsTest.java @@ -36,9 +36,7 @@ public void testString() { public void testType() { Assert.assertEquals(HugeType.EDGE_OUT, Directions.OUT.type()); Assert.assertEquals(HugeType.EDGE_IN, Directions.IN.type()); - Assert.assertThrows(IllegalArgumentException.class, () -> { - Directions.BOTH.type(); - }); + Assert.assertThrows(IllegalArgumentException.class, Directions.BOTH::type); } @Test diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/id/IdTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/id/IdTest.java index dd794ab5d8..8bd772a3db 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/id/IdTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/id/IdTest.java @@ -54,9 +54,7 @@ public void testStringId() { Assert.assertEquals(IdGenerator.of("test-id"), id); Assert.assertNotEquals(IdGenerator.of("test-id2"), id); - Assert.assertThrows(IllegalArgumentException.class, () -> { - id.asLong(); - }); + Assert.assertThrows(IllegalArgumentException.class, id::asLong); Assert.assertEquals("test-id", IdGenerator.asStoredString(id)); Assert.assertEquals(id, IdGenerator.ofStoredString("test-id", @@ -123,9 +121,7 @@ public void testUuidId() { Assert.assertNotEquals(id3, id); Assert.assertNotEquals(id4, id); - Assert.assertThrows(UnsupportedOperationException.class, () -> { - id.asLong(); - }); + Assert.assertThrows(UnsupportedOperationException.class, id::asLong); Assert.assertEquals("g14RU5KBSVeGkc95JY6Q6w==", IdGenerator.asStoredString(id)); @@ -142,25 +138,17 @@ public void testObjectId() { Assert.assertEquals(object, id.asObject()); Assert.assertEquals(object.hashCode(), id.hashCode()); Assert.assertEquals(object.toString(), id.toString()); - Assert.assertTrue(id.equals(IdGenerator.of(object))); - Assert.assertFalse(id.equals(IdGenerator.of(object2))); - Assert.assertFalse(id.equals(object)); + Assert.assertEquals(id, IdGenerator.of(object)); + Assert.assertNotEquals(id, IdGenerator.of(object2)); + Assert.assertNotEquals(id, object); - Assert.assertThrows(UnsupportedOperationException.class, () -> { - id.asString(); - }); - Assert.assertThrows(UnsupportedOperationException.class, () -> { - id.asLong(); - }); - Assert.assertThrows(UnsupportedOperationException.class, () -> { - id.asBytes(); - }); + Assert.assertThrows(UnsupportedOperationException.class, id::asString); + Assert.assertThrows(UnsupportedOperationException.class, id::asLong); + Assert.assertThrows(UnsupportedOperationException.class, id::asBytes); Assert.assertThrows(UnsupportedOperationException.class, () -> { id.compareTo(id); }); - Assert.assertThrows(UnsupportedOperationException.class, () -> { - id.length(); - }); + Assert.assertThrows(UnsupportedOperationException.class, id::length); } @Test diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/serializer/TableBackendEntryTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/serializer/TableBackendEntryTest.java index 0d41321cc7..2771764d48 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/serializer/TableBackendEntryTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/serializer/TableBackendEntryTest.java @@ -170,9 +170,7 @@ public void testNotImplemented() { TableBackendEntry entry = new TableBackendEntry(HugeType.VERTEX); BackendColumn col = BackendColumn.of(new byte[]{1}, new byte[]{12}); - Assert.assertThrows(NotImplementedException.class, () -> { - entry.columnsSize(); - }); + Assert.assertThrows(NotImplementedException.class, entry::columnsSize); Assert.assertThrows(NotImplementedException.class, () -> { entry.columns(); }); @@ -185,8 +183,6 @@ public void testNotImplemented() { Assert.assertThrows(NotImplementedException.class, () -> { entry.merge(entry); }); - Assert.assertThrows(NotImplementedException.class, () -> { - entry.clear(); - }); + Assert.assertThrows(NotImplementedException.class, entry::clear); } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IdSetTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IdSetTest.java index 5f78f8de60..2a9082c831 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IdSetTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IdSetTest.java @@ -18,7 +18,6 @@ package org.apache.hugegraph.unit.util.collection; import java.util.HashSet; -import java.util.Iterator; import java.util.Random; import java.util.Set; import java.util.UUID; @@ -247,9 +246,7 @@ public void testIdSetIterator() { Assert.assertEquals(uuids.size() + strings.size(), nonNumberIds.size()); - Iterator iterator = idSet.iterator(); - while (iterator.hasNext()) { - Id id = iterator.next(); + for (Id id : idSet) { if (id instanceof IdGenerator.LongId) { Assert.assertTrue(numbers.contains(id.asLong())); } else if (id instanceof IdGenerator.UuidId) { diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IntMapTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IntMapTest.java index 43c0e8229c..c22a76a8ed 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IntMapTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util/collection/IntMapTest.java @@ -200,14 +200,14 @@ public void testIntFixedMapBySegmentsPut() { for (int i = 0; i < capacity; i++) { Assert.assertTrue(map.put(i, i * i)); Assert.assertEquals(i * i, map.get(i)); - Assert.assertEquals(true, map.containsKey(i)); - Assert.assertEquals(false, map.containsKey(i + 1)); + Assert.assertTrue(map.containsKey(i)); + Assert.assertFalse(map.containsKey(i + 1)); int u = -i - 1; Assert.assertTrue(map.put(u, u)); Assert.assertEquals(u, map.get(u)); - Assert.assertEquals(true, map.containsKey(u)); - Assert.assertEquals(false, map.containsKey(u - 1)); + Assert.assertTrue(map.containsKey(u)); + Assert.assertFalse(map.containsKey(u - 1)); } IntIterator values = map.values(); @@ -297,17 +297,17 @@ public void testIntFixedMapBySegmentsPutRandom() { Assert.assertTrue(map.put(k, k * k)); Assert.assertEquals(k * k, map.get(k)); - Assert.assertEquals(true, map.containsKey(k)); + Assert.assertTrue(map.containsKey(k)); int u = -k - 1; Assert.assertTrue(map.put(u, u)); Assert.assertEquals(u, map.get(u)); - Assert.assertEquals(true, map.containsKey(u)); + Assert.assertTrue(map.containsKey(u)); int r = i % 2 == 0 ? k : u; - Assert.assertEquals(true, map.containsKey(r)); + Assert.assertTrue(map.containsKey(r)); Assert.assertTrue(map.remove(r)); - Assert.assertEquals(false, map.containsKey(r)); + Assert.assertFalse(map.containsKey(r)); } return map.size(); @@ -330,9 +330,7 @@ public void testIntFixedMapBySegmentsKeys() { Assert.assertEquals(Integer.MAX_VALUE - 1, iter.next()); Assert.assertFalse(iter.hasNext()); - Assert.assertThrows(NoSuchElementException.class, () -> { - iter.next(); - }, e -> { + Assert.assertThrows(NoSuchElementException.class, iter::next, e -> { Assert.assertNull(e.getMessage()); }); } @@ -359,9 +357,7 @@ public void testIntFixedMapBySegmentsKeysWithMultiSegs() { } Assert.assertFalse(iter.hasNext()); - Assert.assertThrows(NoSuchElementException.class, () -> { - iter.next(); - }, e -> { + Assert.assertThrows(NoSuchElementException.class, iter::next, e -> { Assert.assertNull(e.getMessage()); }); } @@ -380,9 +376,7 @@ public void testIntFixedMapBySegmentsValues() { Assert.assertEquals(1, iter.next()); Assert.assertFalse(iter.hasNext()); - Assert.assertThrows(NoSuchElementException.class, () -> { - iter.next(); - }, e -> { + Assert.assertThrows(NoSuchElementException.class, iter::next, e -> { Assert.assertNull(e.getMessage()); }); } @@ -409,9 +403,7 @@ public void testIntFixedMapBySegmentsValuesWithMultiSegs() { } Assert.assertFalse(iter.hasNext()); - Assert.assertThrows(NoSuchElementException.class, () -> { - iter.next(); - }, e -> { + Assert.assertThrows(NoSuchElementException.class, iter::next, e -> { Assert.assertNull(e.getMessage()); }); } @@ -457,7 +449,6 @@ protected void afterExecute(Runnable r, Throwable t) { } } }; - ; AtomicInteger size = new AtomicInteger(); int mapSize = 100;