Merge branch 'features/r2_11_2_alphafold/JAL-629' into features/JAL-3858_PAEsInProjects
[jalview.git] / src / jalview / util / MapUtils.java
1 package jalview.util;
2
3 import java.util.Map;
4
5 public class MapUtils
6 {
7   /*
8    * Return the value of the first key that exists in the map
9    */
10   public static <K, V> V getFirst(Map<K, V> map, K... keys)
11   {
12     return getFirst(false, map, keys);
13   }
14
15   public static <K, V> V getFirst(boolean nonNull, Map<K, V> map, K... keys)
16   {
17     for (K key : keys)
18     {
19       if (map.containsKey(key))
20       {
21         if (!(nonNull && (map.get(key) == null)))
22         {
23           return map.get(key);
24         }
25         else if (!nonNull)
26         {
27           return map.get(key);
28         }
29       }
30     }
31     return null;
32   }
33
34   public static <K> boolean containsAKey(Map<K, ?> map, K... keys)
35   {
36     for (K key : keys)
37     {
38       if (map.containsKey(key))
39         return true;
40     }
41     return false;
42   }
43 }