Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / util / MatchUtil.java
index 2f629fdf876a8c8e306f50629e8eba016d85215b..ce4f5b7d93c52cd07503b080a203ff3d753b58c0 100644 (file)
@@ -5,17 +5,16 @@
  * 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.openflowplugin.impl.util;
 
 import com.google.common.collect.ImmutableMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.function.Function;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import java.util.stream.Collectors;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionResolvers;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
@@ -57,67 +56,69 @@ public final class MatchUtil {
             })
             .put(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow
                     .Match.class, (match) -> {
-                final MatchBuilder matchBuilder = new MatchBuilder(match);
+                    final MatchBuilder matchBuilder = new MatchBuilder(match);
 
-                resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
-                        .addAugmentation(GeneralAugMatchNotifUpdateFlowStats.class,
-                                new GeneralAugMatchNodesNodeTableFlowBuilder()
-                                        .setExtensionList(extensionLists)
-                                        .build()));
+                    resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
+                            .addAugmentation(GeneralAugMatchNotifUpdateFlowStats.class,
+                                    new GeneralAugMatchNodesNodeTableFlowBuilder()
+                                            .setExtensionList(extensionLists)
+                                            .build()));
 
-                return matchBuilder.build();
-            })
+                    return matchBuilder.build();
+                })
             .put(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed
                     .Match.class, (match) -> {
-                final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed
-                        .MatchBuilder matchBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types
-                        .rev131026.flow.mod.removed.MatchBuilder(match);
-
-                resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
-                        .addAugmentation(GeneralAugMatchNotifSwitchFlowRemoved.class,
-                                new GeneralAugMatchNotifSwitchFlowRemovedBuilder()
-                                        .setExtensionList(extensionLists)
-                                        .build()));
-
-                return matchBuilder.build();
-            })
+                    final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed
+                            .MatchBuilder matchBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types
+                            .rev131026.flow.mod.removed.MatchBuilder(match);
+
+                    resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
+                            .addAugmentation(GeneralAugMatchNotifSwitchFlowRemoved.class,
+                                    new GeneralAugMatchNotifSwitchFlowRemovedBuilder()
+                                            .setExtensionList(extensionLists)
+                                            .build()));
+
+                    return matchBuilder.build();
+                })
             .put(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received
                     .Match.class, (match) -> {
-                final org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received
-                        .MatchBuilder matchBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
-                        .rev130709.packet.received.MatchBuilder(match);
-
-                resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
-                        .addAugmentation(GeneralAugMatchNotifPacketIn.class,
-                                new GeneralAugMatchNotifPacketInBuilder()
-                                        .setExtensionList(extensionLists)
-                                        .build()));
-
-                return matchBuilder.build();
-            })
+                    final org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received
+                            .MatchBuilder matchBuilder =
+                            new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
+                            .rev130709.packet.received.MatchBuilder(match);
+
+                    resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
+                            .addAugmentation(GeneralAugMatchNotifPacketIn.class,
+                                    new GeneralAugMatchNotifPacketInBuilder()
+                                            .setExtensionList(extensionLists)
+                                            .build()));
+
+                    return matchBuilder.build();
+                })
             .put(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.in.message
                     .Match.class, (match) -> {
-                final org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.in.message
-                        .MatchBuilder matchBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
-                        .rev130709.packet.in.message.MatchBuilder(match);
-
-                resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
-                        .addAugmentation(GeneralAugMatchPacketInMessage.class,
-                                new GeneralAugMatchPacketInMessageBuilder()
-                                        .setExtensionList(extensionLists)
-                                        .build()));
-
-                return matchBuilder.build();
-            })
+                    final org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.in.message
+                            .MatchBuilder matchBuilder =
+                            new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
+                            .rev130709.packet.in.message.MatchBuilder(match);
+
+                    resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
+                            .addAugmentation(GeneralAugMatchPacketInMessage.class,
+                                    new GeneralAugMatchPacketInMessageBuilder()
+                                            .setExtensionList(extensionLists)
+                                            .build()));
+
+                    return matchBuilder.build();
+                })
             .build();
 
-    private MatchUtil(){
+    private MatchUtil() {
         throw new IllegalStateException("This class should not be instantiated.");
     }
 
 
     public static MatchV10Builder createEmptyV10Match() {
-        Short zeroShort = Short.valueOf("0");
+        Short zeroShort = 0;
         Integer zeroInteger = 0;
         MatchV10Builder matchV10Builder = new MatchV10Builder();
         matchV10Builder.setDlDst(ZERO_MAC_ADDRESS);
@@ -134,35 +135,33 @@ public final class MatchUtil {
         matchV10Builder.setNwTos(zeroShort);
         matchV10Builder.setTpDst(zeroInteger);
         matchV10Builder.setTpSrc(zeroInteger);
-        FlowWildcardsV10 flowWildcardsV10 = new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true);
+        FlowWildcardsV10 flowWildcardsV10 =
+                new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true);
         matchV10Builder.setWildcards(flowWildcardsV10);
         return matchV10Builder;
     }
 
     @Nullable
     public static <T extends Match> T transformMatch(@Nullable final Match match,
-                                                     @Nonnull final Class<T> implementedInterface) {
-        if (Objects.isNull(match)) {
+                                                     @NonNull final Class<T> implementedInterface) {
+        if (match == null) {
             return null;
         }
 
-        if (implementedInterface.equals(match.getImplementedInterface())) {
+        if (implementedInterface.equals(match.implementedInterface())) {
             return implementedInterface.cast(match);
         }
 
         final Function<Match, Match> matchMatchFunction = TRANSFORMERS.get(implementedInterface);
-
-        if (Objects.isNull(matchMatchFunction)) {
-            return null;
-        }
-
-        return implementedInterface.cast(matchMatchFunction.apply(match));
+        return matchMatchFunction == null ? null : implementedInterface.cast(matchMatchFunction.apply(match));
     }
 
     private static Optional<List<ExtensionList>> resolveExtensions(final Match match) {
         return ExtensionResolvers
                 .getMatchExtensionResolver()
                 .getExtension(match)
-                .flatMap(matchExtension -> Optional.ofNullable(matchExtension.getExtensionList()));
+                .flatMap(matchExtension ->
+                        Optional.ofNullable(matchExtension.nonnullExtensionList().values()
+                        .stream().collect(Collectors.toList())));
     }
-}
\ No newline at end of file
+}