code format (#2528)

This commit is contained in:
Lei Jiang 2018-09-21 08:57:27 +08:00 committed by Jerrick Zhu
parent b411a777b3
commit 18dee4e44d
21 changed files with 180 additions and 90 deletions

View File

@ -59,8 +59,9 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
}
public AbstractDirectory(URL url, URL consumerUrl, List<Router> routers) {
if (url == null)
if (url == null) {
throw new IllegalArgumentException("url == null");
}
this.url = url;
this.consumerUrl = consumerUrl;
setRouters(routers);

View File

@ -46,8 +46,9 @@ public class StaticDirectory<T> extends AbstractDirectory<T> {
public StaticDirectory(URL url, List<Invoker<T>> invokers, List<Router> routers) {
super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routers);
if (invokers == null || invokers.isEmpty())
if (invokers == null || invokers.isEmpty()) {
throw new IllegalArgumentException("invokers == null");
}
this.invokers = invokers;
}

View File

@ -37,10 +37,12 @@ public abstract class AbstractLoadBalance implements LoadBalance {
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
if (invokers == null || invokers.isEmpty())
if (invokers == null || invokers.isEmpty()) {
return null;
if (invokers.size() == 1)
}
if (invokers.size() == 1) {
return invokers.get(0);
}
return doSelect(invokers, url, invocation);
}

View File

@ -75,8 +75,9 @@ public class LeastActiveLoadBalance extends AbstractLoadBalance {
for (int i = 0; i < leastCount; i++) {
int leastIndex = leastIndexes[i];
offsetWeight -= getWeight(invokers.get(leastIndex), invocation);
if (offsetWeight <= 0)
if (offsetWeight <= 0) {
return invokers.get(leastIndex);
}
}
}
// If all invokers have the same weight value or totalWeight=0, return evenly.

View File

@ -40,9 +40,9 @@ public class MockInvokersSelector implements Router {
return getNormalInvokers(invokers);
} else {
String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK);
if (value == null)
if (value == null) {
return getNormalInvokers(invokers);
else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
} else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
return getMockedInvokers(invokers);
}
}

View File

