forked from hugegraph/hugegraph-sync
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
This commit is contained in:
parent
5551ec17f2
commit
b7f8b56730
|
|
@ -95,7 +95,7 @@ public class LoadDetectFilter implements ContainerRequestFilter {
|
|||
|
||||
public static boolean isWhiteAPI(ContainerRequestContext context) {
|
||||
List<PathSegment> 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);
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class RestServer {
|
|||
}
|
||||
|
||||
Collection<NetworkListener> 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();
|
||||
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@ public abstract class CassandraStore extends AbstractBackendStore<CassandraSessi
|
|||
|
||||
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, " +
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ public class CassandraTables {
|
|||
|
||||
// Let super class do delete if not deleting edge by label
|
||||
List<Object> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ public class StandardAuthManager implements AuthManager {
|
|||
}
|
||||
|
||||
List<HugeUser> 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);
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ public final class CachedGraphTransaction extends GraphTransaction {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public interface Id extends Comparable<Id> {
|
|||
}
|
||||
|
||||
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':
|
||||
|
|
|
|||
|
|
@ -53,9 +53,7 @@ public abstract class Condition {
|
|||
|
||||
public enum RelationType implements BiPredicate<Object, Object> {
|
||||
|
||||
EQ("==", (v1, v2) -> {
|
||||
return equals(v1, v2);
|
||||
}),
|
||||
EQ("==", RelationType::equals),
|
||||
|
||||
GT(">", (v1, v2) -> {
|
||||
return compare(v1, v2) > 0;
|
||||
|
|
|
|||
|
|
@ -277,12 +277,12 @@ public class ConditionQuery extends IdQuery {
|
|||
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;
|
||||
|
|
@ -309,7 +309,7 @@ public class ConditionQuery extends IdQuery {
|
|||
}
|
||||
}
|
||||
|
||||
if (intersectValues.size() == 0) {
|
||||
if (intersectValues.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
E.checkState(intersectValues.size() == 1,
|
||||
|
|
@ -565,7 +565,7 @@ public class ConditionQuery extends IdQuery {
|
|||
|
||||
public boolean matchUserpropKeys(List<Id> keys) {
|
||||
Set<Id> conditionKeys = this.userpropKeys();
|
||||
return keys.size() > 0 && conditionKeys.containsAll(keys);
|
||||
return !keys.isEmpty() && conditionKeys.containsAll(keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -869,7 +869,7 @@ public class ConditionQuery extends IdQuery {
|
|||
*/
|
||||
boolean hasRightValue = removeFieldValue(fieldValues,
|
||||
property.value());
|
||||
if (fieldValues.size() > 0) {
|
||||
if (!fieldValues.isEmpty()) {
|
||||
this.addLeftIndex(element.id(), propId, fieldValues);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class QueryResults<R> {
|
|||
}
|
||||
|
||||
public void setQuery(Query query) {
|
||||
if (this.queries.size() > 0) {
|
||||
if (!this.queries.isEmpty()) {
|
||||
this.queries.clear();
|
||||
}
|
||||
this.addQuery(query);
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ public class BinarySerializer extends AbstractSerializer {
|
|||
@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.
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ public abstract class TableSerializer extends AbstractSerializer {
|
|||
* 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());
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ public class TextSerializer extends AbstractSerializer {
|
|||
@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.
|
||||
|
|
@ -506,7 +506,7 @@ public class TextSerializer extends AbstractSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ public class InMemoryDBTable extends BackendTable<BackendSession,
|
|||
|
||||
protected Map<Id, BackendEntry> queryById(Collection<Id> ids,
|
||||
Map<Id, BackendEntry> entries) {
|
||||
assert ids.size() > 0;
|
||||
assert !ids.isEmpty();
|
||||
Map<Id, BackendEntry> rs = InsertionOrderUtil.newMap();
|
||||
|
||||
for (Id id : ids) {
|
||||
|
|
@ -262,7 +262,7 @@ public class InMemoryDBTable extends BackendTable<BackendSession,
|
|||
protected Map<Id, BackendEntry> queryByFilter(
|
||||
Collection<Condition> conditions,
|
||||
Map<Id, BackendEntry> entries) {
|
||||
assert conditions.size() > 0;
|
||||
assert !conditions.isEmpty();
|
||||
|
||||
Map<Id, BackendEntry> rs = new HashMap<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ public class InMemoryDBTables {
|
|||
private Map<Id, BackendEntry> queryEdgeById(
|
||||
Collection<Id> ids, boolean prefix,
|
||||
Map<Id, BackendEntry> entries) {
|
||||
assert ids.size() > 0;
|
||||
assert !ids.isEmpty();
|
||||
Map<Id, BackendEntry> rs = InsertionOrderUtil.newMap();
|
||||
|
||||
for (Id id : ids) {
|
||||
|
|
|
|||
|
|
@ -306,9 +306,7 @@ public final class RamTable {
|
|||
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<HugeEdge> query(ConditionQuery query) {
|
||||
|
|
@ -540,7 +538,7 @@ public final class RamTable {
|
|||
|
||||
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 {}",
|
||||
|
|
|
|||
|
|
@ -1704,7 +1704,7 @@ public class GraphIndexTransaction extends AbstractTransaction {
|
|||
}
|
||||
|
||||
private static Query parent(Collection<Query> queries) {
|
||||
if (queries.size() > 0) {
|
||||
if (!queries.isEmpty()) {
|
||||
// Chose the first one as origin query (any one is OK)
|
||||
return queries.iterator().next();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,23 +180,23 @@ public class GraphTransaction extends IndexableTransaction {
|
|||
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 @@ public class GraphTransaction extends IndexableTransaction {
|
|||
@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 class GraphTransaction extends IndexableTransaction {
|
|||
// 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 class GraphTransaction extends IndexableTransaction {
|
|||
for (Edge edge : batchEdges) {
|
||||
vertexIds.add(((HugeEdge) edge).otherVertex().id());
|
||||
}
|
||||
assert vertexIds.size() > 0;
|
||||
assert !vertexIds.isEmpty();
|
||||
return this.queryAdjacentVertices(vertexIds.toArray());
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -536,7 +536,7 @@ public class LouvainTraverser extends AlgoTraverser {
|
|||
for (Pair<Community, Set<Id>> 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 class LouvainTraverser extends AlgoTraverser {
|
|||
final String C_PASS0 = labelOfPassN(0);
|
||||
Collection<Object> comms = Collections.singletonList(community);
|
||||
boolean reachPass0 = false;
|
||||
while (comms.size() > 0 && !reachPass0) {
|
||||
while (!comms.isEmpty() && !reachPass0) {
|
||||
Iterator<Vertex> subComms = this.vertices(comms.iterator());
|
||||
comms = new HashSet<>();
|
||||
while (subComms.hasNext()) {
|
||||
|
|
@ -703,7 +703,7 @@ public class LouvainTraverser extends AlgoTraverser {
|
|||
if (pass < 0) {
|
||||
// drop edges of all pass
|
||||
List<String> 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 class LouvainTraverser extends AlgoTraverser {
|
|||
if (pass < 0) {
|
||||
// drop vertices of all pass
|
||||
List<String> 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);
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ public class LpaAlgorithm extends AbstractCommAlgorithm {
|
|||
}
|
||||
|
||||
// isolated vertex
|
||||
if (labels.size() == 0) {
|
||||
if (labels.isEmpty()) {
|
||||
return this.labelOfVertex(vertex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ public class PageRankAlgorithm extends AbstractCommAlgorithm {
|
|||
|
||||
private void contributeToAdjacentVertices(Id sourceVertexId,
|
||||
List<Id> adjacentVertices) {
|
||||
if (adjacentVertices.size() == 0) {
|
||||
if (adjacentVertices.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
DoublePair sourcePair = this.vertexRankMap.get(sourceVertexId);
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public class EdgeLabel extends SchemaLabel {
|
|||
}
|
||||
|
||||
public boolean existSortKeys() {
|
||||
return this.sortKeys.size() > 0;
|
||||
return !this.sortKeys.isEmpty();
|
||||
}
|
||||
|
||||
public List<Id> sortKeys() {
|
||||
|
|
|
|||
|
|
@ -477,7 +477,7 @@ public class VertexLabelBuilder extends AbstractBuilder
|
|||
|
||||
private void checkIdStrategy() {
|
||||
IdStrategy strategy = this.idStrategy;
|
||||
boolean hasPrimaryKey = this.primaryKeys.size() > 0;
|
||||
boolean hasPrimaryKey = !this.primaryKeys.isEmpty();
|
||||
switch (strategy) {
|
||||
case DEFAULT:
|
||||
if (hasPrimaryKey) {
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ public abstract class HugeElement implements Element, GraphType, Idfiable, Compa
|
|||
}
|
||||
|
||||
public boolean hasProperties() {
|
||||
return this.properties.size() > 0;
|
||||
return !this.properties.isEmpty();
|
||||
}
|
||||
|
||||
public int sizeOfProperties() {
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ public class HugeVertex extends HugeElement implements Vertex, Cloneable {
|
|||
}
|
||||
|
||||
public boolean existsEdges() {
|
||||
return this.edges.size() > 0;
|
||||
return !this.edges.isEmpty();
|
||||
}
|
||||
|
||||
public Collection<HugeEdge> getEdges() {
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ public class NeighborRankTraverser extends HugeTraverser {
|
|||
|
||||
private List<Map<Id, Double>> topRanks(List<Ranks> ranks,
|
||||
List<Step> steps) {
|
||||
assert ranks.size() > 0;
|
||||
assert !ranks.isEmpty();
|
||||
List<Map<Id, Double>> results = newList(ranks.size());
|
||||
// The first layer is root node so skip i=0
|
||||
results.add(ranks.get(0));
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ public class HugeVertexStep<E extends Element>
|
|||
withEdgeCond = false;
|
||||
} else {
|
||||
// Partial sysprop conditions are in sort-keys
|
||||
assert query.userpropKeys().size() > 0;
|
||||
assert !query.userpropKeys().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class HugeVertexStepByBatch<E extends Element>
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Iterator<E> flatMap(List<Traverser.Admin<Vertex>> 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 @@ public class HugeVertexStepByBatch<E extends Element>
|
|||
|
||||
private Iterator<Vertex> vertices(
|
||||
List<Traverser.Admin<Vertex>> traversers) {
|
||||
assert traversers.size() > 0;
|
||||
assert !traversers.isEmpty();
|
||||
|
||||
Iterator<Edge> edges = this.edges(traversers);
|
||||
return this.queryAdjacentVertices(edges);
|
||||
}
|
||||
|
||||
private Iterator<Edge> edges(List<Traverser.Admin<Vertex>> traversers) {
|
||||
assert traversers.size() > 0;
|
||||
assert !traversers.isEmpty();
|
||||
|
||||
BatchConditionQuery batchQuery = new BatchConditionQuery(
|
||||
HugeType.EDGE, traversers.size());
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ public final class HugeVertexStepStrategy
|
|||
* @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 @@ public final class HugeVertexStepStrategy
|
|||
* @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) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public interface IntMap {
|
|||
|
||||
private static final int DEFAULT_SEGMENTS = (IntSet.CPUS + 8) * 32;
|
||||
private static final Function<Integer, IntMap> 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 @@ public interface IntMap {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public interface IntSet {
|
|||
|
||||
private static final int DEFAULT_SEGMENTS = IntSet.CPUS * 100;
|
||||
private static final Function<Integer, IntSet> 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 @@ public interface IntSet {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -534,7 +534,7 @@ public class HbaseSessions extends BackendSessionPool {
|
|||
*/
|
||||
@Override
|
||||
public boolean hasChanges() {
|
||||
return this.batch.size() > 0;
|
||||
return !this.batch.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import org.apache.hugegraph.backend.store.BackendEntry;
|
|||
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 @@ public abstract class HbaseStore extends AbstractBackendStore<HbaseSessions.Sess
|
|||
}
|
||||
|
||||
protected List<String> 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 abstract class HbaseStore extends AbstractBackendStore<HbaseSessions.Sess
|
|||
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 abstract class HbaseStore extends AbstractBackendStore<HbaseSessions.Sess
|
|||
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));
|
||||
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ public class MysqlTables {
|
|||
public void delete(MysqlSessions.Session session, MysqlBackendEntry.Row entry) {
|
||||
// Let super class do delete if not deleting edge by label
|
||||
List<Object> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ public class PaloTables {
|
|||
MysqlBackendEntry.Row entry) {
|
||||
// Let super class do delete if not deleting edge by label
|
||||
List<Object> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ public class PostgresqlSerializer extends MysqlSerializer {
|
|||
* 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);
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ public class RocksDBSstSessions extends RocksDBSessions {
|
|||
*/
|
||||
@Override
|
||||
public boolean hasChanges() {
|
||||
return this.batch.size() > 0;
|
||||
return !this.batch.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ public class ScyllaDBTablesWithMV {
|
|||
private static final String LABEL = CassandraTable.formatKey(HugeKeys.LABEL);
|
||||
private final List<String> 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(","));
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class JaccardSimilarityApiTest extends BaseApiTest {
|
|||
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 class JaccardSimilarityApiTest extends BaseApiTest {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4113,7 +4113,7 @@ public class VertexCoreTest extends BaseCoreTest {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ public class DirectionsTest {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -54,9 +54,7 @@ public class IdTest extends BaseUnitTest {
|
|||
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 class IdTest extends BaseUnitTest {
|
|||
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 class IdTest extends BaseUnitTest {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -170,9 +170,7 @@ public class TableBackendEntryTest extends BaseUnitTest {
|
|||
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 class TableBackendEntryTest extends BaseUnitTest {
|
|||
Assert.assertThrows(NotImplementedException.class, () -> {
|
||||
entry.merge(entry);
|
||||
});
|
||||
Assert.assertThrows(NotImplementedException.class, () -> {
|
||||
entry.clear();
|
||||
});
|
||||
Assert.assertThrows(NotImplementedException.class, entry::clear);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 class IdSetTest {
|
|||
Assert.assertEquals(uuids.size() + strings.size(),
|
||||
nonNumberIds.size());
|
||||
|
||||
Iterator<Id> 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) {
|
||||
|
|
|
|||
|
|
@ -200,14 +200,14 @@ public class IntMapTest extends BaseUnitTest {
|
|||
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 class IntMapTest extends BaseUnitTest {
|
|||
|
||||
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 class IntMapTest extends BaseUnitTest {
|
|||
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 class IntMapTest extends BaseUnitTest {
|
|||
}
|
||||
|
||||
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 class IntMapTest extends BaseUnitTest {
|
|||
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 class IntMapTest extends BaseUnitTest {
|
|||
}
|
||||
|
||||
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 @@ public class IntMapTest extends BaseUnitTest {
|
|||
}
|
||||
}
|
||||
};
|
||||
;
|
||||
|
||||
AtomicInteger size = new AtomicInteger();
|
||||
int mapSize = 100;
|
||||
|
|
|
|||
Loading…
Reference in New Issue