Some code style and refactor (#4355)
* extract duplicated method * change while loop to if since once rs.next() return false, it will never return true for the following calls * simplify if() return true; return false pattern * fix compilation Signed-off-by: liqiang.clq <liqiang.clq@alibaba-inc.com>
This commit is contained in:
parent
7c6016b18f
commit
c761f30e3b
|
|
@ -65,10 +65,7 @@ public class ClassAnnotationMatch implements IndirectMatch {
|
|||
for (AnnotationDescription annotation : declaredAnnotations) {
|
||||
annotationList.remove(annotation.getAnnotationType().getActualName());
|
||||
}
|
||||
if (annotationList.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return annotationList.isEmpty();
|
||||
}
|
||||
|
||||
private ElementMatcher.Junction buildEachAnnotation(String annotationName) {
|
||||
|
|
|
|||
|
|
@ -75,11 +75,8 @@ public class HierarchyMatch implements IndirectMatch {
|
|||
matchHierarchyClass(typeDescription.getSuperClass(), parentTypes);
|
||||
}
|
||||
|
||||
if (parentTypes.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
return parentTypes.size() == 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void matchHierarchyClass(TypeDescription.Generic clazz, List<String> parentTypes) {
|
||||
|
|
|
|||
|
|
@ -91,10 +91,7 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI
|
|||
* registered then return false.
|
||||
*/
|
||||
private Boolean checkRegisterStatus(Invocation invocation) {
|
||||
if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return null != invocation.getOperationMeta() && null != invocation.getEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,10 +91,7 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI
|
|||
* registered then return false.
|
||||
*/
|
||||
private Boolean checkRegisterStatus(Invocation invocation) {
|
||||
if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return null != invocation.getOperationMeta() && null != invocation.getEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,10 +182,7 @@ public class EndpointRelationServerSideMetrics extends Metrics {
|
|||
if (componentId != metrics.componentId)
|
||||
return false;
|
||||
|
||||
if (getTimeBucket() != metrics.getTimeBucket())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return getTimeBucket() == metrics.getTimeBucket();
|
||||
}
|
||||
|
||||
public static class Builder implements StorageBuilder<EndpointRelationServerSideMetrics> {
|
||||
|
|
|
|||
|
|
@ -181,10 +181,7 @@ public class ServiceRelationClientSideMetrics extends Metrics {
|
|||
if (componentId != metrics.componentId)
|
||||
return false;
|
||||
|
||||
if (getTimeBucket() != metrics.getTimeBucket())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return getTimeBucket() == metrics.getTimeBucket();
|
||||
}
|
||||
|
||||
public static class Builder implements StorageBuilder<ServiceRelationClientSideMetrics> {
|
||||
|
|
|
|||
|
|
@ -181,10 +181,7 @@ public class ServiceRelationServerSideMetrics extends Metrics {
|
|||
if (componentId != metrics.componentId)
|
||||
return false;
|
||||
|
||||
if (getTimeBucket() != metrics.getTimeBucket())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return getTimeBucket() == metrics.getTimeBucket();
|
||||
}
|
||||
|
||||
public static class Builder implements StorageBuilder<ServiceRelationServerSideMetrics> {
|
||||
|
|
|
|||
|
|
@ -89,10 +89,7 @@ public class EndpointInventory extends RegisterSource {
|
|||
return false;
|
||||
if (!name.equals(source.getName()))
|
||||
return false;
|
||||
if (detectPoint != source.getDetectPoint())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return detectPoint == source.getDetectPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -87,10 +87,7 @@ public class NetworkAddressInventory extends RegisterSource {
|
|||
return false;
|
||||
|
||||
NetworkAddressInventory source = (NetworkAddressInventory) obj;
|
||||
if (!name.equals(source.getName()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return name.equals(source.getName());
|
||||
}
|
||||
|
||||
public NetworkAddressInventory getClone() {
|
||||
|
|
|
|||
|
|
@ -163,10 +163,7 @@ public class ServiceInstanceInventory extends RegisterSource {
|
|||
return false;
|
||||
if (isAddress != source.getIsAddress())
|
||||
return false;
|
||||
if (addressId != source.getAddressId())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return addressId == source.getAddressId();
|
||||
}
|
||||
|
||||
public ServiceInstanceInventory getClone() {
|
||||
|
|
|
|||
|
|
@ -168,10 +168,7 @@ public class ServiceInventory extends RegisterSource {
|
|||
return false;
|
||||
if (isAddress != source.getIsAddress())
|
||||
return false;
|
||||
if (addressId != source.getAddressId())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return addressId == source.getAddressId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -46,9 +46,7 @@ public class TraceSegmentSampler {
|
|||
if (idPartsList.size() == 3) {
|
||||
Long lastLong = idPartsList.get(2);
|
||||
long sampleValue = lastLong % 10000;
|
||||
if (sampleValue < sampleRate) {
|
||||
return true;
|
||||
}
|
||||
return sampleValue < sampleRate;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,13 @@ public class H2MetadataQueryDAO implements IMetadataQueryDAO {
|
|||
sql.append(" and ").append(ServiceInventory.IS_ADDRESS).append("=" + BooleanUtils.FALSE);
|
||||
sql.append(" and ").append(ServiceInventory.NODE_TYPE).append("=" + NodeType.Normal.value());
|
||||
|
||||
return getNum(sql, condition);
|
||||
}
|
||||
|
||||
private Integer getNum(StringBuilder sql, List<Object> condition) throws IOException {
|
||||
try (Connection connection = h2Client.getConnection()) {
|
||||
try (ResultSet resultSet = h2Client.executeQuery(connection, sql.toString(), condition.toArray(new Object[0]))) {
|
||||
while (resultSet.next()) {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt("num");
|
||||
}
|
||||
}
|
||||
|
|
@ -90,17 +94,7 @@ public class H2MetadataQueryDAO implements IMetadataQueryDAO {
|
|||
sql.append("select count(*) num from ").append(EndpointInventory.INDEX_NAME).append(" where ");
|
||||
sql.append(EndpointInventory.DETECT_POINT).append("=").append(DetectPoint.SERVER.ordinal());
|
||||
|
||||
try (Connection connection = h2Client.getConnection()) {
|
||||
try (ResultSet resultSet = h2Client.executeQuery(connection, sql.toString(), condition.toArray(new Object[0]))) {
|
||||
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getInt("num");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
return 0;
|
||||
return getNum(sql, condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -111,16 +105,7 @@ public class H2MetadataQueryDAO implements IMetadataQueryDAO {
|
|||
sql.append(ServiceInventory.NODE_TYPE).append("=?");
|
||||
condition.add(nodeTypeValue);
|
||||
|
||||
try (Connection connection = h2Client.getConnection()) {
|
||||
try (ResultSet resultSet = h2Client.executeQuery(connection, sql.toString(), condition.toArray(new Object[0]))) {
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getInt("num");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
return 0;
|
||||
return getNum(sql, condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue