HugeGraph-410: fixed code style of hugegraph-common

Change-Id: I8e123a315e483ed66658ce93c3eaffa61d94cfb3
This commit is contained in:
liningrui 2017-07-11 15:31:03 +08:00
parent 7bdf878dd4
commit 36959044a1
9 changed files with 97 additions and 81 deletions

View File

@ -16,7 +16,8 @@ import com.google.common.collect.ImmutableSet;
*/
public class ConfigOption<T> {
private static final Logger logger = LoggerFactory.getLogger(ConfigOption.class);
private static final Logger logger =
LoggerFactory.getLogger(ConfigOption.class);
private static final Set<Class<?>> ACCEPTED_DATATYPES;
private static final String ACCEPTED_DATATYPES_STRING;
@ -45,20 +46,20 @@ public class ConfigOption<T> {
private final Predicate<T> checkFunc;
public ConfigOption(String name, T value, Boolean rewritable, String desc,
Predicate<T> verifyFunc) {
this(name, (Class<T>) value.getClass(), value, rewritable, desc, verifyFunc);
Predicate<T> func) {
this(name, (Class<T>) value.getClass(), value, rewritable, desc, func);
}
public ConfigOption(String name, Class<T> dataType, T value, Boolean
rewritable, String desc, Predicate<T> checkFunc) {
public ConfigOption(String name, Class<T> dataType, T value,
Boolean rewritable, String desc, Predicate<T> func) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(dataType);
Preconditions.checkNotNull(rewritable);
if (!ACCEPTED_DATATYPES.contains(dataType)) {
String msg = String.format("Input datatype: '%s' doesn't belong "
+ "to acceptable type set: [%s]",
dataType, ACCEPTED_DATATYPES_STRING);
String msg = String.format("Input datatype: '%s' doesn't belong " +
"to acceptable type set: [%s]",
dataType, ACCEPTED_DATATYPES_STRING);
logger.error(msg);
throw new IllegalArgumentException(msg);
}
@ -68,7 +69,7 @@ public class ConfigOption<T> {
this.value = value;
this.rewritable = rewritable;
this.desc = desc;
this.checkFunc = checkFunc;
this.checkFunc = func;
if (this.checkFunc != null) {
check(this.value);
@ -93,19 +94,22 @@ public class ConfigOption<T> {
public void value(T value) {
check(value);
E.checkArgument(this.rewritable, "Not allowed to modify option: '%s' "
+ "which is unrewritable", this.name);
E.checkArgument(this.rewritable,
"Not allowed to modify option: '%s' which " +
"is unrewritable", this.name);
this.value = value;
}
public void check(Object value) {
E.checkNotNull(value, "value", this.name);
E.checkArgument(this.dataType.isInstance(value),
"Invalid class for option '%s'. Expected '%s' but given '%s'",
this.name, this.dataType, value.getClass());
"Invalid class for option '%s'. Expected '%s' but " +
"given '%s'", this.name, this.dataType,
value.getClass());
T result = (T) value;
E.checkArgument(this.checkFunc.apply(result),
"Invalid option value for [%s]: %s", this.name, value);
"Invalid option value for [%s]: %s",
this.name, value);
}
}

View File

@ -61,8 +61,8 @@ public class HugeConfig extends PropertiesConfiguration {
File file = new File(fileName);
E.checkArgument(file.exists() && file.isFile() && file.canRead(),
"Need to specify a readable config file, " +
"but got: %s", file.toString());
"Need to specify a readable config file, " +
"but got: %s", file.toString());
return file;
}
@ -79,7 +79,7 @@ public class HugeConfig extends PropertiesConfiguration {
Class dataType = option.dataType();
String getMethod = "get" + dataType.getSimpleName();
Method method = this.getClass()
.getMethod(getMethod, String.class, dataType);
.getMethod(getMethod, String.class, dataType);
option.value(method.invoke(this, key, option.value()));
}
} catch (Exception e) {

View File

@ -14,7 +14,8 @@ import com.baidu.hugegraph.exception.ConfigException;
*/
public class OptionHolder {
private static final Logger logger = LoggerFactory.getLogger(HugeConfig.class);
private static final Logger logger =
LoggerFactory.getLogger(HugeConfig.class);
protected Map<String, ConfigOption> options;
@ -29,7 +30,8 @@ public class OptionHolder {
ConfigOption option = (ConfigOption) field.get(this);
this.options.put(option.name(), option);
} catch (Exception e) {
String msg = String.format("Failed to regiser option : %s", field);
String msg = String.format(
"Failed to regiser option : %s", field);
logger.error(msg, e);
throw new ConfigException(msg, e);
}

View File

@ -13,7 +13,8 @@ import com.google.common.collect.Maps;
*/
public class OptionSpace {
private static final Logger logger = LoggerFactory.getLogger(OptionSpace.class);
private static final Logger logger =
LoggerFactory.getLogger(OptionSpace.class);
private static final Map<String, ConfigOption> options = Maps.newHashMap();

View File

@ -32,7 +32,8 @@ import javassist.NotFoundException;
public class PerfUtil {
private static final Logger logger = LoggerFactory.getLogger(PerfUtil.class);
private static final Logger logger =
LoggerFactory.getLogger(PerfUtil.class);
private static ThreadLocal<PerfUtil> instance = new ThreadLocal<>();
private Map<String, Stopwatch> stopwatches;
@ -40,7 +41,7 @@ public class PerfUtil {
private PerfUtil() {
this.stopwatches = new HashMap<>();
this.callStack = new Stack<String>();
this.callStack = new Stack<>();
}
public static PerfUtil instance() {
@ -143,7 +144,8 @@ public class PerfUtil {
}
ctMethod.insertBefore(String.format(START, name));
ctMethod.insertAfter(String.format(END, name), true); // asFinally true
// Insert as a finally-statement
ctMethod.insertAfter(String.format(END, name), true);
logger.debug("Profiled for: '{}' [{}]", name, ctMethod.getLongName());
}
@ -193,13 +195,13 @@ public class PerfUtil {
sb.append("name: 'Total Cost',");
sb.append("type: 'pie',");
sb.append(String.format("radius: ['%s%%', '%s%%'],",
radiusFrom, radiusTo));
radiusFrom, radiusTo));
sb.append(String.format(
"label: {normal: {position: 'inner', formatter:"
+ "function(params) {"
+ " if (params.percent > %s) return params.data.name;"
+ " else return '';"
+ "}}},", showFactor));
"label: {normal: {position: 'inner', formatter:" +
"function(params) {" +
" if (params.percent > %s) return params.data.name;" +
" else return '';" +
"}}},", showFactor));
sb.append("data: [");
items.sort((i, j) -> i.id().compareTo(j.id()));
@ -239,8 +241,8 @@ public class PerfUtil {
return sb.toString();
};
BiConsumer<List<Stopwatch>, List<Stopwatch>> fillOther = (
itemsOfI, parents) -> {
BiConsumer<List<Stopwatch>, List<Stopwatch>> fillOther =
(itemsOfI, parents) -> {
for (Stopwatch parent : parents) {
Stream<Stopwatch> children = itemsOfI.stream().filter(c -> {
return c.parent().equals(parent.id());

View File

@ -97,9 +97,9 @@ public class Stopwatch implements Cloneable {
}
public String toJson() {
return String.format("{\"totalCost\":%s, "
+ "\"minCost\":%s, \"maxCost\":%s, \"times\":%s, "
+ "\"name\":\"%s\", \"parent\":\"%s\"}",
return String.format("{\"totalCost\":%s, " +
"\"minCost\":%s, \"maxCost\":%s, \"times\":%s, " +
"\"name\":\"%s\", \"parent\":\"%s\"}",
this.totalCost,
this.minCost,
this.maxCost,

View File

@ -0,0 +1,52 @@
package com.baidu.hugegraph.type;
/**
* Shard is used for backend storage (like cassandra, hbase) scanning
* operations. Each shard represents a range of tokens for a node.
* Reading data from a given shard does not cross multiple nodes.
*/
public class Shard {
// token range start
private String start;
// token range end
private String end;
// partitions count in this range
private long length;
public Shard(String start, String end, long length) {
this.start = start;
this.end = end;
this.length = length;
}
public String start() {
return this.start;
}
public void start(String start) {
this.start = start;
}
public String end() {
return this.end;
}
public void end(String end) {
this.end = end;
}
public long length() {
return this.length;
}
public void length(long length) {
this.length = length;
}
@Override
public String toString() {
return String.format("Shard{start=%s, end=%s, length=%s}",
this.start, this.end, this.length);
}
}

View File

@ -1,44 +0,0 @@
package com.baidu.hugegraph.type;
public class Split {
private String start; // token range start
private String end; // token range end
private long length; // partitions count in this range
public Split(String start, String end, long length) {
this.start = start;
this.end = end;
this.length = length;
}
public String start() {
return this.start;
}
public void start(String start) {
this.start = start;
}
public String end() {
return this.end;
}
public void end(String end) {
this.end = end;
}
public long length() {
return this.length;
}
public void length(long length) {
this.length = length;
}
@Override
public String toString() {
return String.format("Split{start=%s, end=%s, length=%s}",
this.start, this.end, this.length);
}
}

View File

@ -42,9 +42,8 @@ public class CheckSocket {
System.exit(E_USAGE);
}
try {
Socket s = new Socket(
InetAddress.getByName(args[0]),
Integer.valueOf(args[1]).intValue());
Socket s = new Socket(InetAddress.getByName(args[0]),
Integer.valueOf(args[1]).intValue());
s.close();
System.exit(0);
} catch (Throwable t) {