Skip to content

Commit

Permalink
code format (apache#2528)
Browse files Browse the repository at this point in the history
  • Loading branch information
laddcn authored and jerrick-zhu committed Sep 21, 2018
1 parent b411a77 commit 18dee4e
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public AbstractDirectory(URL url, List<Router> routers) {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public StaticDirectory(URL url, List<Invoker<T>> invokers) {

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ static int calculateWarmupWeight(int uptime, int warmup, int weight) {

@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,36 @@ else if ("&".equals(separator)) {
}
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public AbstractClusterInvoker(Directory<T> directory) {
}

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.
Expand Down Expand Up @@ -110,8 +111,9 @@ public void destroy() {
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,29 @@ private static String toUpperMethoName(String methodName) {
// 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ public static MetricName join(MetricName... parts) {
nameBuilder.append(name);
}

if (!part.getTags().isEmpty())
if (!part.getTags().isEmpty()) {
tags.putAll(part.getTags());
}
}

MetricLevel level = firstName == null ? null : firstName.getMetricLevel();
Expand All @@ -219,11 +220,13 @@ public static MetricName join(MetricName... parts) {
* @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);
}
Expand All @@ -233,8 +236,9 @@ private static String buildName(String... names) {
boolean first = true;

for (String name : names) {
if (name == null || name.isEmpty())
if (name == null || name.isEmpty()) {
continue;
}

if (first) {
first = false;
Expand Down Expand Up @@ -276,84 +280,102 @@ public int hashCode() {

@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);

for (final String key : keys) {
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;
Expand Down
Loading

0 comments on commit 18dee4e

Please sign in to comment.