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

optimize some code styles #4655

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Result invoke(Invocation invocation) throws RpcException {
Result result = null;

String value = directory.getUrl().getMethodParameter(invocation.getMethodName(), MOCK_KEY, Boolean.FALSE.toString()).trim();
if (value.length() == 0 || value.equalsIgnoreCase("false")) {
if (value.length() == 0 || "false".equalsIgnoreCase(value)) {
//no mock
result = this.invoker.invoke(invocation);
} else if (value.startsWith("force")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public JdkCompiler() {
StandardJavaFileManager manager = compiler.getStandardFileManager(diagnosticCollector, null, null);
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader instanceof URLClassLoader
&& (!loader.getClass().getName().equals("sun.misc.Launcher$AppClassLoader"))) {
&& (!"sun.misc.Launcher$AppClassLoader".equals(loader.getClass().getName()))) {
try {
URLClassLoader urlClassLoader = (URLClassLoader) loader;
List<File> files = new ArrayList<File>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public static boolean matchIpRange(String pattern, String host, int port) throws
throw new IllegalArgumentException("Illegal Argument pattern or hostName. Pattern:" + pattern + ", Host:" + host);
}
pattern = pattern.trim();
if (pattern.equals("*.*.*.*") || pattern.equals("*")) {
if ("*.*.*.*".equals(pattern) || "*".equals(pattern)) {
return true;
}

Expand Down Expand Up @@ -458,7 +458,7 @@ public static boolean matchIpRange(String pattern, String host, int port) throws
}
}
for (int i = 0; i < mask.length; i++) {
if (mask[i].equals("*") || mask[i].equals(ipAddress[i])) {
if ("*".equals(mask[i]) || mask[i].equals(ipAddress[i])) {
continue;
} else if (mask[i].contains("-")) {
String[] rangeNumStrs = mask[i].split("-");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,10 @@ private static Object newInstance(Class<?> cls) {
* @return
*/
private static Object getDefaultValue(Class<?> parameterType) {
if (parameterType.getName().equals("char")) {
if ("char".equals(parameterType.getName())) {
return Character.MIN_VALUE;
}
if (parameterType.getName().equals("bool")) {
if ("bool".equals(parameterType.getName())) {
return false;
}
return parameterType.isPrimitive() ? 0 : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package com.alibaba.dubbo.rpc.protocol.dubbo;

import org.apache.dubbo.rpc.AppResponse;
import org.apache.dubbo.rpc.Result;

import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.exchange.ResponseCallback;
import com.alibaba.dubbo.remoting.exchange.ResponseFuture;
import com.alibaba.dubbo.rpc.RpcException;

import org.apache.dubbo.rpc.AppResponse;
import org.apache.dubbo.rpc.Result;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -106,18 +106,22 @@ public void accept(Object obj, Throwable t) {
future.whenComplete(biConsumer);
}

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}

@Override
public boolean isCancelled() {
return false;
}

@Override
public boolean isDone() {
return future.isDone();
}

@Override
@SuppressWarnings("unchecked")
public V get() throws InterruptedException, ExecutionException {
try {
Expand All @@ -129,6 +133,7 @@ public V get() throws InterruptedException, ExecutionException {
}
}

@Override
@SuppressWarnings("unchecked")
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SimpleRegistryExporter {

private static final Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();

private static final ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
private static final ProxyFactory PROXY_FACTORY = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();

public synchronized static Exporter<RegistryService> exportIfAbsent(int port) {
try {
Expand All @@ -55,7 +55,7 @@ public static Exporter<RegistryService> export(int port) {
}

public static Exporter<RegistryService> export(int port, RegistryService registryService) {
return protocol.export(proxyFactory.getInvoker(registryService, RegistryService.class,
return protocol.export(PROXY_FACTORY.getInvoker(registryService, RegistryService.class,
new URLBuilder(DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName())
.setPath(RegistryService.class.getName())
.addParameter(INTERFACE_KEY, RegistryService.class.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ private boolean isSimplePropertySettingMethod(Method method) {
// 1. - setUnknownFields( com.google.protobuf.UnknownFieldSet unknownFields)
// 2. - setField(com.google.protobuf.Descriptors.FieldDescriptor field,java.lang.Object value)
// 3. - setRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field,int index,java.lang.Object value)
if (methodName.equals("setField") && types[0].equals(Descriptors.FieldDescriptor.class)
|| methodName.equals("setUnknownFields") && types[0].equals(UnknownFieldSet.class)
|| methodName.equals("setRepeatedField") && types[0].equals(Descriptors.FieldDescriptor.class)) {
if ("setField".equals(methodName) && types[0].equals(Descriptors.FieldDescriptor.class)
|| "setUnknownFields".equals(methodName) && types[0].equals(UnknownFieldSet.class)
|| "setRepeatedField".equals(methodName) && types[0].equals(Descriptors.FieldDescriptor.class)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SimpleRegistryExporter {

private static final Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();

private static final ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
private static final ProxyFactory PROXY_FACTORY = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();

public synchronized static Exporter<RegistryService> exportIfAbsent(int port) {
try {
Expand All @@ -56,7 +56,7 @@ public static Exporter<RegistryService> export(int port) {
}

public static Exporter<RegistryService> export(int port, RegistryService registryService) {
return protocol.export(proxyFactory.getInvoker(registryService, RegistryService.class,
return protocol.export(PROXY_FACTORY.getInvoker(registryService, RegistryService.class,
new URLBuilder(DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName())
.setPath(RegistryService.class.getName())
.addParameter(INTERFACE_KEY, RegistryService.class.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ private String toValue() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NacosServiceName)) return false;
if (this == o) {
return true;
}
if (!(o instanceof NacosServiceName)) {
return false;
}
NacosServiceName that = (NacosServiceName) o;
return Objects.equals(getValue(), that.getValue());
}
Expand All @@ -233,6 +237,7 @@ public int hashCode() {
return Objects.hash(getValue());
}

@Override
public String toString() {
return getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class StatusTelnetHandler implements TelnetHandler {

@Override
public String telnet(Channel channel, String message) {
if (message.equals("-l")) {
if ("-l".equals(message)) {
List<StatusChecker> checkers = extensionLoader.getActivateExtension(channel.getUrl(), "status");
String[] header = new String[]{"resource", "status", "message"};
List<List<String>> table = new ArrayList<List<String>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ private static byte isCallBack(URL url, String methodName, int argIndex) {
if (url != null) {
String callback = url.getParameter(methodName + "." + argIndex + ".callback");
if (callback != null) {
if (callback.equalsIgnoreCase("true")) {
if ("true".equalsIgnoreCase(callback)) {
isCallback = CALLBACK_CREATE;
} else if (callback.equalsIgnoreCase("false")) {
} else if ("false".equalsIgnoreCase(callback)) {
isCallback = CALLBACK_DESTROY;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String telnet(Channel channel, String message) {
return "Please input service name, eg: \r\ncd XxxService\r\ncd com.xxx.XxxService";
}
StringBuilder buf = new StringBuilder();
if (message.equals("/") || message.equals("..")) {
if ("/".equals(message) || "..".equals(message)) {
String service = (String) channel.getAttribute(SERVICE_KEY);
channel.removeAttribute(SERVICE_KEY);
buf.append("Cancelled default service " + service + ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String telnet(Channel channel, String message) throws RemotingException {
int sleepMilliseconds = 0;
if (StringUtils.isNotEmpty(message)) {
String[] parameters = message.split("\\s+");
if (parameters.length == 2 && parameters[0].equals("-t") && StringUtils.isInteger(parameters[1])) {
if (parameters.length == 2 && "-t".equals(parameters[0]) && StringUtils.isInteger(parameters[1])) {
sleepMilliseconds = Integer.parseInt(parameters[1]);
} else {
return "Invalid parameter,please input like shutdown -t 10000";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String uri = request.getRequestURI();
HessianSkeleton skeleton = skeletonMap.get(uri);
if (!request.getMethod().equalsIgnoreCase("POST")) {
if (!"POST".equalsIgnoreCase(request.getMethod())) {
response.setStatus(500);
} else {
RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String uri = request.getRequestURI();
HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
if (!request.getMethod().equalsIgnoreCase("POST")) {
if (!"POST".equalsIgnoreCase(request.getMethod())) {
response.setStatus(500);
} else {
RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public void handle(HttpServletRequest request, HttpServletResponse response)
response.setHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER, "POST");
response.setHeader(ACCESS_CONTROL_ALLOW_HEADERS_HEADER, "*");
}
if (request.getMethod().equalsIgnoreCase("OPTIONS")) {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
response.setStatus(200);
} else if (request.getMethod().equalsIgnoreCase("POST")) {
} else if ("POST".equalsIgnoreCase(request.getMethod())) {

RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public void handle(HttpServletRequest request, HttpServletResponse response)
response.setHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER, "POST");
response.setHeader(ACCESS_CONTROL_ALLOW_HEADERS_HEADER, "*");
}
if (request.getMethod().equalsIgnoreCase("OPTIONS")) {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
response.setStatus(200);
} else if (request.getMethod().equalsIgnoreCase("POST")) {
} else if ("POST".equalsIgnoreCase(request.getMethod())) {

RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Object invoke(MethodInvocation invocation)

// handle toString()
Method method = invocation.getMethod();
if (method.getDeclaringClass() == Object.class && method.getName().equals("toString")) {
if (method.getDeclaringClass() == Object.class && "toString".equals(method.getName())) {
return proxyObject.getClass().getName() + "@" + System.identityHashCode(proxyObject);
}

Expand Down
Loading