format code

This commit is contained in:
caoyixiong 2019-06-26 12:07:33 +08:00
parent 781273faa6
commit 34025a5132
14 changed files with 42 additions and 45 deletions

View File

@ -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 = "";

View File

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

View File

@ -100,6 +100,6 @@ public class SpasAdapter {
}
}
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";
}

View File

@ -36,7 +36,7 @@ public class JVMUtil {
}
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 {

View File

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

View File

@ -195,7 +195,7 @@ public class HostReactor {
return serviceInfo;
}
private ServiceInfo getSerivceInfo0(String serviceName, String clusters) {
private ServiceInfo getServiceInfo0(String serviceName, String clusters) {
String key = ServiceInfo.getKey(serviceName, clusters);
@ -218,7 +218,7 @@ public class HostReactor {
return failoverReactor.getService(key);
}
ServiceInfo serviceObj = getSerivceInfo0(serviceName, clusters);
ServiceInfo serviceObj = getServiceInfo0(serviceName, clusters);
if (null == serviceObj) {
serviceObj = new ServiceInfo(serviceName, clusters);
@ -264,7 +264,7 @@ public class HostReactor {
}
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);

View File

@ -138,7 +138,7 @@ public class Chooser<K, T> {
}
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.");
}

View File

@ -178,15 +178,22 @@ public class IoUtils {
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();
}
}
}
}

View File

@ -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[]) {

View File

@ -26,31 +26,23 @@ import java.util.regex.Pattern;
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
public class IPUtil {
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}$";
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?)$";
Pattern pat = Pattern.compile(rexp);
Matcher mat = pat.matcher(addr);
boolean ipAddress = mat.find();
return ipAddress;
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();
}
}

View File

@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@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);

View File

@ -28,7 +28,7 @@ import java.util.Locale;
*/
public class StringUtils {
public static final int INDEX_NOT_FOUND = -1;
private static final int INDEX_NOT_FOUND = -1;
public static final String EMPTY = "";

View File

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

View File

@ -25,7 +25,7 @@ import java.util.concurrent.ThreadFactory;
*/
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";