1 28 29 package com.idaremedia.antx.parameters; 30 31 import com.idaremedia.antx.helpers.Strings; 32 import com.idaremedia.antx.helpers.Tk; 33 34 62 63 public final class FeedbackLevel extends EnumSkeleton 64 { 65 67 69 public static int VERBOSE_INDEX = 0; 70 public static int NORMAL_INDEX = VERBOSE_INDEX+1; 71 public static int QUIET_INDEX = NORMAL_INDEX+1; 72 public static int VERYQUIET_INDEX = QUIET_INDEX+1; 73 public static int NONE_INDEX = VERYQUIET_INDEX+1; 74 75 76 78 79 private static final String [] VALUES_= new String [] { 80 "verbose", "normal", "quiet", "veryquiet", "none" 81 }; 82 83 84 86 87 public static final FeedbackLevel VERBOSE= 88 new FeedbackLevel(VALUES_[VERBOSE_INDEX],VERBOSE_INDEX); 89 90 91 public static final FeedbackLevel NORMAL= 92 new FeedbackLevel(VALUES_[NORMAL_INDEX],NORMAL_INDEX); 93 94 95 public static final FeedbackLevel QUIET= 96 new FeedbackLevel(VALUES_[QUIET_INDEX],QUIET_INDEX); 97 98 99 public static final FeedbackLevel VERYQUIET= 100 new FeedbackLevel(VALUES_[VERYQUIET_INDEX],VERYQUIET_INDEX); 101 102 103 public static final FeedbackLevel NONE= 104 new FeedbackLevel(VALUES_[NONE_INDEX],NONE_INDEX); 105 106 107 108 111 public FeedbackLevel() 112 { 113 super(); 114 } 115 116 117 122 private FeedbackLevel(String v, int i) 123 { 124 super(v); 125 } 126 127 128 129 134 public static String [] copyOfDefaultValues(String [] fillin) 135 { 136 if (fillin==null) { 137 fillin = new String [VALUES_.length]; 138 } 139 System.arraycopy(VALUES_,0,fillin,0,VALUES_.length); 140 return fillin; 141 } 142 143 144 145 150 public String [] getValues() 151 { 152 return FeedbackLevel.copyOfDefaultValues(null); 153 }; 154 155 156 157 163 public static FeedbackLevel from(int i) 164 { 165 if (i==NORMAL.index) { return NORMAL; } 166 if (i==QUIET.index) { return QUIET; } 167 if (i==VERYQUIET.index) { return VERYQUIET; } 168 if (i==VERBOSE.index) { return VERBOSE; } 169 if (i==NONE.index) { return NONE; } 170 return null; 171 } 172 173 174 181 public static FeedbackLevel from(int i, FeedbackLevel dflt) 182 { 183 FeedbackLevel choice= from(i); 184 return (choice==null) ? dflt : choice; 185 } 186 187 188 193 public static FeedbackLevel from(String s) 194 { 195 if (s!=null && s.length()>1) { 196 s = Tk.lowercaseFrom(s); 197 if (Character.isDigit(s.charAt(0))) { 198 try { return from(Integer.parseInt(s)); } 199 catch(Exception nfx) {} 200 } else { 201 if (Strings.DEFAULT.equals(s)) { return NORMAL; } 202 if (NORMAL.value.equals(s)) { return NORMAL; } 203 if (QUIET.value.equals(s)) { return QUIET; } 204 if (VERYQUIET.value.equals(s)) { return VERYQUIET; } 205 if (VERBOSE.value.equals(s)) { return VERBOSE; } 206 if (NONE.equals(s)) { return NONE; } 207 if (Tk.string2NegBool(s)==Boolean.FALSE) { 208 return NONE; 209 } 210 } 211 } 212 return null; 213 } 214 215 216 223 public static FeedbackLevel from(String s, FeedbackLevel dflt) 224 { 225 FeedbackLevel choice= from(s); 226 return (choice==null) ? dflt : choice; 227 } 228 229 230 231 237 public static boolean isQuietish(FeedbackLevel fbl, boolean nullIsQuiet) 238 { 239 if (fbl==null) { 240 return nullIsQuiet; 241 } 242 return fbl.getIndex()>=QUIET_INDEX; 243 } 244 245 246 247 255 public static boolean isQuietish(FeedbackLevel fbl, boolean normalIsQuiet, 256 boolean nullIsQuiet) 257 { 258 if (fbl==null) { 259 return nullIsQuiet; 260 } 261 if (fbl.getIndex()>=QUIET_INDEX) { 262 return true; 263 } 264 return NORMAL_INDEX==fbl.getIndex() ? normalIsQuiet : false; 265 } 266 267 } 268 269 | Popular Tags |