Skip to content

Commit

Permalink
optimize some code styles (#4260)
Browse files Browse the repository at this point in the history
* optimize some code styles

Signed-off-by: jimin.jm <slievrly@163.com>

* optimize some code styles

Signed-off-by: jimin.jm <slievrly@163.com>
  • Loading branch information
slievrly authored and beiwei30 committed Jul 22, 2019
1 parent 9960d23 commit 764b8df
Show file tree
Hide file tree
Showing 52 changed files with 148 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ public void testMapArrayMerger() {
*/
@Test
public void testLongArrayMerger() {
long[] arrayOne = {1l, 2l};
long[] arrayTwo = {2l, 34l};
long[] arrayOne = {1L, 2L};
long[] arrayTwo = {2L, 34L};
long[] result = MergerFactory.getMerger(long[].class).merge(arrayOne, arrayTwo, null);
Assertions.assertEquals(4, result.length);
double[] mergedResult = {1l, 2l, 2l, 34l};
double[] mergedResult = {1L, 2L, 2L, 34L};
for (int i = 0; i < mergedResult.length; i++) {
Assertions.assertEquals(mergedResult[i], result[i], 0.0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ public void testSelectBalance() {
}

Assertions.assertEquals(runs, counter.get(invoker2).get() + counter.get(invoker4).get());
;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Object call() throws Exception {
clusterinvoker.invoke(inv);
}

public static interface Demo {
public interface Demo {
}

public static class MockInvoker<T> extends AbstractInvoker<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

public interface MenuService {

public Menu getMenu();
Menu getMenu();

public void addMenu(String menu, List<String> items);
void addMenu(String menu, List<String> items);

}
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ private Invoker<IHelloService> getClusterInvoker(URL url) {
return getClusterInvokerMock(url, null);
}

public static interface IHelloService {
public interface IHelloService {
String getSomething();

String getSomething2();
Expand All @@ -688,9 +688,9 @@ public static interface IHelloService {

Boolean getBoolean2();

public List<String> getListString();
List<String> getListString();

public List<User> getUsers();
List<User> getUsers();

void sayHello();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public interface CommonConstants {

Pattern COMMA_SPLIT_PATTERN = Pattern.compile("\\s*[,]+\\s*");

public final static String PATH_SEPARATOR = "/";
String PATH_SEPARATOR = "/";

public final static String PROTOCOL_SEPARATOR = "://";
String PROTOCOL_SEPARATOR = "://";

String REGISTRY_SEPARATOR = "|";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
@Deprecated
public interface JSONVisitor {
public static final String CLASS_PROPERTY = "class";
String CLASS_PROPERTY = "class";

/**
* parse begin .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testCglibProxy() throws Exception {
}
}

public static interface ITest {
public interface ITest {
String getName();

void setName(String name, String name2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ public void test_getMethodNames_ContainExtendsParentMethods() throws Exception {
assertArrayEquals(new String[]{"hello", "world"}, Wrapper.getWrapper(Son.class).getMethodNames());
}

public static interface I0 {
public interface I0 {
String getName();
}

public static interface I1 extends I0 {
public interface I1 extends I0 {
void setName(String name);

void hello(String name);
Expand All @@ -147,19 +147,19 @@ public static interface I1 extends I0 {
void setFloat(float f);
}

public static interface EmptyService {
public interface EmptyService {
}

public static interface Parent1 {
public interface Parent1 {
void hello();
}


public static interface Parent2 {
public interface Parent2 {
void world();
}

public static interface Son extends Parent1, Parent2 {
public interface Son extends Parent1, Parent2 {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
package org.apache.dubbo.common.extension.ext6_inject;

public interface Dao {
public void update();
void update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -47,7 +48,7 @@ public class IOUtilsTest {

@BeforeEach
public void setUp() throws Exception {
is = new ByteArrayInputStream(TEXT.getBytes("UTF-8"));
is = new ByteArrayInputStream(TEXT.getBytes(StandardCharsets.UTF_8));
os = new ByteArrayOutputStream();
reader = new StringReader(TEXT);
writer = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void testGetReturnTypes () throws Exception{
Assertions.assertEquals("java.util.List<java.lang.String>", types2[1].getTypeName());
}

public static interface TypeClass {
public interface TypeClass {

CompletableFuture<String> getFuture();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public int hashCode() {
return result;
}

static public enum TestEnum {
public enum TestEnum {
VALUE1, VALUE2
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public String toString() {
+ ")";
}

public static interface KeyGenerator {
public interface KeyGenerator {
String generateKey(ReferenceConfig<?> referenceConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@

public interface JValidatorTestTarget {
@MethodValidated
public void someMethod1(String anything);
void someMethod1(String anything);

@MethodValidated(Test2.class)
public void someMethod2(@NotNull ValidationParameter validationParameter);
void someMethod2(@NotNull ValidationParameter validationParameter);

public void someMethod3(ValidationParameter[] parameters);
void someMethod3(ValidationParameter[] parameters);

public void someMethod4(List<String> strings);
void someMethod4(List<String> strings);

public void someMethod5(Map<String, String> map);
void someMethod5(Map<String, String> map);

@interface Test2 {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

public enum ColorEnum {

RED, YELLOW, BLUE;
RED, YELLOW, BLUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public int hashCode() {
return result;
}

static public enum TestEnum {
public enum TestEnum {
VALUE1, VALUE2
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void setApplication(String application) {
this.application = application;
}

public static enum KeyTypeEnum {
public enum KeyTypeEnum {
PATH, UNIQUE_KEY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.identifier.MetadataIdentifier.KeyTypeEnum;
import org.apache.dubbo.metadata.store.MetadataReport;

import com.google.gson.Gson;
Expand Down Expand Up @@ -190,9 +191,9 @@ private void saveProperties(MetadataIdentifier metadataIdentifier, String value,

try {
if (add) {
properties.setProperty(metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), value);
properties.setProperty(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), value);
} else {
properties.remove(metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
properties.remove(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
}
long version = lastCacheChanged.incrementAndGet();
if (sync) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metadata.identifier;

import org.apache.dubbo.metadata.identifier.MetadataIdentifier.KeyTypeEnum;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -34,12 +35,12 @@ public void testGetUniqueKey() {
String group = null;
String application = "vic.zk.md";
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH),
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.PATH),
"metadata" + PATH_SEPARATOR + interfaceName + PATH_SEPARATOR +
(version == null ? "" : (version + PATH_SEPARATOR))
+ (group == null ? "" : (group + PATH_SEPARATOR)) + PROVIDER_SIDE
+ PATH_SEPARATOR + application);
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY),
interfaceName + MetadataIdentifier.SEPARATOR +
(version == null ? "" : version) + MetadataIdentifier.SEPARATOR
+ (group == null ? "" : group) + MetadataIdentifier.SEPARATOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
*/
public interface InterfaceNameTestService2 {

public void test2();
void test2();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.retry.ExponentialBackoffRetry;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -233,7 +234,7 @@ public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exc

if (data.getPath().split("/").length == 5) {
byte[] value = data.getData();
String stringValue = new String(value, "utf-8");
String stringValue = new String(value, StandardCharsets.UTF_8);

// fire event to all listeners
Map<String, Object> added = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void testDoRetry_nofify() throws Exception {
public void notify(List<URL> urls) {
count.incrementAndGet();
//The exception is thrown for the first time to see if the back will be called again to incrementAndGet
if (count.get() == 1l) {
if (count.get() == 1L) {
throw new RuntimeException("test exception please ignore");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ public void testDubbo1UrlWithGenericInvocation() {

}

;

/**
* When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
*/
Expand Down Expand Up @@ -1083,7 +1081,7 @@ enum Param {
MORGAN,
}

private static interface DemoService {
private interface DemoService {
}

private static class MockRegistry implements Registry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* not an instance of {@link ChannelBuffer} type.
*/
@Override
public boolean equals(Object o);
boolean equals(Object o);

/**
* Returns the factory which creates a {@link ChannelBuffer} whose type and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Object reply(ExchangeChannel channel, RpcMessage msg) throws RemotingExce

}

public static interface ServiceProvider {
public interface ServiceProvider {
Object getImplementation(String service);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public void test_Encode_Response() throws IOException {
Channel channel = getCliendSideChannel(url);
Response response = new Response();
response.setHeartbeat(true);
response.setId(1001l);
response.setId(1001L);
response.setStatus((byte) 20);
response.setVersion("11");
Person person = new Person();
Expand Down Expand Up @@ -379,7 +379,7 @@ public void test_Encode_Error_Response() throws IOException {
Channel channel = getCliendSideChannel(url);
Response response = new Response();
response.setHeartbeat(true);
response.setId(1001l);
response.setId(1001L);
response.setStatus((byte) 10);
response.setVersion("11");
String badString = "bad";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public void test_Connect_Biz_Error() throws RemotingException {
Assertions.assertThrows(RemotingException.class, () -> handler.connected(new MockedChannel()));
}

;

@Test
public void test_Disconnect_Biz_Error() throws RemotingException {
Assertions.assertThrows(RemotingException.class, () -> handler.disconnected(new MockedChannel()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public interface EtcdClient {
* @throws TimeoutException if the wait timed out
* @return lease id from etcd
*/
public long createLease(long ttl, long timeout, TimeUnit unit)
long createLease(long ttl, long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public interface RetryPolicy {
* @param sleep should be sleep
* @return true should be retry
*/
public boolean shouldRetry(int retried, long elapsed, boolean sleep);
boolean shouldRetry(int retried, long elapsed, boolean sleep);

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exc
curatorClient.delete(path);
valueFromCache = curatorClient.getContent(path + "/d.json");
Assertions.assertNull(valueFromCache);
Thread.sleep(2000l);
Assertions.assertTrue(9l >= atomicInteger.get());
Assertions.assertTrue(2l <= atomicInteger.get());
Thread.sleep(2000L);
Assertions.assertTrue(9L >= atomicInteger.get());
Assertions.assertTrue(2L <= atomicInteger.get());
}
}
Loading

0 comments on commit 764b8df

Please sign in to comment.