Cleanup boolean literals 68/94368/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Jan 2021 16:12:41 +0000 (17:12 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Jan 2021 16:12:41 +0000 (17:12 +0100)
A number of places are using explicit literals where not needed,
as pointed out by sonar. Fix these sites.

Change-Id: I0ad6a690c66fb3b53bb4cd5c549399b665e7bc98
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/AttributeUtil.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/ExtendedCommunityUtil.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractEROWithSubobjectsParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/AbstractXROWithSubobjectsParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/EROExplicitExclusionRouteSubobjectParser.java
pcep/server/server-provider/src/main/java/org/opendaylight/bgpcep/pcep/server/provider/MessagesUtil.java

index f919a0d17bd78335bb382deb540b3d80c29dc6b3..ae7907937d8fd94bc1de610a1193ed15aa642331 100644 (file)
@@ -10,15 +10,13 @@ package org.opendaylight.protocol.bgp.parser.spi;
 import io.netty.buffer.ByteBuf;
 
 public final class AttributeUtil {
-
-    private static final int MAX_ATTR_LENGTH_FOR_SINGLE_BYTE = 255;
-
     public static final int OPTIONAL = 128;
     public static final int TRANSITIVE = 64;
     public static final int PARTIAL = 32;
     private static final int EXTENDED = 16;
 
     private AttributeUtil() {
+        // Hidden on purpose
     }
 
     /**
@@ -32,7 +30,7 @@ public final class AttributeUtil {
      */
     public static void formatAttribute(final int flags, final int type, final ByteBuf value, final ByteBuf buffer) {
         final int length = value.writerIndex();
-        final boolean extended = length > MAX_ATTR_LENGTH_FOR_SINGLE_BYTE ? true : false;
+        final boolean extended = length > 255;
         buffer.writeByte(extended ? flags | EXTENDED : flags);
         buffer.writeByte(type);
         if (extended) {
index 3386cb365f715a703d38f9ef3c1caf41b0c8d5a0..d0299eb247a9e1d464ba863092c836b0985bf106 100644 (file)
@@ -14,6 +14,7 @@ public final class ExtendedCommunityUtil {
     private static final byte NON_TRANS = 0x40;
 
     private ExtendedCommunityUtil() {
+        // Hidden on pupose
     }
 
     /**
@@ -25,7 +26,7 @@ public final class ExtendedCommunityUtil {
      *         type.
      */
     public static int setTransitivity(final int type, final boolean isTransitive) {
-        return isTransitive ? type : ExtendedCommunityUtil.toNonTransitiveType(type);
+        return isTransitive ? type : type | NON_TRANS;
     }
 
     /**
@@ -35,10 +36,6 @@ public final class ExtendedCommunityUtil {
      * @return True if input type is transitive, false if the type is non-transitive
      */
     public static boolean isTransitive(final int type) {
-        return (type & NON_TRANS) == 0 ? true : false;
-    }
-
-    private static int toNonTransitiveType(final int type) {
-        return type | NON_TRANS;
+        return (type & NON_TRANS) == 0;
     }
 }
index a5f48fa1f9482f983a7cfb2fcc87825bbe8583d9..19676c1da64557589efc562925f11dcbba869d93 100644 (file)
@@ -617,7 +617,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
 
     private static boolean isLongLivedStaleTable(final Optional<NormalizedNode<?, ?>> optTable) {
         final Optional<NormalizedNode<?, ?>> optAttributes = NormalizedNodes.findNode(optTable, ATTRIBUTES_NID);
-        return optAttributes.isPresent() ? isLongLivedStale(extractContainer(optAttributes)) : false;
+        return optAttributes.isPresent() && isLongLivedStale(extractContainer(optAttributes));
     }
 
     private static ContainerNode effectiveAttributes(final Optional<? extends NormalizedNode<?, ?>> optUptodate) {
index e3fdcdae8c316a6ce59ea3fc0c548dd0fd1788a7..93067c9beb0f090fcc6790abf2ef6db059faff1a 100644 (file)
@@ -24,7 +24,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public abstract class AbstractEROWithSubobjectsParser extends CommonObjectParser implements ObjectSerializer {
-
     private static final Logger LOG = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
 
     private static final int HEADER_LENGTH = 2;
@@ -42,11 +41,8 @@ public abstract class AbstractEROWithSubobjectsParser extends CommonObjectParser
         Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
         final List<Subobject> subs = new ArrayList<>();
         while (buffer.isReadable()) {
-            final boolean loose = ((buffer.getUnsignedByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0)
-                    ? true
-                    : false;
-            final int type = (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES)
-                    & ~(1 << Values.FIRST_BIT_OFFSET);
+            final boolean loose = (buffer.getUnsignedByte(buffer.readerIndex()) & 1 << Values.FIRST_BIT_OFFSET) != 0;
+            final int type = buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES & ~(1 << Values.FIRST_BIT_OFFSET);
             final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
             if (length > buffer.readableBytes()) {
                 throw new PCEPDeserializerException(
index bd23431ddebf0751cb7b86f3a2f47fc2355191cc..6294070cfd7149416482055d654142d8224dbc22 100644 (file)
@@ -44,8 +44,8 @@ public abstract class AbstractXROWithSubobjectsParser extends CommonObjectParser
         final List<Subobject> subs = new ArrayList<>();
         while (buffer.isReadable()) {
             final boolean mandatory =
-                ((buffer.getUnsignedByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
-            final int type = UnsignedBytes.checkedCast((buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES)
+                (buffer.getUnsignedByte(buffer.readerIndex()) & 1 << Values.FIRST_BIT_OFFSET) != 0;
+            final int type = UnsignedBytes.checkedCast(buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES
                 & ~(1 << Values.FIRST_BIT_OFFSET));
             final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
             if (length > buffer.readableBytes()) {
index 039f12d9d0503a6d5dc65cedb8a6709510cd07bc..87b9fc26ddbda0bd3a1dc5f7f646650514a3999a 100644 (file)
@@ -70,7 +70,7 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
             .route.object.xro.Subobject> xros = new ArrayList<>();
         while (buffer.isReadable()) {
             final boolean mandatory =
-                    (buffer.getByte(buffer.readerIndex()) & 1 << Values.FIRST_BIT_OFFSET) != 0 ? true : false;
+                    (buffer.getByte(buffer.readerIndex()) & 1 << Values.FIRST_BIT_OFFSET) != 0;
             final int type =
                     buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES & ~(1 << Values.FIRST_BIT_OFFSET);
             final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
index 7ecfdf7c7f5b55fc39dfb0fecd339e35defa48dd..66272b8ebd1a78da893f866e5f9a05d64837dcfc 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.bgpcep.pcep.server.provider;
 
 import com.google.common.collect.Lists;
@@ -84,14 +83,14 @@ public final class MessagesUtil {
     public static final int PATH_DELAY = 12;
 
     private MessagesUtil() {
-        throw new UnsupportedOperationException();
+        // Hidden on purpose
     }
 
-    public static Ero getEro(List<PathDescription> pathDescriptions) {
+    public static Ero getEro(final List<PathDescription> pathDescriptions) {
         /* Prepare ERO */
-        final EroBuilder eroBuilder = new EroBuilder();
-        eroBuilder.setIgnore(false);
-        eroBuilder.setProcessingRule(true);
+        final EroBuilder eroBuilder = new EroBuilder()
+            .setIgnore(false)
+            .setProcessingRule(true);
         final List<Subobject> eroSubs = new ArrayList<>();
 
         /* Fulfill ERO sublist */
@@ -121,7 +120,7 @@ public final class MessagesUtil {
             } else {
                 /* Prepare SubObject for Segment Routing */
                 SrEroType srEro = null;
-                if ((path.getLocalIpv4() != null) && (path.getRemoteIpv4() != null)) {
+                if (path.getLocalIpv4() != null && path.getRemoteIpv4() != null) {
                     srEro = new SrEroTypeBuilder()
                             .setNaiType(NaiType.Ipv4Adjacency)
                             .setSid(path.getSid())
@@ -135,7 +134,7 @@ public final class MessagesUtil {
                                     .build())
                             .build();
                 }
-                if ((path.getLocalIpv6() != null) && (path.getRemoteIpv6() != null)) {
+                if (path.getLocalIpv6() != null && path.getRemoteIpv6() != null) {
                     srEro = new SrEroTypeBuilder()
                             .setNaiType(NaiType.Ipv6Adjacency)
                             .setSid(path.getSid())
@@ -165,30 +164,30 @@ public final class MessagesUtil {
         return eroBuilder.build();
     }
 
-    private static PathsBuilder buildPath(ConstrainedPath cpath) {
+    private static PathsBuilder buildPath(final ConstrainedPath cpath) {
         final PathsBuilder pathBuilder = new PathsBuilder();
 
         /* Get ERO from Path Description */
         pathBuilder.setEro(getEro(cpath.getPathDescription()));
 
         /* Fulfill Computed Metrics if available */
-        final ArrayList<Metrics> metrics = new ArrayList<Metrics>();
+        final ArrayList<Metrics> metrics = new ArrayList<>();
         if (cpath.getMetric() != null) {
             final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true)
                     .setMetricType(Uint8.valueOf(IGP_METRIC)).setValue(new Float32(
-                            ByteBuffer.allocate(4).putFloat(Float.valueOf(cpath.getMetric().floatValue())).array()));
+                            ByteBuffer.allocate(4).putFloat(cpath.getMetric().floatValue()).array()));
             metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
         }
         if (cpath.getTeMetric() != null) {
             final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true)
                     .setMetricType(Uint8.valueOf(TE_METRIC)).setValue(new Float32(
-                            ByteBuffer.allocate(4).putFloat(Float.valueOf(cpath.getTeMetric().floatValue())).array()));
+                            ByteBuffer.allocate(4).putFloat(cpath.getTeMetric().floatValue()).array()));
             metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
         }
         if (cpath.getDelay() != null) {
             final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true)
                     .setMetricType(Uint8.valueOf(PATH_DELAY)).setValue(new Float32(ByteBuffer.allocate(4)
-                            .putFloat(Float.valueOf(cpath.getDelay().getValue().floatValue())).array()));
+                            .putFloat(cpath.getDelay().getValue().floatValue()).array()));
             metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
         }
         if (!metrics.isEmpty()) {
@@ -198,7 +197,7 @@ public final class MessagesUtil {
         if (cpath.getBandwidth() != null) {
             final BandwidthBuilder bwBuilder = new BandwidthBuilder();
             bwBuilder.setBandwidth(new Bandwidth(new Float32(ByteBuffer.allocate(4)
-                    .putFloat(Float.valueOf(cpath.getBandwidth().getValue().floatValue())).array())));
+                    .putFloat(cpath.getBandwidth().getValue().floatValue()).array())));
             pathBuilder.setBandwidth(bwBuilder.build());
             if (cpath.getClassType() != null) {
                 pathBuilder.setClassType(new ClassTypeBuilder().setClassType(
@@ -210,10 +209,10 @@ public final class MessagesUtil {
         return pathBuilder;
     }
 
-    public static Pcrep createPcRepMessage(Rp rp, P2p p2p, ConstrainedPath cpath) {
+    public static Pcrep createPcRepMessage(final Rp rp, final P2p p2p, final ConstrainedPath cpath) {
 
         /* Prepare Path Object with ERO and Object from the Request */
-        final ArrayList<Paths> paths = new ArrayList<Paths>();
+        final ArrayList<Paths> paths = new ArrayList<>();
         PathsBuilder pathBuilder = buildPath(cpath);
 
         if (p2p.getLspa() != null) {
@@ -238,11 +237,11 @@ public final class MessagesUtil {
         return new PcrepBuilder().setPcrepMessage(msgBuilder.build()).build();
     }
 
-    public static Pcrep createNoPathMessage(Rp rp, byte reason) {
+    public static Pcrep createNoPathMessage(final Rp rp, final byte reason) {
 
         /* Prepare NoPath Object */
         final Flags flags = new Flags(false, false, false, false, false, false,
-                (reason == UNKNOWN_DESTINATION) ? true : false, (reason == UNKNOWN_SOURCE) ? true : false);
+                reason == UNKNOWN_DESTINATION, reason == UNKNOWN_SOURCE);
         final NoPathVectorBuilder npvBuilder = new NoPathVectorBuilder().setFlags(flags);
         final TlvsBuilder tlvsBuilder = new TlvsBuilder().setNoPathVector(npvBuilder.build());
         final NoPathBuilder npBuilder = new NoPathBuilder()