Optimize BgpAttributeConditionsUtil 92/83192/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 19 Jul 2019 17:28:08 +0000 (19:28 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 22 Jul 2019 09:36:04 +0000 (09:36 +0000)
We can very slightly optimize dispatch in these utilities by
returning statements. Also rename a confusingly-named local
variable.

Change-Id: Ia68705e82a4830b92111494e32a9ffcfed2943e8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 249cb9fc0261e5687020ab51014a45d45d67c50c)

bgp/openconfig-rp-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/registry/BgpAttributeConditionsUtil.java

index 42ba6b934e0199ce0f05636e0936ef18d9be3cc4..410ff3170e488fcdb90e40179723f96464834f53 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.protocol.bgp.openconfig.routing.policy.spi.registry;
 
 import java.util.List;
@@ -32,7 +31,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCase;
 
 /**
- * Bgp Attribute Conditions Util per check conditions matchs.
+ * Bgp Attribute Conditions Util per check conditions matches.
  *
  * @author Claudio D. Gasparini
  */
@@ -81,18 +80,11 @@ final class BgpAttributeConditionsUtil {
     }
 
     private static boolean matchMED(final MultiExitDisc multiExitDisc, final Long med) {
-        if (multiExitDisc == null || med == null) {
-            return true;
-        }
-
-        return multiExitDisc.getMed().equals(med);
+        return multiExitDisc == null || med == null || med.equals(multiExitDisc.getMed());
     }
 
     private static boolean matchOrigin(final Origin origin, final BgpOriginAttrType originEq) {
-        if (origin == null || originEq == null) {
-            return true;
-        }
-        return origin.getValue().getIntValue() == originEq.getIntValue();
+        return origin == null || originEq == null || origin.getValue().getIntValue() == originEq.getIntValue();
     }
 
     private static boolean matchAsPathLength(final AsPath asPath, final AsPathLength asPathLength) {
@@ -110,18 +102,17 @@ final class BgpAttributeConditionsUtil {
         }
 
         final Class<? extends AttributeComparison> comp = asPathLength.getOperator();
-        final long asPathLenght = asPathLength.getValue();
+        final long asLength = asPathLength.getValue();
         if (comp == AttributeEq.class) {
-            return total == asPathLenght;
+            return total == asLength;
         } else if (comp == AttributeGe.class) {
-            return total >= asPathLenght;
+            return total >= asLength;
         } else if (comp == AttributeLe.class) {
-            return total <= asPathLenght;
+            return total <= asLength;
         }
         return false;
     }
 
-
     private static boolean matchNextHopIn(final CNextHop nextHop, final List<IpAddress> nextHopIn) {
         if (nextHop == null || nextHopIn == null || nextHop instanceof EmptyNextHopCase) {
             return true;
@@ -137,9 +128,6 @@ final class BgpAttributeConditionsUtil {
     }
 
     private static boolean matchLocalPref(final LocalPref localPref, final Long localPrefEq) {
-        if (localPref == null || localPrefEq == null) {
-            return true;
-        }
-        return localPref.getPref().equals(localPrefEq);
+        return localPref == null || localPrefEq == null || localPrefEq.equals(localPref.getPref());
     }
 }