Remove check for empty lists, where not needed. 69/15369/1
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 16 Feb 2015 16:07:04 +0000 (17:07 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Mon, 16 Feb 2015 16:08:58 +0000 (17:08 +0100)
- fixed communities tests

Change-Id: I232bb411f56b06fb2711b268587e3213039223a3
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
17 files changed:
bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSExtendedCommunitiesAttributeParserTest.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkAttributesParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/NodeAttributesParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/PrefixAttributesParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/CapabilityParameterParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00PCInitiateMessageParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07PCReportMessageParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07PCUpdateRequestMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPMonitoringRequestMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractEROWithSubobjectsParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrEroUtil.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java

index 4005f931476208c1c822c16f42090e7b91aa76be..04a8681bdbc98443dbe28828958cb3a54038cddf 100644 (file)
@@ -90,10 +90,10 @@ public class FSExtendedCommunitiesAttributeParserTest {
 
         final ByteBuf serializedBuffer = Unpooled.buffer();
         parser.serializeAttribute(pa.build(), serializedBuffer);
-        assertArrayEquals(new byte[]{ (byte)192, 16, 8, (byte)128, 6, 0, 72, 0, 1, 2, 3,
-            (byte)192, 16, 8, (byte)128, 7, 0, 0, 0, 0, 0, 3,
-            (byte)192, 16, 8, (byte)128, 8, 0, 35, 4, 2, 8, 7,
-            (byte)192, 16, 8, (byte)128, 9, 0, 0, 0, 0, 0, 63 }, ByteArray.readAllBytes(serializedBuffer));
+        assertArrayEquals(new byte[]{ (byte)192, 16, 32, (byte)128, 6, 0, 72, 0, 1, 2, 3,
+            (byte)128, 7, 0, 0, 0, 0, 0, 3,
+            (byte)128, 8, 0, 35, 4, 2, 8, 7,
+            (byte)128, 9, 0, 0, 0, 0, 0, 63 }, ByteArray.readAllBytes(serializedBuffer));
 
         try {
             parser.parseAttribute(Unpooled.copiedBuffer(new byte[] { 11, 11, 21, 45, 5, 4, 3, 1 }), pa);
index ee9d727557b8a1dd17abd855cde8a1c168628d07..d79f860bf494627a3901cca8d94b6fbe9ffb29bf 100644 (file)
@@ -195,7 +195,7 @@ final class LinkAttributesParser {
         }
         // this sub-TLV contains eight 32-bit IEEE floating point numbers
         final List<UnreservedBandwidth> ubList = linkAttributes.getUnreservedBandwidth();
-        if (ubList != null && !ubList.isEmpty()) {
+        if (ubList != null) {
             final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
             for (final UnreservedBandwidth unreservedBandwidth : ubList) {
                 unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
@@ -214,7 +214,7 @@ final class LinkAttributesParser {
             TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator);
         }
         final List<SrlgId> srlgList = linkAttributes.getSharedRiskLinkGroups();
-        if (srlgList != null && !srlgList.isEmpty()) {
+        if (srlgList != null) {
             final ByteBuf sharedRLGBuf = Unpooled.buffer();
             for (final SrlgId srlgId : srlgList) {
                 sharedRLGBuf.writeInt(srlgId.getValue().intValue());
index e0f57288c791d85729289acab571e89d0634c569..b0420d17f766ea859d4a8a5dd7235d7334bdeb95 100644 (file)
@@ -139,7 +139,7 @@ final class NodeAttributesParser {
         LOG.trace("Started serializing Node Attributes");
         final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
         final List<TopologyIdentifier> topList = nodeAttributes.getTopologyIdentifier();
-        if (topList != null && !topList.isEmpty()) {
+        if (topList != null) {
             final ByteBuf mpIdBuf = Unpooled.buffer();
             for (final TopologyIdentifier topologyIdentifier : topList) {
                 mpIdBuf.writeShort(topologyIdentifier.getValue());
@@ -151,7 +151,7 @@ final class NodeAttributesParser {
             TlvUtil.writeTLV(DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator);
         }
         final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
-        if (isisList != null && !isisList.isEmpty()) {
+        if (isisList != null) {
             for (final IsisAreaIdentifier isisAreaIdentifier : isisList) {
                 TlvUtil.writeTLV(ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
             }
index 9560404ce5b84b7e2416f45cc0d29a61f1c6f0e0..f64bfccad58e0fc1f0fecd3402199db504ec301b 100644 (file)
@@ -140,7 +140,7 @@ final class PrefixAttributesParser {
             TlvUtil.writeTLV(ROUTE_TAG, routeTagsBuf, byteAggregator);
         }
         final List<ExtendedRouteTag> routeTagList = prefixAtrributes.getExtendedTags();
-        if (routeTagList != null && !routeTagList.isEmpty()) {
+        if (routeTagList != null) {
             final ByteBuf extendedBuf = Unpooled.buffer();
             for (final ExtendedRouteTag extendedRouteTag : routeTagList) {
                 extendedBuf.writeBytes(extendedRouteTag.getValue());
index c3da520c9fbd02bc2e545384dad6b82b8e7beade..6ef1d75d3353cd7f480fb59fab16f7ecd87249cd 100644 (file)
@@ -70,10 +70,10 @@ public final class CapabilityParameterParser implements ParameterParser, Paramet
 
     @Override
     public void serializeParameter(final BgpParameters parameter, final ByteBuf byteAggregator) {
-        if (parameter.getOptionalCapabilities() != null && !parameter.getOptionalCapabilities().isEmpty()) {
-            LOG.trace("Started serializing BGP Capability: {}", parameter.getOptionalCapabilities());
+        if (parameter.getOptionalCapabilities() != null) {
             final ByteBuf buffer = Unpooled.buffer();
             for (final OptionalCapabilities optionalCapa : parameter.getOptionalCapabilities()) {
+                LOG.trace("Started serializing BGP Capability: {}", optionalCapa);
                 serializeOptionalCapability(optionalCapa, buffer);
             }
             ParameterUtil.formatParameter(TYPE, buffer, byteAggregator);
index 880ab145f3c5eb7d9f3a1d4410c4221e79b05a90..9e2ee85b9a601a46bc4d8377e4ddb911957a4014 100644 (file)
@@ -84,7 +84,7 @@ public final class CommunitiesAttributeParser implements AttributeParser, Attrib
         Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
         final PathAttributes pathAttributes = (PathAttributes) attribute;
         final List<Communities> communities = pathAttributes.getCommunities();
-        if (communities == null || communities.isEmpty()) {
+        if (communities == null) {
             return;
         }
         final ByteBuf communitiesBuffer = Unpooled.buffer();
index 62e3c504662bca2abf47103b37059685edbd90d1..5e7f9e09383b7c668beeed03922f22b0fc7d4696 100644 (file)
@@ -189,15 +189,15 @@ public class ExtendedCommunitiesAttributeParser implements AttributeParser,Attri
     public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
         Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
         final List<ExtendedCommunities> communitiesList = ((PathAttributes) attribute).getExtendedCommunities();
-        if (communitiesList == null || communitiesList.isEmpty()) {
+        if (communitiesList == null) {
             return;
         }
+        final ByteBuf extendedCommunitiesBuffer = Unpooled.buffer();
         for (final ExtendedCommunities extendedCommunities : communitiesList) {
-            final ByteBuf extendedCommunitiesBuffer = Unpooled.buffer();
             serializeHeader(extendedCommunities, extendedCommunitiesBuffer);
             serializeExtendedCommunity(extendedCommunities, extendedCommunitiesBuffer);
-            AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, extendedCommunitiesBuffer, byteAggregator);
         }
+        AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, extendedCommunitiesBuffer, byteAggregator);
     }
 
     protected void serializeHeader(final ExtendedCommunities extendedCommunities, final ByteBuf extendedCommunitiesBuffer) {
index 98e5ac37d8b7c82bfb3d0b4c4dac4e186aae41ae..c7170efb7701c457e02ba0a8bec85fce05ee3c61 100644 (file)
@@ -213,13 +213,13 @@ public class ComplementaryTest {
 
         final ByteBuf serializedBuffer = Unpooled.buffer();
         parser.serializeAttribute(pa.build(), serializedBuffer);
-        assertArrayEquals(new byte[]{ (byte)192, 16, 8, 0, 5, 0, 54, 0, 0, 1, 76,
-            (byte)192, 16, 8, 40, 5, 0, 54, 0, 0, 1, 76,
-            (byte)192, 16, 8, 1, 2, 0, 35, 4, 2, 8, 7,
-            (byte)192, 16, 8, 0, 3, 0, 24, 4, 2, 8, 7,
-            (byte)192, 16, 8, 41, 6, 12, 51, 2, 5, 21, 45,
-            (byte)192, 16, 8, 3, 6, 21, 45, 5, 4, 3, 1,
-            (byte)192, 16, 8, 43, 6, 21, 45, 5, 4, 3, 1 }, ByteArray.readAllBytes(serializedBuffer));
+        assertArrayEquals(new byte[]{ (byte)192, 16, 56, 0, 5, 0, 54, 0, 0, 1, 76,
+            40, 5, 0, 54, 0, 0, 1, 76,
+            1, 2, 0, 35, 4, 2, 8, 7,
+            0, 3, 0, 24, 4, 2, 8, 7,
+            41, 6, 12, 51, 2, 5, 21, 45,
+            3, 6, 21, 45, 5, 4, 3, 1,
+            43, 6, 21, 45, 5, 4, 3, 1 }, ByteArray.readAllBytes(serializedBuffer));
 
         try {
             parser.parseAttribute(Unpooled.copiedBuffer(new byte[] { 11, 11, 21, 45, 5, 4, 3, 1 }), pa);
index a86ddf6483ede5e5447e065d3b2e31e695ca7378..42532ef4d581bf2bd819194176a5af5aef5f8446 100644 (file)
@@ -63,7 +63,7 @@ public class CInitiated00PCInitiateMessageParser extends AbstractMessageParser {
         serializeObject(req.getEro(), buffer);
         serializeObject(req.getLspa(), buffer);
         serializeObject(req.getBandwidth(), buffer);
-        if (req.getMetrics() != null && !req.getMetrics().isEmpty()) {
+        if (req.getMetrics() != null) {
             for (final Metrics m : req.getMetrics()) {
                 serializeObject(m.getMetric(), buffer);
             }
index 5c4a66eea6751c9a0562003a723bf61d808e35d5..63a90c82e18441c0ce1ead96f5174d84e288f77f 100644 (file)
@@ -72,7 +72,7 @@ public class Stateful07PCReportMessageParser extends AbstractMessageParser {
             serializeObject(p.getEro(), buffer);
             serializeObject(p.getLspa(), buffer);
             serializeObject(p.getBandwidth(), buffer);
-            if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
+            if (p.getMetrics() != null) {
                 for (final Metrics m : p.getMetrics()) {
                     serializeObject(m.getMetric(), buffer);
                 }
index 3eeb0c4f2ff2117544eca3976869c522674c87c2..a820afe2a341840f6d215d31c276dda0a475a8ba 100644 (file)
@@ -69,7 +69,7 @@ public class Stateful07PCUpdateRequestMessageParser extends AbstractMessageParse
             serializeObject(p.getEro(), buffer);
             serializeObject(p.getLspa(), buffer);
             serializeObject(p.getBandwidth(), buffer);
-            if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
+            if (p.getMetrics() != null) {
                 for (final Metrics m : p.getMetrics()) {
                     serializeObject(m.getMetric(), buffer);
                 }
index fa1b0071362e9dfe3b30544e9a4f8078f6447ba0..c7523353b2fd7fb5647f26a0b6e15f2d6d64d11c 100644 (file)
@@ -42,7 +42,7 @@ public class PCEPMonitoringRequestMessageParser extends PCEPRequestMessageParser
     }
 
     @Override
-    public void serializeMessage(Message message, ByteBuf out) {
+    public void serializeMessage(final Message message, final ByteBuf out) {
         Preconditions.checkArgument(message instanceof Pcmonreq, "Wrong instance of Message. Passed instance of %s. Need Pcmonreq.", message.getClass());
         final PcreqMessage msg = ((Pcmonreq) message).getPcreqMessage();
         if (msg.getMonitoringRequest() == null) {
@@ -53,14 +53,14 @@ public class PCEPMonitoringRequestMessageParser extends PCEPRequestMessageParser
         if (msg.getSvec() != null) {
             serializeSvec(msg, buffer);
         }
-        if (msg.getRequests() != null && !msg.getRequests().isEmpty()) {
+        if (msg.getRequests() != null) {
             serializeRequest(msg, buffer);
         }
         MessageUtil.formatMessage(TYPE, buffer, out);
     }
 
     @Override
-    protected Message validate(List<Object> objects, List<Message> errors) throws PCEPDeserializerException {
+    protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
         if (objects == null) {
             throw new IllegalArgumentException("Passed list can't be null.");
         }
index 4adccf1ef5d2dd207e92cfbba8032008025c282f..a9c70613590a1cb2c038b5aa4a3a2c6e4d5576a7 100644 (file)
@@ -170,7 +170,7 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
             mBuilder.setSvec(svecs);
         }
         final List<Requests> requests = getRequests(objects, errors);
-        if (requests != null && !requests.isEmpty()) {
+        if (requests != null) {
             mBuilder.setRequests(requests);
         } else {
             errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.<Rp>absent()));
index 694b025675797709b13913c02cb6e33ae0afbf6c..b3bd242201657d49c67c11ee2abd310678b66813 100644 (file)
@@ -59,7 +59,7 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
     }
 
     protected final void serializeSubobject(final List<Subobject> subobjects, final ByteBuf buffer) {
-        if(subobjects != null && !subobjects.isEmpty()) {
+        if(subobjects != null) {
             for (final Subobject subobject : subobjects) {
                 this.subobjReg.serializeSubobject(subobject, buffer);
             }
index 1f43df479f301b98c9651fc65d5239bcc4ee5360..391dda2d3f552d6a42dce33b5f4a306efb1fcf57 100644 (file)
@@ -23,7 +23,7 @@ public final class SrEroUtil {
     }
 
     protected static PCEPErrors validateSrEroSubobjects(final Ero ero) {
-        if (ero.getSubobject() != null && !ero.getSubobject().isEmpty()) {
+        if (ero.getSubobject() != null) {
             for (final Subobject subobject : ero.getSubobject()) {
                 if (!(subobject.getSubobjectType() instanceof SrEroSubobject)) {
                     return PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS;
index 423c344969ca1737e4cb915ba2f1709868fe076c..93d548cd056a47cdd76eaa097e532d0cd34c5289 100644 (file)
@@ -145,7 +145,7 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
     }
 
     protected final void serializeVendorInformationObjects(final List<VendorInformationObject> viObjects, final ByteBuf buffer) {
-        if (viObjects != null && !viObjects.isEmpty()) {
+        if (viObjects != null) {
             for (final VendorInformationObject viObject : viObjects) {
                 this.viRegistry.serializeVendorInformationObject(viObject, buffer);
             }
index 65c9321756d1d5408031b2cb960a446446fdddd6..816f1d59f2927ea1f07866e952008c494979cd62 100644 (file)
@@ -83,7 +83,7 @@ public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, O
     protected abstract void addVendorInformationTlvs(final T builder, final List<VendorInformationTlv> tlvs);
 
     protected final void serializeVendorInformationTlvs(final List<VendorInformationTlv> tlvs, final ByteBuf buffer) {
-        if (tlvs != null && !tlvs.isEmpty()) {
+        if (tlvs != null) {
             for (final VendorInformationTlv tlv : tlvs) {
                 LOG.trace("Serializing VENDOR-INFORMATION TLV {}", tlv);
                 this.viTlvReg.serializeVendorInformationTlv(tlv, buffer);