package jalview.util; import java.util.Map; public class MapUtils { /** * Return the value of the first key that exists in the map and has a non-null * value */ public static V getFirst(Map map, K... keys) { return getFirst(false, map, keys); } /** * Return the value of the first key that exists in the map - optionally * limiting to only returning non-null values for first extant key encountered */ public static V getFirst(boolean nonNull, Map 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; } /** * peeks in to the map and returns true if one of a bunch of keys is contained * in it * * @param * @param map * @param keys * @return */ public static boolean containsAKey(Map map, K... keys) { for (K key : keys) { if (map.containsKey(key)) return true; } return false; } }