Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCao committed Jun 26, 2019
1 parent 781273f commit 34025a5
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class NacosConfigService implements ConfigService {

private static final Logger LOGGER = LogUtils.logger(NacosConfigService.class);

private final long POST_TIMEOUT = 3000L;
private static final long POST_TIMEOUT = 3000L;

private static final String EMPTY = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class Limiter {

private static final Logger LOGGER = LogUtils.logger(Limiter.class);

private static int CAPACITY_SIZE = 1000;
private static int LIMIT_TIME = 1000;
private static final int CAPACITY_SIZE = 1000;
private static final int LIMIT_TIME = 1000;
private static Cache<String, RateLimiter> cache = CacheBuilder.newBuilder()
.initialCapacity(CAPACITY_SIZE).expireAfterAccess(1, TimeUnit.MINUTES)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public static String signWithhmacSHA1Encrypt(String encryptText, String encryptK
}
}

private static String GROUP_KEY = "group";
private static String TENANT_KEY = "tenant";
private static final String GROUP_KEY = "group";
private static final String TENANT_KEY = "tenant";
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Boolean isMultiInstance() {
}

private static Boolean isMultiInstance = false;
private static String TRUE = "true";
private static final String TRUE = "true";
private static final Logger LOGGER = LogUtils.logger(JVMUtil.class);

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class BeatReactor {

private ScheduledExecutorService executorService;

private volatile long clientBeatInterval = 5 * 1000;

private NamingProxy serverProxy;

public final Map<String, BeatInfo> dom2Beat = new ConcurrentHashMap<String, BeatInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public ServiceInfo processServiceJSON(String json) {
return serviceInfo;
}

private ServiceInfo getSerivceInfo0(String serviceName, String clusters) {
private ServiceInfo getServiceInfo0(String serviceName, String clusters) {

String key = ServiceInfo.getKey(serviceName, clusters);

Expand All @@ -218,7 +218,7 @@ public ServiceInfo getServiceInfo(final String serviceName, final String cluster
return failoverReactor.getService(key);
}

ServiceInfo serviceObj = getSerivceInfo0(serviceName, clusters);
ServiceInfo serviceObj = getServiceInfo0(serviceName, clusters);

if (null == serviceObj) {
serviceObj = new ServiceInfo(serviceName, clusters);
Expand Down Expand Up @@ -264,7 +264,7 @@ public void scheduleUpdateIfAbsent(String serviceName, String clusters) {
}

public void updateServiceNow(String serviceName, String clusters) {
ServiceInfo oldService = getSerivceInfo0(serviceName, clusters);
ServiceInfo oldService = getServiceInfo0(serviceName, clusters);
try {

String result = serverProxy.queryList(serviceName, clusters, pushReceiver.getUDPPort(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void refresh() {
}

double doublePrecisionDelta = 0.0001;
if (index != 0 && !(Math.abs(weights[index - 1] - 1) < doublePrecisionDelta)) {
if (index == 0 || (Math.abs(weights[index - 1] - 1) < doublePrecisionDelta)) {
throw new IllegalStateException(
"Cumulative Weight caculate wrong , the sum of probabilities does not equals 1.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,22 @@ public static byte[] tryDecompress(byte[] raw) throws Exception {
if (!isGzipStream(raw)) {
return raw;
}
GZIPInputStream gis = null;
ByteArrayOutputStream out = null;

GZIPInputStream gis
= new GZIPInputStream(new ByteArrayInputStream(raw));
ByteArrayOutputStream out
= new ByteArrayOutputStream();

IoUtils.copy(gis, out);

return out.toByteArray();
try {
gis = new GZIPInputStream(new ByteArrayInputStream(raw));
out = new ByteArrayOutputStream();
IoUtils.copy(gis, out);
return out.toByteArray();
} finally {
if (out != null) {
out.close();
}
if (gis != null) {
gis.close();
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RandomUtils {
/**
* An instance of {@link JvmRandom}.
*/
public static final Random JVM_RANDOM = new JvmRandom();
private static final Random JVM_RANDOM = new JvmRandom();

// should be possible for JVM_RANDOM?
// public static void nextBytes(byte[]) {
Expand Down
32 changes: 12 additions & 20 deletions client/src/main/java/com/alibaba/nacos/client/utils/IPUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,23 @@
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
public class IPUtil {

public static boolean isIPV4(String addr) {
if (null == addr) {
return false;
}
String rexp = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
private static final String IPV4_PATTERN = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
private static final String IPV6_PATTERN = "^([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$";

Pattern pat = Pattern.compile(rexp);

Matcher mat = pat.matcher(addr);

boolean ipAddress = mat.find();
return ipAddress;
public static boolean isIPV4(String addr) {
return isMatch(addr, IPV4_PATTERN);
}

public static boolean isIPV6(String addr) {
if (null == addr) {
return isMatch(addr, IPV6_PATTERN);
}

private static boolean isMatch(String data, String pattern) {
if (StringUtils.isBlank(data)) {
return false;
}
String rexp = "^([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$";

Pattern pat = Pattern.compile(rexp);

Matcher mat = pat.matcher(addr);

boolean ipAddress = mat.find();
return ipAddress;
Pattern pat = Pattern.compile(pattern);
Matcher mat = pat.matcher(data);
return mat.find();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
public class JSONUtils {

static ObjectMapper mapper = new ObjectMapper();
private static ObjectMapper mapper = new ObjectMapper();

static {
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class StringUtils {

public static final int INDEX_NOT_FOUND = -1;
private static final int INDEX_NOT_FOUND = -1;

public static final String EMPTY = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CmdbProvider implements CmdbReader, CmdbWriter {

private CmdbService cmdbService;

ServiceLoader<CmdbService> serviceLoader = ServiceLoader.load(CmdbService.class);
private ServiceLoader<CmdbService> serviceLoader = ServiceLoader.load(CmdbService.class);

private Map<String, Map<String, Entity>> entityMap = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class UtilsAndCommons {

public static final String NACOS_SERVER_VERSION = "/v1";
private static final String NACOS_SERVER_VERSION = "/v1";

public static final String NACOS_CMDB_CONTEXT = NACOS_SERVER_VERSION + "/cmdb";

Expand Down

0 comments on commit 34025a5

Please sign in to comment.