Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 16:01:40 GMT
  2. Package jalview.util

File MapUtils.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
20% of files have more coverage

Code metrics

8
12
3
1
77
36
8
0.67
4
3
2.67

Classes

Class Line # Actions
MapUtils 25 12 8
0.7391304473.9%
 

Contributing tests

This file is covered by 33 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.util;
22   
23    import java.util.Map;
24   
 
25    public class MapUtils
26    {
27    /**
28    * Return the value of the first key that exists in the map and has a non-null
29    * value
30    */
 
31  94 toggle public static <K, V> V getFirst(Map<K, V> map, K... keys)
32    {
33  94 return getFirst(false, map, keys);
34    }
35   
36    /**
37    * Return the value of the first key that exists in the map - optionally
38    * limiting to only returning non-null values for first extant key encountered
39    */
 
40  94 toggle public static <K, V> V getFirst(boolean nonNull, Map<K, V> map, K... keys)
41    {
42  94 for (K key : keys)
43    {
44  124 if (map.containsKey(key))
45    {
46  94 if (!(nonNull && (map.get(key) == null)))
47    {
48  94 return map.get(key);
49    }
50  0 else if (!nonNull)
51    {
52  0 return map.get(key);
53    }
54    }
55    }
56  0 return null;
57    }
58   
59    /**
60    * peeks in to the map and returns true if one of a bunch of keys is contained
61    * in it
62    *
63    * @param <K>
64    * @param map
65    * @param keys
66    * @return
67    */
 
68  49 toggle public static <K> boolean containsAKey(Map<K, ?> map, K... keys)
69    {
70  49 for (K key : keys)
71    {
72  66 if (map.containsKey(key))
73  47 return true;
74    }
75  2 return false;
76    }
77    }