Remove useless UnsupportedOperationExceptions
[bgpcep.git] / bgp / openconfig-rp-spi / src / main / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / spi / registry / BgpAttributeConditionsUtil.java
index 2d374e4ace1e62eeefbc2d4e8e27e79c6d7f06fb..e71a321b14797d864008b22cd0e64e046b04f062 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;
@@ -30,15 +29,16 @@ 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.EmptyNextHopCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCase;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 /**
- * Bgp Attribute Conditions Util per check conditions matchs.
+ * Bgp Attribute Conditions Util per check conditions matches.
  *
  * @author Claudio D. Gasparini
  */
 final class BgpAttributeConditionsUtil {
     private BgpAttributeConditionsUtil() {
-        throw new UnsupportedOperationException();
+        // Hidden on purpose
     }
 
     static boolean matchConditions(
@@ -59,19 +59,12 @@ final class BgpAttributeConditionsUtil {
         return afiSafiIn == null ? true : afiSafiIn.contains(afiSafi);
     }
 
-    private static boolean matchMED(final MultiExitDisc multiExitDisc, final Long med) {
-        if (multiExitDisc == null || med == null) {
-            return true;
-        }
-
-        return multiExitDisc.getMed().equals(med);
+    private static boolean matchMED(final MultiExitDisc multiExitDisc, final Uint32 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) {
@@ -89,18 +82,17 @@ final class BgpAttributeConditionsUtil {
         }
 
         final Class<? extends AttributeComparison> comp = asPathLength.getOperator();
-        final long asPathLenght = asPathLength.getValue();
+        final long asLength = asPathLength.getValue().toJava();
         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;
@@ -115,10 +107,7 @@ final class BgpAttributeConditionsUtil {
         return nextHopIn.contains(global);
     }
 
-    private static boolean matchLocalPref(final LocalPref localPref, final Long localPrefEq) {
-        if (localPref == null || localPrefEq == null) {
-            return true;
-        }
-        return localPref.getPref().equals(localPrefEq);
+    private static boolean matchLocalPref(final LocalPref localPref, final Uint32 localPrefEq) {
+        return localPref == null || localPrefEq == null || localPrefEq.equals(localPref.getPref());
     }
 }