Use DistinctNodeContainer.getChildByArg() 06/97606/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Sep 2021 10:00:00 +0000 (12:00 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Sep 2021 10:06:30 +0000 (12:06 +0200)
The check implied by Optional.get() differs only by the exception thrown
-- and VerifyException is more appropriate. By same token we can
side-step the Optional and use childByArg() instead.

Change-Id: I317577ef635c621be360297a2b5b376edbbbd2d4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AdjRibOutListener.java

index 6aff41df8fd4fe71bd1fd5154baa1c4574fa57c4..d033e4f13160b65f16cf9033565240078107d967 100644 (file)
@@ -195,13 +195,12 @@ final class AdjRibOutListener implements ClusteredDOMDataTreeChangeListener, Pre
     }
 
     private static Ipv4Prefix extractPrefix(final MapEntryNode ipv4Route) {
-        return new Ipv4Prefix((String) ipv4Route.findChildByArg(ROUTE_KEY_PREFIX_LEAF).get().body());
+        return new Ipv4Prefix((String) ipv4Route.getChildByArg(ROUTE_KEY_PREFIX_LEAF).body());
     }
 
     private static PathId extractPathId(final MapEntryNode ipv4Route) {
-        return ipv4Route.findChildByArg(ROUTE_KEY_PATHID_LEAF)
-            .map(dataContainerChild -> new PathId((Uint32) dataContainerChild.body()))
-            .orElse(null);
+        final var pathId = ipv4Route.childByArg(ROUTE_KEY_PATHID_LEAF);
+        return pathId == null ? null : new PathId((Uint32) pathId.body());
     }
 
     public void close() {