Sonar fixes
Rule: Use isEmpty() to check whether the collection is empty or not.
Change-Id: Ib5ab56b2263623b297db56c5cac2c2ee80e12725
diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
index d766f0d..50d63aa 100644
--- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
@@ -171,7 +171,7 @@
if ((as4pathSet != null) && (as4pathSeq != null)) {
int iAsLenIndex = cb.writerIndex();
cb.writeByte(0);
- if (as4pathSeq.size() != 0) {
+ if (!as4pathSeq.isEmpty()) {
cb.writeByte(AsPath.ASPATH_SEQ_TYPE);
cb.writeByte(as4pathSeq.size());
diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
index f6442d9..db1eed6 100644
--- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
@@ -208,7 +208,7 @@
if (isaspathSet()) {
int iAsLenIndex = cb.writerIndex();
cb.writeByte(0);
- if (aspathSeq.size() != 0) {
+ if (!aspathSeq.isEmpty()) {
cb.writeByte(ASPATH_SEQ_TYPE);
cb.writeByte(aspathSeq.size());
diff --git a/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/Controller.java b/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/Controller.java
index 406d09c..ae9504b 100644
--- a/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/Controller.java
+++ b/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/Controller.java
@@ -127,7 +127,7 @@
configPacket[1] = numberOfInterface;
//First time configuration
if (processes == null) {
- if (isisProcesses.size() > 0) {
+ if (!isisProcesses.isEmpty()) {
processes = isisProcesses;
connectPeer();
}
@@ -337,7 +337,7 @@
}
interfaceList.add(isisInterface);
}
- if (interfaceList.size() > 0) {
+ if (!interfaceList.isEmpty()) {
IsisProcess process = new DefaultIsisProcess();
process.setProcessId(jsonNode.path(IsisConstants.PROCESSESID).asText());
process.setIsisInterfaceList(interfaceList);
diff --git a/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisMessageDecoder.java b/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisMessageDecoder.java
index b75bc3f..43d95d8 100644
--- a/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisMessageDecoder.java
+++ b/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisMessageDecoder.java
@@ -73,7 +73,7 @@
isisMessageList.add(message);
}
}
- return (isisMessageList.size() > 0) ? isisMessageList : null;
+ return (!isisMessageList.isEmpty()) ? isisMessageList : null;
}
/**
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/NeighborForExtendedIs.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/NeighborForExtendedIs.java
index f5cd03b..5c3bb2e 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/NeighborForExtendedIs.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/tlv/NeighborForExtendedIs.java
@@ -134,7 +134,7 @@
List<Byte> byteList = new ArrayList<>();
byteList.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborId()));
byteList.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.metric())));
- if (this.teSubTlv.size() > 0) {
+ if (!this.teSubTlv.isEmpty()) {
for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.teSubTlv) {
byteList.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv));
}
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
index 80bd083..a385376 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
@@ -423,7 +423,7 @@
adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.DOWN.value());
adjacencyStateTlv.setLocalCircuitId(Integer.parseInt(isisInterface.circuitId()));
Set<MacAddress> neighbors = isisInterface.neighbors();
- if (neighbors.size() > 0) {
+ if (!neighbors.isEmpty()) {
IsisNeighbor neighbor = isisInterface.lookup(neighbors.iterator().next());
adjacencyStateTlv.setAdjacencyType((byte) neighbor.interfaceState().value());
adjacencyStateTlv.setNeighborSystemId(neighbor.neighborSystemId());
@@ -509,7 +509,7 @@
areaAddressTlv.addAddress(isisInterface.areaAddress());
l1L2HelloPdu.addTlv(areaAddressTlv);
Set<MacAddress> neighbors = isisInterface.neighbors();
- if (neighbors.size() > 0) {
+ if (!neighbors.isEmpty()) {
List<MacAddress> neighborMacs = new ArrayList<>();
for (MacAddress neighbor : neighbors) {
IsisNeighbor isisNeighbor = isisInterface.lookup(neighbor);
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfControllerImpl.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfControllerImpl.java
index 83462ee..01f52dc 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfControllerImpl.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfControllerImpl.java
@@ -115,10 +115,10 @@
try {
List<OspfProcess> ospfProcesses = OspfConfigUtil.processes(processesNode);
//if there is interface details then update configuration
- if (ospfProcesses.size() > 0 &&
- ospfProcesses.get(0).areas() != null && ospfProcesses.get(0).areas().size() > 0 &&
+ if (!ospfProcesses.isEmpty() &&
+ ospfProcesses.get(0).areas() != null && !ospfProcesses.get(0).areas().isEmpty() &&
ospfProcesses.get(0).areas().get(0) != null &&
- ospfProcesses.get(0).areas().get(0).ospfInterfaceList().size() > 0) {
+ !ospfProcesses.get(0).areas().get(0).ospfInterfaceList().isEmpty()) {
ctrl.updateConfig(ospfProcesses);
}
} catch (Exception e) {
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java
index 1d6ae23..e459afa 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java
@@ -66,6 +66,6 @@
ospfMessageList.add(message);
}
}
- return (ospfMessageList.size() > 0) ? ospfMessageList : null;
+ return (!ospfMessageList.isEmpty()) ? ospfMessageList : null;
}
}
\ No newline at end of file
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
index efaae8a..d5fed14 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
@@ -356,7 +356,7 @@
OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data();
@SuppressWarnings("unchecked")
Set<Uuid> ports = setPorts.set();
- if (ports == null || ports.size() == 0) {
+ if (ports == null || ports.isEmpty()) {
log.warn("The port uuid is null");
return null;
}
@@ -677,9 +677,9 @@
mirrorBuilder.externalIds(mirror.externalIds());
mirror = mirrorBuilder.build();
- if (mirror.monitorDstPorts().size() == 0 &&
- mirror.monitorSrcPorts().size() == 0 &&
- mirror.monitorVlans().size() == 0) {
+ if (mirror.monitorDstPorts().isEmpty() &&
+ mirror.monitorSrcPorts().isEmpty() &&
+ mirror.monitorVlans().isEmpty()) {
log.warn("Invalid monitoring data");
return false;
}
@@ -1332,7 +1332,7 @@
OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
@SuppressWarnings("unchecked")
Set<String> datapathIds = datapathIdSet.set();
- if (datapathIds == null || datapathIds.size() == 0) {
+ if (datapathIds == null || datapathIds.isEmpty()) {
return null;
}
String datapathId = (String) datapathIds.toArray()[0];
@@ -1347,7 +1347,7 @@
OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data();
@SuppressWarnings("unchecked")
Set<Integer> ofPorts = ofPortSet.set();
- if (ofPorts == null || ofPorts.size() <= 0) {
+ if (ofPorts == null || ofPorts.isEmpty()) {
log.debug("The ofport is null in {}", intf.getName());
return -1;
}
diff --git a/protocols/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java b/protocols/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java
index 04199e2..8258a74 100644
--- a/protocols/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java
+++ b/protocols/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/OvsdbControllerImpl.java
@@ -342,7 +342,7 @@
OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data();
@SuppressWarnings("unchecked")
Set<Integer> ofPorts = ofPortSet.set();
- while (ofPorts == null || ofPorts.size() <= 0) {
+ while (ofPorts == null || ofPorts.isEmpty()) {
log.debug("The ofport is null in {}", intf.getName());
return -1;
}
@@ -374,7 +374,7 @@
OvsdbSet dpidSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
@SuppressWarnings("unchecked")
Set<String> dpids = dpidSet.set();
- if (dpids == null || dpids.size() == 0) {
+ if (dpids == null || dpids.isEmpty()) {
return 0;
}
return stringToLong((String) dpids.toArray()[0]);
diff --git a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/BasicPceccHandler.java b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/BasicPceccHandler.java
index 90b8ea0..9d65a16 100644
--- a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/BasicPceccHandler.java
+++ b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/BasicPceccHandler.java
@@ -153,7 +153,7 @@
checkNotNull(pceStore, PCE_STORE_NULL);
List<Link> linkList = tunnel.path().links();
- if ((linkList != null) && (linkList.size() > 0)) {
+ if ((linkList != null) && (!linkList.isEmpty())) {
// Sequence through reverse order to push local labels into devices
// Generation of labels from egress to ingress
for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) {
@@ -161,7 +161,7 @@
DeviceId dstDeviceId = link.dst().deviceId();
DeviceId srcDeviceId = link.src().deviceId();
labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum);
- if ((labelRscList != null) && (labelRscList.size() > 0)) {
+ if ((labelRscList != null) && (!labelRscList.isEmpty())) {
// Link label value is taken from destination device local pool.
// [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes.
// Link label value is used as OUT and IN for both ends
@@ -228,7 +228,7 @@
boolean srcDeviceUpdated = false;
List<LspLocalLabelInfo> lspLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
- if ((lspLabelInfoList != null) && (lspLabelInfoList.size() > 0)) {
+ if ((lspLabelInfoList != null) && (!lspLabelInfoList.isEmpty())) {
for (int i = 0; i < lspLabelInfoList.size(); ++i) {
LspLocalLabelInfo lspLocalLabelInfo =
lspLabelInfoList.get(i);
@@ -299,7 +299,7 @@
Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create();
List<LspLocalLabelInfo> lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
- if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) {
+ if ((lspLocalLabelInfoList != null) && (!lspLocalLabelInfoList.isEmpty())) {
for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) {
LspLocalLabelInfo lspLocalLabelInfo = iterator.next();
DeviceId deviceId = lspLocalLabelInfo.deviceId();
diff --git a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PceccSrTeBeHandler.java b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PceccSrTeBeHandler.java
index 88e3b14..c6dad5a 100644
--- a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PceccSrTeBeHandler.java
+++ b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PceccSrTeBeHandler.java
@@ -191,7 +191,7 @@
// The specificDeviceId is the new device and is not there in the pce store.
// So, first generate its label and configure label and its lsr-id to it.
Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum);
- if (result.size() > 0) {
+ if (!result.isEmpty()) {
// Only one element (label-id) to retrieve
Iterator<LabelResource> iterator = result.iterator();
DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next();
@@ -338,7 +338,7 @@
// Allocate adjacency label to a link from label manager.
// Take label from source device pool to allocate.
labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum);
- if (labelList.size() <= 0) {
+ if (labelList.isEmpty()) {
log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString());
return false;
}
@@ -427,7 +427,7 @@
// Label stack is linked list to make labels in order.
List<LabelResourceId> labelStack = new LinkedList<>();
List<Link> linkList = path.links();
- if ((linkList != null) && (linkList.size() > 0)) {
+ if ((linkList != null) && (!linkList.isEmpty())) {
// Path: [x] ---- [y] ---- [z]
// For other than last link, add only source[x] device label.
// For the last link, add both source[y] and destination[z] device labels.