Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix checkstyle core-util issue #1855

Merged
merged 12 commits into from
May 11, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,9 @@ public static void checkCapacity(long capacity, long access,

public static void checkSkipDegree(long skipDegree, long degree,
long capacity) {
E.checkArgument(skipDegree >= 0L &&
skipDegree <= Query.DEFAULT_CAPACITY ,
"The skipped degree must be in [0, %s], but got '%s'",
Query.DEFAULT_CAPACITY, skipDegree);
E.checkArgument(skipDegree >= 0L && skipDegree <= Query.DEFAULT_CAPACITY,
"The skipped degree must be in [0, %s], but got '%s'",
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved
Query.DEFAULT_CAPACITY, skipDegree);
if (capacity != NO_LIMIT) {
E.checkArgument(degree != NO_LIMIT && degree < capacity,
"The max degree must be < capacity");
Expand All @@ -378,10 +377,9 @@ public static void checkSkipDegree(long skipDegree, long degree,
}
}

public static <K, V extends Comparable<? super V>> Map<K, V> topN(
Map<K, V> map,
boolean sorted,
long limit) {
public static <K, V extends Comparable<? super V>> Map<K, V> topN(Map<K,
V> map, boolean sorted, long limit) {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

if (sorted) {
map = CollectionUtil.sortByValue(map, false);
}
Expand Down Expand Up @@ -636,7 +634,7 @@ public String toString() {

public static class PathSet implements Set<Path> {

public final static PathSet EMPTY = new PathSet(ImmutableSet.of());
public static final PathSet EMPTY = new PathSet(ImmutableSet.of());

private final Set<Path> paths;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public JaccardSimilarTraverser(HugeGraph graph) {
super(graph);
}


public double jaccardSimilarity(Id vertex, Id other, Directions dir,
String label, long degree) {
String label, long degree) {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved
E.checkNotNull(vertex, "vertex id");
E.checkNotNull(other, "the other vertex id");
this.checkVertexExist(vertex, "vertex");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
import com.baidu.hugegraph.iterator.FilterIterator;
import com.baidu.hugegraph.util.Consumers;


public abstract class OltpTraverser extends HugeTraverser
implements AutoCloseable {
public abstract class OltpTraverser extends HugeTraverser implements AutoCloseable {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

private static final String EXECUTOR_NAME = "oltp";
private static Consumers.ExecutorPool executors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ public PathSet forward(boolean all) {
Id target = edge.id().otherVertexId();

PathSet paths = this.record.findPath(target,
t -> !this.superNode(t, this.direction),
all, false);
t -> !this.superNode(t, this.direction), all, false);
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

if (paths.isEmpty()) {
continue;
Expand Down Expand Up @@ -217,8 +216,7 @@ public PathSet backward(boolean all) {
Id target = edge.id().otherVertexId();

PathSet paths = this.record.findPath(target,
t -> !this.superNode(t, opposite),
all, false);
t -> !this.superNode(t, opposite), all,false);
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

if (paths.isEmpty()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private Path linkPath(Stack<Record> all, int node) {
List<Id> ids = new ArrayList<>(size);
ids.add(this.id(node));
int value = node;
for (int i = size - 1; i > 0 ; i--) {
for (int i = size - 1; i > 0; i--) {
IntMap layer = ((Int2IntRecord) all.elementAt(i)).layer();
value = layer.get(value);
ids.add(this.id(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import javax.script.ScriptEngine;
import javax.script.ScriptException;

import com.baidu.hugegraph.auth.HugePermission;
import com.baidu.hugegraph.auth.ResourceType;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslator;
import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.collect.Collections2;
import org.apache.tinkerpop.gremlin.process.traversal.Compare;
import org.apache.tinkerpop.gremlin.process.traversal.Contains;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
Expand Down Expand Up @@ -65,6 +64,7 @@
import org.apache.tinkerpop.gremlin.structure.PropertyType;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.slf4j.Logger;

import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.HugeGraph;
Expand All @@ -91,10 +91,13 @@
import com.baidu.hugegraph.util.DateUtil;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.JsonUtil;
import com.baidu.hugegraph.util.Log;
import com.google.common.collect.ImmutableList;

public final class TraversalUtil {

private static final Logger LOG = Log.logger(HugeGraph.class);

public static final String P_CALL = "P.";

public static HugeGraph getGraph(Step<?, ?> step) {
Expand Down Expand Up @@ -287,9 +290,7 @@ public static void fillConditionQuery(ConditionQuery query,
}
}

public static Condition convHas2Condition(HasContainer has,
HugeType type,
HugeGraph graph) {
public static Condition convHas2Condition(HasContainer has, HugeType type, HugeGraph graph) {
P<?> p = has.getPredicate();
E.checkArgument(p != null, "The predicate of has(%s) is null", has);
BiPredicate<?, ?> bp = p.getBiPredicate();
Expand Down Expand Up @@ -373,7 +374,6 @@ private static Relation convCompare2Relation(HugeGraph graph,
convCompare2UserpropRelation(graph, type, has);
}


private static Relation convCompare2SyspropRelation(HugeGraph graph,
HugeType type,
HasContainer has) {
Expand All @@ -397,9 +397,9 @@ private static Relation convCompare2SyspropRelation(HugeGraph graph,
return Condition.lte(key, value);
case neq:
return Condition.neq(key, value);
default:
throw newUnsupportedPredicate(has.getPredicate());
}

throw newUnsupportedPredicate(has.getPredicate());
}

private static Relation convCompare2UserpropRelation(HugeGraph graph,
Expand All @@ -426,9 +426,9 @@ private static Relation convCompare2UserpropRelation(HugeGraph graph,
return Condition.lte(pkeyId, value);
case neq:
return Condition.neq(pkeyId, value);
default:
throw newUnsupportedPredicate(has.getPredicate());
}

throw newUnsupportedPredicate(has.getPredicate());
}

private static Condition convRelationType2Relation(HugeGraph graph,
Expand Down Expand Up @@ -469,6 +469,8 @@ public static Condition convIn2Relation(HugeGraph graph,
return Condition.in(hugeKey, valueList);
case without:
return Condition.nin(hugeKey, valueList);
default:
throw newUnsupportedPredicate(has.getPredicate());
}
} else {
valueList = new ArrayList<>(values);
Expand All @@ -480,10 +482,10 @@ public static Condition convIn2Relation(HugeGraph graph,
return Condition.in(pkey.id(), valueList);
case without:
return Condition.nin(pkey.id(), valueList);
default:
throw newUnsupportedPredicate(has.getPredicate());
}
}

throw newUnsupportedPredicate(has.getPredicate());
}

public static Condition convContains2Relation(HugeGraph graph,
Expand Down Expand Up @@ -902,7 +904,10 @@ private static Number predicateNumber(String value) {
value = JsonUtil.fromJson(value, String.class);
}
return DateUtil.parse(value).getTime();
} catch (Exception ignored) {}
} catch (Exception ignored) {
// @todo
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved
// ignored
}
}

throw new HugeException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public boolean isSchema() {
}

public boolean isGraph() {
return this.isVertex() || this.isEdge() ;
return this.isVertex() || this.isEdge();
}

public boolean isVertex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@

public interface SerialEnum {

public byte code();
byte code();

static Table<Class<?>, Byte, SerialEnum> table = HashBasedTable.create();
Table<Class<?>, Byte, SerialEnum> TABLE = HashBasedTable.create();

public static void register(Class<? extends SerialEnum> clazz) {
static void register(Class<? extends SerialEnum> clazz) {
Object enums;
try {
enums = clazz.getMethod("values").invoke(null);
} catch (Exception e) {
throw new BackendException(e);
}
for (SerialEnum e : CollectionUtil.<SerialEnum>toList(enums)) {
table.put(clazz, e.code(), e);
TABLE.put(clazz, e.code(), e);
}
}

public static <T extends SerialEnum> T fromCode(Class<T> clazz, byte code) {
static <T extends SerialEnum> T fromCode(Class<T> clazz, byte code) {
@SuppressWarnings("unchecked")
T value = (T) table.get(clazz, code);
T value = (T) TABLE.get(clazz, code);
if (value == null) {
E.checkArgument(false, "Can't construct %s from code %s",
clazz.getSimpleName(), code);
}
return value;
}

public static void registerInternalEnums() {
static void registerInternalEnums() {
SerialEnum.register(Action.class);
SerialEnum.register(AggregateType.class);
SerialEnum.register(Cardinality.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ public static void checkGremlinConfig(String conf) {
try {

FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder(YAMLConfiguration.class)
new FileBasedConfigurationBuilder(YAMLConfiguration.class)
.configure(params.fileBased().setFileName(conf));
YAMLConfiguration config = (YAMLConfiguration) builder
.getConfiguration();
YAMLConfiguration config = (YAMLConfiguration) builder.getConfiguration();

List<HierarchicalConfiguration<ImmutableNode>> nodes =
config.childConfigurationsAt(
Expand All @@ -78,9 +77,9 @@ public static void checkGremlinConfig(String conf) {
for (HierarchicalConfiguration<ImmutableNode> node : nodes) {
NodeModel<ImmutableNode> nodeModel = node.getNodeModel();
E.checkArgument(nodeModel != null &&
(nodeHandler = nodeModel.getNodeHandler()) != null &&
(root = nodeHandler.getRootNode()) != null,
"Node '%s' must contain root", node);
(nodeHandler = nodeModel.getNodeHandler()) != null &&
(root = nodeHandler.getRootNode()) != null,
"Node '%s' must contain root", node);
}
} catch (ConfigurationException e) {
throw new HugeException("Failed to load yaml config file '%s'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ private void run() {
this.consume();
}
assert this.ending;
while (this.consume());
while (this.consume()){
// ignore
}

LOG.debug("Worker finished");
}
Expand Down Expand Up @@ -147,7 +149,7 @@ private void done() {
if (this.exception == null) {
this.exception = e;
} else {
LOG.warn("Error while calling done()", e);;
LOG.warn("Error while calling done()", e);
}
}
}
Expand All @@ -170,7 +172,7 @@ public void provide(V v) throws Throwable {
try {
this.queue.put(v);
} catch (InterruptedException e) {
LOG.warn("Interrupted while enqueue", e);;
LOG.warn("Interrupted while enqueue", e);
}
}
}
Expand Down Expand Up @@ -262,7 +264,7 @@ public static RuntimeException wrapException(Throwable e) {

public static class ExecutorPool {

private final static int POOL_CAPACITY = 2 * CoreOptions.CPUS;
private static final int POOL_CAPACITY = 2 * CoreOptions.CPUS;

private final String threadNamePrefix;
private final int executorWorkers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class GZipUtil {

private static final int BUF_SIZE = (int) (4 * Bytes.KB);

public static String md5(String input){
public static String md5(String input) {
return DigestUtils.md5Hex(input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@

public final class KryoUtil {

private static final ThreadLocal<Kryo> kryos = new ThreadLocal<>();
private static final ThreadLocal<Kryo> KRYOS = new ThreadLocal<>();

public static Kryo kryo() {
Kryo kryo = kryos.get();
Kryo kryo = KRYOS.get();
if (kryo != null) {
return kryo;
}

kryo = new Kryo();
registerSerializers(kryo);
kryos.set(kryo);
KRYOS.set(kryo);
return kryo;
}

Expand Down Expand Up @@ -70,9 +70,9 @@ public static byte[] toKryoWithType(Object value) {
kryo().writeClassAndObject(output, value);
output.flush();
return bos.toByteArray();
} catch (IOException e) {
throw new BackendException("Failed to serialize: %s", e, value);
}
} catch (IOException e) {
throw new BackendException("Failed to serialize: %s", e, value);
}
}

@SuppressWarnings("unchecked")
Expand Down
Loading