@ -105,33 +105,36 @@ public class ConditionRouter implements Router, Comparable<Router> {
}
// The Value in the KV part.
else if ("=".equals(separator)) {
if (pair == null)
if (pair == null) {
throw new ParseException("Illegal route rule \""
+ rule + "\", The error char '" + separator
+ "' at index " + matcher.start() + " before \""
+ content + "\".", matcher.start());
}
values = pair.matches;
values.add(content);
}
// The Value in the KV part.
else if ("!=".equals(separator)) {
if (pair == null)
if (pair == null) {
throw new ParseException("Illegal route rule \""
+ rule + "\", The error char '" + separator
+ "' at index " + matcher.start() + " before \""
+ content + "\".", matcher.start());
}
values = pair.mismatches;
values.add(content);
}
// The Value in the KV part, if Value have more than one items.
else if (",".equals(separator)) { // Should be seperateed by ','
if (values == null || values.isEmpty())
if (values == null || values.isEmpty()) {
throw new ParseException("Illegal route rule \""
+ rule + "\", The error char '" + separator
+ "' at index " + matcher.start() + " before \""
+ content + "\".", matcher.start());
}
values.add(content);
} else {
throw new ParseException("Illegal route rule \"" + rule

View File

@ -59,8 +59,9 @@ public abstract class AbstractClusterInvoker<T> implements Invoker<T> {
}
public AbstractClusterInvoker(Directory<T> directory, URL url) {
if (directory == null)
if (directory == null) {
throw new IllegalArgumentException("service directory == null");
}
this.directory = directory;
//sticky: invoker.isAvailable() should always be checked before using when availablecheck is true.
@ -110,8 +111,9 @@ public abstract class AbstractClusterInvoker<T> implements Invoker<T> {
* @throws RpcException
*/
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
if (invokers == null || invokers.isEmpty())
if (invokers == null || invokers.isEmpty()) {
return null;
}
String methodName = invocation == null ? "" : invocation.getMethodName();
boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);

View File

@ -202,28 +202,29 @@ public class JValidator implements Validator {
// Copy from javassist.bytecode.annotation.Annotation.createMemberValue(ConstPool, CtClass);
private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
if (memberValue instanceof BooleanMemberValue)
if (memberValue instanceof BooleanMemberValue) {
((BooleanMemberValue) memberValue).setValue((Boolean) value);
else if (memberValue instanceof ByteMemberValue)
} else if (memberValue instanceof ByteMemberValue) {
((ByteMemberValue) memberValue).setValue((Byte) value);
else if (memberValue instanceof CharMemberValue)
} else if (memberValue instanceof CharMemberValue) {
((CharMemberValue) memberValue).setValue((Character) value);
else if (memberValue instanceof ShortMemberValue)
} else if (memberValue instanceof ShortMemberValue) {
((ShortMemberValue) memberValue).setValue((Short) value);
else if (memberValue instanceof IntegerMemberValue)
} else if (memberValue instanceof IntegerMemberValue) {
((IntegerMemberValue) memberValue).setValue((Integer) value);
else if (memberValue instanceof LongMemberValue)
} else if (memberValue instanceof LongMemberValue) {
((LongMemberValue) memberValue).setValue((Long) value);
else if (memberValue instanceof FloatMemberValue)
} else if (memberValue instanceof FloatMemberValue) {
((FloatMemberValue) memberValue).setValue((Float) value);
else if (memberValue instanceof DoubleMemberValue)
} else if (memberValue instanceof DoubleMemberValue) {
((DoubleMemberValue) memberValue).setValue((Double) value);
else if (memberValue instanceof ClassMemberValue)
} else if (memberValue instanceof ClassMemberValue) {
((ClassMemberValue) memberValue).setValue(((Class<?>) value).getName());
else if (memberValue instanceof StringMemberValue)
} else if (memberValue instanceof StringMemberValue) {
((StringMemberValue) memberValue).setValue((String) value);
else if (memberValue instanceof EnumMemberValue)
} else if (memberValue instanceof EnumMemberValue) {
((EnumMemberValue) memberValue).setValue(((Enum<?>) value).name());
}
/* else if (memberValue instanceof AnnotationMemberValue) */
else if (memberValue instanceof ArrayMemberValue) {
CtClass arrayType = type.getComponentType();

View File

@ -204,8 +204,9 @@ public class MetricName implements Comparable<MetricName> {
nameBuilder.append(name);
}
if (!part.getTags().isEmpty())
if (!part.getTags().isEmpty()) {
tags.putAll(part.getTags());
}
}
MetricLevel level = firstName == null ? null : firstName.getMetricLevel();
@ -219,11 +220,13 @@ public class MetricName implements Comparable<MetricName> {
* @return A newly created metric name with the specified path.
**/
public static MetricName build(String... parts) {
if (parts == null || parts.length == 0)
if (parts == null || parts.length == 0) {
return MetricName.EMPTY;
}
if (parts.length == 1)
if (parts.length == 1) {
return new MetricName(parts[0], EMPTY_TAGS);
}
return new MetricName(buildName(parts), EMPTY_TAGS);
}
@ -233,8 +236,9 @@ public class MetricName implements Comparable<MetricName> {
boolean first = true;
for (String name : names) {
if (name == null || name.isEmpty())
if (name == null || name.isEmpty()) {
continue;
}
if (first) {
first = false;
@ -276,64 +280,78 @@ public class MetricName implements Comparable<MetricName> {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
}
if (obj == null)
if (obj == null) {
return false;
}
if (getClass() != obj.getClass())
if (getClass() != obj.getClass()) {
return false;
}
MetricName other = (MetricName) obj;
if (key == null) {
if (other.key != null)
if (other.key != null) {
return false;
} else if (!key.equals(other.key))
}
} else if (!key.equals(other.key)) {
return false;
}
if (!tags.equals(other.tags))
if (!tags.equals(other.tags)) {
return false;
}
return true;
}
@Override
public int compareTo(MetricName o) {
if (o == null)
if (o == null) {
return -1;
}
int c = compareName(key, o.getKey());
if (c != 0)
if (c != 0) {
return c;
}
return compareTags(tags, o.getTags());
}
private int compareName(String left, String right) {
if (left == null && right == null)
if (left == null && right == null) {
return 0;
}
if (left == null)
if (left == null) {
return 1;
}
if (right == null)
if (right == null) {
return -1;
}
return left.compareTo(right);
}
private int compareTags(Map<String, String> left, Map<String, String> right) {
if (left == null && right == null)
if (left == null && right == null) {
return 0;
}
if (left == null)
if (left == null) {
return 1;
}
if (right == null)
if (right == null) {
return -1;
}
final Iterable<String> keys = uniqueSortedKeys(left, right);
@ -341,19 +359,23 @@ public class MetricName implements Comparable<MetricName> {
final String a = left.get(key);
final String b = right.get(key);
if (a == null && b == null)
if (a == null && b == null) {
continue;
}
if (a == null)
if (a == null) {
return -1;
}
if (b == null)
if (b == null) {
return 1;
}
int c = a.compareTo(b);
if (c != 0)
if (c != 0) {
return c;
}
}
return 0;

View File

@ -140,48 +140,65 @@ public class Statistics implements Serializable {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
Statistics other = (Statistics) obj;
if (application == null) {
if (other.application != null)
if (other.application != null) {
return false;
} else if (!application.equals(other.application))
}
} else if (!application.equals(other.application)) {
return false;
}
if (client == null) {
if (other.client != null)
if (other.client != null) {
return false;
} else if (!client.equals(other.client))
}
} else if (!client.equals(other.client)) {
return false;
}
if (group == null) {
if (other.group != null)
if (other.group != null) {
return false;
} else if (!group.equals(other.group))
}
} else if (!group.equals(other.group)) {
return false;
}
if (method == null) {
if (other.method != null)
if (other.method != null) {
return false;
} else if (!method.equals(other.method))
}
} else if (!method.equals(other.method)) {
return false;
}
if (server == null) {
if (other.server != null)
if (other.server != null) {
return false;
} else if (!server.equals(other.server))
}
} else if (!server.equals(other.server)) {
return false;
}
if (service == null) {
if (other.service != null)
if (other.service != null) {
return false;
} else if (!service.equals(other.service))
}
} else if (!service.equals(other.service)) {
return false;
}
if (version == null) {
if (other.version != null)
if (other.version != null) {
return false;
} else if (!version.equals(other.version))
}
} else if (!version.equals(other.version)) {
return false;
}
return true;
}

