From 2da2d410e5bd679b356b079972b441695c353833 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Thu, 2 Jun 2016 13:23:39 +0200 Subject: Intializers for the new vlan model Change-Id: I513f0b190e9d9e669663a9a216e7c72b1ebeb10d Signed-off-by: Marek Gradzki --- .../v3po/interfacesstate/InterfaceUtils.java | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java index e0bae975f..756b298bd 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java @@ -19,14 +19,15 @@ package io.fd.honeycomb.v3po.translate.v3po.interfacesstate; import static com.google.common.base.Preconditions.checkNotNull; import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceCustomizer.getCachedInterfaceDump; import static java.util.Objects.requireNonNull; -import static java.util.stream.Collectors.toList; import com.google.common.base.Preconditions; import io.fd.honeycomb.v3po.translate.ModificationCache; +import io.fd.honeycomb.v3po.translate.util.RWUtils; import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils; import java.math.BigInteger; import java.util.Map; import java.util.concurrent.CompletionStage; +import java.util.stream.Collector; import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd; @@ -59,6 +60,9 @@ public final class InterfaceUtils { private static final int PHYSICAL_ADDRESS_LENGTH = 6; + private static final Collector SINGLE_ITEM_COLLECTOR = + RWUtils.singleItemCollector(); + private InterfaceUtils() { throw new UnsupportedOperationException("This utility class cannot be instantiated"); } @@ -147,11 +151,11 @@ public final class InterfaceUtils { /** * Queries VPP for interface description given interface key. * - * @param futureJvpp VPP Java Future API - * @param name interface name - * @param index VPP index of the interface - * @param ctx per-tx scope context containing cached dump with all the interfaces. If the cache is not - * available or outdated, another dump will be performed. + * @param futureJvpp VPP Java Future API + * @param name interface name + * @param index VPP index of the interface + * @param ctx per-tx scope context containing cached dump with all the interfaces. If the cache is not + * available or outdated, another dump will be performed. * @return SwInterfaceDetails DTO or null if interface was not found * @throws IllegalArgumentException If interface cannot be found */ @@ -198,13 +202,8 @@ public final class InterfaceUtils { } // SwInterfaceDump's name filter does prefix match, so we need additional filtering: - final SwInterfaceDetails iface = ifaces.swInterfaceDetails.stream().filter(d -> d.swIfIndex == index).collect( - Collectors.collectingAndThen(toList(), l -> { - if (l.size() == 1) { - return l.get(0); - } - throw new RuntimeException(); - })); + final SwInterfaceDetails iface = + ifaces.swInterfaceDetails.stream().filter(d -> d.swIfIndex == index).collect(SINGLE_ITEM_COLLECTOR); allInterfaces.put(index, iface); // update the cache return iface; } -- cgit 1.2.3-korg