[motify info] Resolve code conflicts

This commit is contained in:
water.lyl 2018-09-13 17:23:04 +08:00
parent de1d976432
commit 89c5c8fd76
3 changed files with 37 additions and 24 deletions

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -17,11 +17,8 @@ package com.alibaba.nacos.api.naming.pojo;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.alibaba.nacos.client.naming.utils.StringUtils;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -30,7 +27,7 @@ import java.util.List;
public class ServiceInfo {
@JSONField(serialize = false)
private String jsonFromServer = StringUtils.EMPTY;
private String jsonFromServer = EMPTY;
public static final String SPLITER = "@@";
@JSONField(name = "dom")
@ -45,9 +42,9 @@ public class ServiceInfo {
private long lastRefTime = 0L;
private String checksum = StringUtils.EMPTY;
private String checksum = "";
private String env = StringUtils.EMPTY;
private String env = "";
private volatile boolean allIPs = false;
@ -75,20 +72,20 @@ public class ServiceInfo {
this.name = keys[serviceNameIndex];
this.clusters = keys[clusterIndex];
this.env = keys[envIndex];
if (StringUtils.equals(keys[allIpFlagIndex], UtilAndComs.ALL_IPS)) {
if (strEquals(keys[allIpFlagIndex], ALL_IPS)) {
this.setAllIPs(true);
}
} else if (keys.length >= allIpFlagIndex) {
this.name = keys[serviceNameIndex];
this.clusters = keys[clusterIndex];
if (StringUtils.equals(keys[envIndex], UtilAndComs.ALL_IPS)) {
if (strEquals(keys[envIndex], ALL_IPS)) {
this.setAllIPs(true);
} else {
this.env = keys[envIndex];
}
} else if (keys.length >= envIndex) {
this.name = keys[serviceNameIndex];
if (StringUtils.equals(keys[clusterIndex], UtilAndComs.ALL_IPS)) {
if (strEquals(keys[clusterIndex], ALL_IPS)) {
this.setAllIPs(true);
} else {
this.clusters = keys[clusterIndex];
@ -99,7 +96,7 @@ public class ServiceInfo {
}
public ServiceInfo(String name, String clusters) {
this(name, clusters, StringUtils.EMPTY);
this(name, clusters, EMPTY);
}
public ServiceInfo(String name, String clusters, String env) {
@ -166,7 +163,7 @@ public class ServiceInfo {
return true;
}
if (CollectionUtils.isEmpty(hosts)) {
if (isEmpty(hosts)) {
return false;
}
@ -181,7 +178,7 @@ public class ServiceInfo {
}
}
if (CollectionUtils.isEmpty(validHosts)) {
if (isEmpty(validHosts)) {
return false;
}
@ -210,25 +207,25 @@ public class ServiceInfo {
@JSONField(serialize = false)
public static String getKey(String name, String clusters, String unit, boolean isAllIPs) {
if (StringUtils.isEmpty(unit)) {
unit = StringUtils.EMPTY;
if (isEmpty(unit)) {
unit = EMPTY;
}
if (!StringUtils.isEmpty(clusters) && !StringUtils.isEmpty(unit)) {
return isAllIPs ? name + SPLITER + clusters + SPLITER + unit + SPLITER + UtilAndComs.ALL_IPS
if (!isEmpty(clusters) && !isEmpty(unit)) {
return isAllIPs ? name + SPLITER + clusters + SPLITER + unit + SPLITER + ALL_IPS
: name + SPLITER + clusters + SPLITER + unit;
}
if (!StringUtils.isEmpty(clusters)) {
return isAllIPs ? name + SPLITER + clusters + SPLITER + UtilAndComs.ALL_IPS : name + SPLITER + clusters;
if (!isEmpty(clusters)) {
return isAllIPs ? name + SPLITER + clusters + SPLITER + ALL_IPS : name + SPLITER + clusters;
}
if (!StringUtils.isEmpty(unit)) {
return isAllIPs ? name + SPLITER + StringUtils.EMPTY + SPLITER + unit + SPLITER + UtilAndComs.ALL_IPS :
name + SPLITER + StringUtils.EMPTY + SPLITER + unit;
if (!isEmpty(unit)) {
return isAllIPs ? name + SPLITER + EMPTY + SPLITER + unit + SPLITER + ALL_IPS :
name + SPLITER + EMPTY + SPLITER + unit;
}
return isAllIPs ? name + SPLITER + UtilAndComs.ALL_IPS : name;
return isAllIPs ? name + SPLITER + ALL_IPS : name;
}
@Override
@ -243,4 +240,20 @@ public class ServiceInfo {
public void setChecksum(String checksum) {
this.checksum = checksum;
}
private static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
private static boolean strEquals(String str1, String str2) {
return str1 == null ? str2 == null : str1.equals(str2);
}
private static boolean isEmpty(Collection coll) {
return (coll == null || coll.isEmpty());
}
private static final String EMPTY = "";
private static final String ALL_IPS = "000--00-ALL_IPS--00--000";
}