Bump mdsal to 5.0.2
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / md / util / OpenflowVersion.java
index 99d7cc8d0043b364fd21ec0cc82fcfd3535df593..ca315493f0a8ac2640843eda7159ced74bd82405 100644 (file)
@@ -8,6 +8,11 @@
 
 package org.opendaylight.openflowplugin.api.openflow.md.util;
 
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.util.Arrays;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
 /**
  * List of Openflow versions supported by the plugin.
  * Note: If you add a version here,
@@ -20,6 +25,8 @@ public enum OpenflowVersion {
     OF13((short)0x04),
     UNSUPPORTED((short)0x00);
 
+    private static final ImmutableMap<Uint8, OpenflowVersion> VERSIONS = Maps.uniqueIndex(Arrays.asList(values()),
+        ver -> Uint8.valueOf(ver.version));
 
     private short version;
 
@@ -27,6 +34,11 @@ public enum OpenflowVersion {
         this.version = version;
     }
 
+    public static OpenflowVersion get(final Uint8 version) {
+        final OpenflowVersion ver = VERSIONS.get(version);
+        return ver != null ? ver : UNSUPPORTED;
+    }
+
     public static OpenflowVersion get(final Short version) {
         for (final OpenflowVersion ofv : OpenflowVersion.values()) {
             if (ofv.version == version) {