View Javadoc

1   package org.sourceforge.vlibrary.util;
2   
3   import java.util.Map;
4   
5   /**
6    * Static utility methods.
7    *
8    * @version $Revision$ $Date$
9    */
10  
11  public class Utils {
12  
13      /**
14       * Case-insensitive get on string key.  First tries s, then s.toLowerCase,
15       * then s.toUpperCase (in that order), returning the first non-null value
16       * that if finds or null if none succeed.
17       *
18       * @param m Map
19       * @param s String key
20       * @return entry corresponding to key, ucase(key), or lowercase(key)
21       */
22      public static Object getIgnoreCase(Map<String, Object> m, String s) {
23          Object result = m.get(s);
24          if (result != null) {
25              return result;
26          }
27          String t = s.toLowerCase();
28          result = m.get(t);
29          if (result != null) {
30              return result;
31          }
32          t = s.toUpperCase();
33          result = m.get(t);
34          if (result != null) {
35              return result;
36          }
37          return null;
38      }
39  }