View File

@ -96,10 +96,12 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
public RegistryDirectory(Class<T> serviceType, URL url) {
super(url);
if (serviceType == null)
if (serviceType == null) {
throw new IllegalArgumentException("service type is null.");
if (url.getServiceKey() == null || url.getServiceKey().length() == 0)
}
if (url.getServiceKey() == null || url.getServiceKey().length() == 0) {
throw new IllegalArgumentException("registry serviceKey is null.");
}
this.serviceType = serviceType;
this.serviceKey = url.getServiceKey();
this.queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
@ -318,8 +320,9 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
}
try {
Router router = routerFactory.getRouter(url);
if (!routers.contains(router))
if (!routers.contains(router)) {
routers.add(router);
}
} catch (Throwable t) {
logger.error("convert router url to router error, url: " + url, t);
}

View File

@ -349,7 +349,9 @@ public abstract class AbstractRegistry implements Registry {
}
protected void notify(List<URL> urls) {
if (urls == null || urls.isEmpty()) return;
if (urls == null || urls.isEmpty()) {
return;
}
for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
URL url = entry.getKey();

View File

@ -116,8 +116,9 @@ public class DubboRegistry extends FailbackRegistry {
@Override
public boolean isAvailable() {
if (registryInvoker == null)
if (registryInvoker == null) {
return false;
}
return registryInvoker.isAvailable();
}

View File

@ -90,22 +90,30 @@ public class RedisRegistry extends FailbackRegistry {
config.setTestOnBorrow(url.getParameter("test.on.borrow", true));
config.setTestOnReturn(url.getParameter("test.on.return", false));
config.setTestWhileIdle(url.getParameter("test.while.idle", false));
if (url.getParameter("max.idle", 0) > 0)
if (url.getParameter("max.idle", 0) > 0) {
config.setMaxIdle(url.getParameter("max.idle", 0));
if (url.getParameter("min.idle", 0) > 0)
}
if (url.getParameter("min.idle", 0) > 0) {
config.setMinIdle(url.getParameter("min.idle", 0));
if (url.getParameter("max.active", 0) > 0)
}
if (url.getParameter("max.active", 0) > 0) {
config.setMaxTotal(url.getParameter("max.active", 0));
if (url.getParameter("max.total", 0) > 0)
}
if (url.getParameter("max.total", 0) > 0) {
config.setMaxTotal(url.getParameter("max.total", 0));
if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0)
}
if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0) {
config.setMaxWaitMillis(url.getParameter("max.wait", url.getParameter("timeout", 0)));
if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
}
if (url.getParameter("num.tests.per.eviction.run", 0) > 0) {
config.setNumTestsPerEvictionRun(url.getParameter("num.tests.per.eviction.run", 0));
if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
}
if (url.getParameter("time.between.eviction.runs.millis", 0) > 0) {
config.setTimeBetweenEvictionRunsMillis(url.getParameter("time.between.eviction.runs.millis", 0));
if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
}
if (url.getParameter("min.evictable.idle.time.millis", 0) > 0) {
config.setMinEvictableIdleTimeMillis(url.getParameter("min.evictable.idle.time.millis", 0));
}
String cluster = url.getParameter("cluster", "failover");
if (!"failover".equals(cluster) && !"replicate".equals(cluster)) {

View File

@ -57,7 +57,9 @@ public class Request {
}
private static String safeToString(Object data) {
if (data == null) return null;
if (data == null) {
return null;
}
String dataStr;
try {
dataStr = data.toString();

View File

@ -221,13 +221,23 @@ final class HeaderExchangeChannel implements ExchangeChannel {
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
HeaderExchangeChannel other = (HeaderExchangeChannel) obj;
if (channel == null) {
if (other.channel != null) return false;
} else if (!channel.equals(other.channel)) return false;
if (other.channel != null) {
return false;
}
} else if (!channel.equals(other.channel)) {
return false;
}
return true;
}

View File

@ -139,8 +139,9 @@ public class HeaderExchangeServer implements ExchangeServer {
Collection<Channel> channels = getChannels();
for (Channel channel : channels) {
try {
if (channel.isConnected())
if (channel.isConnected()) {
channel.send(request, getUrl().getParameter(Constants.CHANNEL_READONLYEVENT_SENT_KEY, true));
}
} catch (RemotingException e) {
logger.warn("send cannot write message error.", e);
}

View File

@ -101,8 +101,9 @@ public class GrizzlyClient extends AbstractClient {
@Override
protected Channel getChannel() {
Connection<?> c = connection;
if (c == null || !c.isOpen())
if (c == null || !c.isOpen()) {
return null;
}
return GrizzlyChannel.getOrAddChannel(c, getUrl(), this);
}

View File

@ -165,8 +165,9 @@ public class MinaClient extends AbstractClient {
@Override
protected Channel getChannel() {
IoSession s = session;
if (s == null || !s.isConnected())
if (s == null || !s.isConnected()) {
return null;
}
return MinaChannel.getOrAddChannel(s, getUrl(), this);
}

View File

@ -178,13 +178,23 @@ final class NettyChannel extends AbstractChannel {
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
NettyChannel other = (NettyChannel) obj;
if (channel == null) {
if (other.channel != null) return false;
} else if (!channel.equals(other.channel)) return false;
if (other.channel != null) {
return false;
}
} else if (!channel.equals(other.channel)) {
return false;
}
return true;
}

View File

@ -43,8 +43,9 @@ public class CompactedObjectInputStream extends ObjectInputStream {
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
int type = read();
if (type < 0)
if (type < 0) {
throw new EOFException();
}
switch (type) {
case 0:
return super.readClassDescriptor();