1 28 29 package com.idaremedia.antx.ownhelpers; 30 31 import com.idaremedia.antx.helpers.Strings; 32 import com.idaremedia.antx.helpers.Tk; 33 import com.idaremedia.antx.parameters.EnumSkeleton; 34 35 46 47 public class FeedbackSink extends EnumSkeleton 48 { 49 51 53 54 public static final int ALL_INDEX = 0; 56 public static final int NONE_INDEX = ALL_INDEX+1; 57 58 public static final int STDOUT_INDEX = NONE_INDEX+1; 59 60 public static final int STDERR_INDEX = STDOUT_INDEX+1; 61 62 public static final int STDIO_INDEX = STDERR_INDEX+1; 63 64 public static final int ANTLOG_INDEX = STDIO_INDEX+1; 65 66 public static final int EXTERNAL_INDEX = ANTLOG_INDEX+1; 67 68 69 protected static final int BASE_COUNT = EXTERNAL_INDEX+1; 70 71 72 74 75 private static final String [] VALUES_= new String [] 76 {"all", "none", "stdout","stderr","stdio", "antlog", "external"}; 77 78 79 81 82 public static final FeedbackSink ALL= 83 new FeedbackSink(VALUES_[ALL_INDEX],ALL_INDEX); 84 85 public static final FeedbackSink NONE= 86 new FeedbackSink(VALUES_[NONE_INDEX],NONE_INDEX); 87 88 89 public static final FeedbackSink STDOUT= 90 new FeedbackSink(VALUES_[STDOUT_INDEX],STDOUT_INDEX); 91 92 public static final FeedbackSink STDERR= 93 new FeedbackSink(VALUES_[STDERR_INDEX],STDERR_INDEX); 94 95 public static final FeedbackSink STDIO= 96 new FeedbackSink(VALUES_[STDIO_INDEX],STDIO_INDEX); 97 98 99 100 public static final FeedbackSink ANTLOG= 101 new FeedbackSink(VALUES_[ANTLOG_INDEX],ANTLOG_INDEX); 102 103 public static final FeedbackSink EXTERNAL= 104 new FeedbackSink(VALUES_[EXTERNAL_INDEX],EXTERNAL_INDEX); 105 106 107 110 public FeedbackSink() 111 { 112 super(); 113 } 114 115 116 121 protected FeedbackSink(String v, int i) 122 { 123 super(v); 124 } 125 126 127 128 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 149 public String [] getValues() 150 { 151 return FeedbackSink.copyOfDefaultValues(null); 152 } 153 154 155 156 161 public static FeedbackSink from(int i) 162 { 163 if (i==ANTLOG.index) { return ANTLOG; } 164 if (i==STDIO.index) { return STDIO; } 165 if (i==STDOUT.index) { return STDOUT; } 166 if (i==STDERR.index) { return STDERR; } 167 if (i==EXTERNAL.index) { return EXTERNAL; } 168 if (i==ALL.index) { return ALL; } 169 if (i==NONE.index) { return NONE; } 170 return null; 171 } 172 173 174 181 public static FeedbackSink from(int i, FeedbackSink dflt) 182 { 183 FeedbackSink choice= from(i); 184 return (choice==null) ? dflt : choice; 185 } 186 187 188 193 public static FeedbackSink 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 (STDIO.value.equals(s)) { return STDIO; } 202 if (STDERR.value.equals(s)) { return STDERR; } 203 if (STDOUT.value.equals(s)) { return STDOUT; } 204 if (ANTLOG.value.equals(s)) { return ANTLOG; } 205 if ("stdlog".equals(s)) { return ANTLOG; } 206 if (EXTERNAL.value.equals(s)) { return EXTERNAL; } 207 if (ALL.value.equals(s)) { return ALL; } 208 if (NONE.value.equals(s)) { return NONE; } 209 if (Strings.DEFAULT.equals(s)) { return STDIO; } 210 if ("both".equals(s)) { return STDIO; } 211 } 212 } 213 return null; 214 } 215 216 217 224 public static FeedbackSink from(String s, FeedbackSink dflt) 225 { 226 FeedbackSink choice= from(s); 227 return (choice==null) ? dflt : choice; 228 } 229 230 231 232 238 public static final boolean isSystem(FeedbackSink ss) 239 { 240 if (ss!=null) { 241 int i= ss.getIndex(); 242 if (i==FeedbackSink.STDIO_INDEX || 243 i==FeedbackSink.STDOUT_INDEX || i==FeedbackSink.STDERR_INDEX) { 244 return true; 245 } 246 } 247 return false; 248 } 249 250 251 257 public static boolean isKnown(FeedbackSink ss) 258 { 259 if (ss!=null) { 260 int i= ss.getIndex(); 261 if (i==FeedbackSink.STDIO_INDEX || i==FeedbackSink.ANTLOG_INDEX || 262 i==FeedbackSink.STDOUT_INDEX || i==FeedbackSink.STDERR_INDEX) { 263 return true; 264 } 265 } 266 return false; 267 } 268 269 270 271 277 public static boolean isGrouping(FeedbackSink ss) 278 { 279 if (ss!=null) { 280 int i= ss.getIndex(); 281 if (i==FeedbackSink.STDIO_INDEX || i==FeedbackSink.ANTLOG_INDEX) { 282 return true; 283 } 284 } 285 return false; 286 } 287 } 288 289 290 | Popular Tags |