Merge branch 'features/JAL-3858_PAEsInProjects' into develop
[jalview.git] / src / jalview / util / MapUtils.java
diff --git a/src/jalview/util/MapUtils.java b/src/jalview/util/MapUtils.java
new file mode 100644 (file)
index 0000000..e0d9c0b
--- /dev/null
@@ -0,0 +1,43 @@
+package jalview.util;
+
+import java.util.Map;
+
+public class MapUtils
+{
+  /*
+   * Return the value of the first key that exists in the map
+   */
+  public static <K, V> V getFirst(Map<K, V> map, K... keys)
+  {
+    return getFirst(false, map, keys);
+  }
+
+  public static <K, V> V getFirst(boolean nonNull, Map<K, V> map, K... keys)
+  {
+    for (K key : keys)
+    {
+      if (map.containsKey(key))
+      {
+        if (!(nonNull && (map.get(key) == null)))
+        {
+          return map.get(key);
+        }
+        else if (!nonNull)
+        {
+          return map.get(key);
+        }
+      }
+    }
+    return null;
+  }
+
+  public static <K> boolean containsAKey(Map<K, ?> map, K... keys)
+  {
+    for (K key : keys)
+    {
+      if (map.containsKey(key))
+        return true;
+    }
+    return false;
+  }
+}