1 19 20 package edu.umd.cs.findbugs; 21 22 25 public class SystemProperties { 26 27 public final static boolean ASSERTIONS_ENABLED; 28 static { 29 boolean tmp = false; 30 assert(tmp = true); 31 ASSERTIONS_ENABLED = tmp; 32 } 33 38 public static boolean getBoolean(String arg0) { 39 try { 40 return Boolean.getBoolean(arg0); 41 } catch (Exception e) { 42 return false; 43 } 44 } 45 46 public static boolean getBoolean(String name, boolean defaultValue) { 47 boolean result = defaultValue; 48 try { 49 String value = System.getProperty(name); 50 if (value == null) return defaultValue; 51 result = toBoolean(value); 52 } catch (IllegalArgumentException e) { 53 } catch (NullPointerException e) { 54 } 55 return result; 56 } 57 private static boolean toBoolean(String name) { 58 return ((name != null) && name.equalsIgnoreCase("true")); 59 } 60 61 62 67 public static Integer getInteger(String arg0, int arg1) { 68 try { 69 return Integer.getInteger(arg0, arg1); 70 } catch (Exception e) { 71 return arg1; 72 } 73 } 74 75 79 public static String getProperty(String arg0) { 80 try { 81 return System.getProperty(arg0); 82 } catch (Exception e) { 83 return null; 84 } 85 } 86 87 92 public static String getProperty(String arg0, String arg1) { 93 try { 94 return System.getProperty(arg0, arg1); 95 } catch (Exception e) { 96 return arg1; 97 } 98 } 99 100 } 101 | Popular Tags |