Remove useless UnsupportedOperationExceptions
[bgpcep.git] / bgp / extensions / route-target / src / main / java / org / opendaylight / protocol / bgp / route / targetcontrain / spi / RouteTargetMembeshipUtil.java
index aba3f630ec7f1c327d03b2e8b1a31438acff5c33..1be88e0df4b7dff1c29358bcddbb8ea4251a259f 100644 (file)
@@ -5,11 +5,8 @@
  * 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.route.targetcontrain.spi;
 
-import java.util.Optional;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.RouteTargetConstrainChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.route.target.constrain.choice.RouteTargetConstrainAs4ExtendedCommunityCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.route.target.constrain.choice.RouteTargetConstrainDefaultCase;
@@ -20,25 +17,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 
 public final class RouteTargetMembeshipUtil {
     private RouteTargetMembeshipUtil() {
-        throw new UnsupportedOperationException();
+        // Hidden on purpose
     }
 
-    public static <R extends Route> Optional<RouteTarget> getRT(final R route) {
-        if (!(route instanceof RouteTargetConstrainRoute)) {
-            return Optional.empty();
-        }
-
-        final RouteTargetConstrainChoice rtc = ((RouteTargetConstrainRoute) route).getRouteTargetConstrainChoice();
-        RouteTarget rt;
+    public static RouteTarget getRT(final RouteTargetConstrainRoute route) {
+        final RouteTargetConstrainChoice rtc = route.getRouteTargetConstrainChoice();
         if (rtc instanceof RouteTargetConstrainDefaultCase) {
-            rt = ((RouteTargetConstrainDefaultCase) rtc).getRouteTargetConstrainDefaultRoute();
+            return ((RouteTargetConstrainDefaultCase) rtc).getRouteTargetConstrainDefaultRoute();
         } else if (rtc instanceof RouteTargetConstrainAs4ExtendedCommunityCase) {
-            rt = ((RouteTargetConstrainAs4ExtendedCommunityCase) rtc).getAs4RouteTargetExtendedCommunity();
+            return ((RouteTargetConstrainAs4ExtendedCommunityCase) rtc).getAs4RouteTargetExtendedCommunity();
         } else if (rtc instanceof RouteTargetConstrainIpv4RouteCase) {
-            rt = ((RouteTargetConstrainIpv4RouteCase) rtc).getRouteTargetIpv4();
+            return ((RouteTargetConstrainIpv4RouteCase) rtc).getRouteTargetIpv4();
         } else {
-            rt = ((RouteTargetConstrainRouteCase) rtc).getRouteTargetExtendedCommunity();
+            return ((RouteTargetConstrainRouteCase) rtc).getRouteTargetExtendedCommunity();
         }
-        return Optional.of(rt);
     }
 }