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 56 57 public final class ExecutionMode extends EnumSkeleton 58 { 59 60 public static final int LOCAL_INDEX = 0; 61 62 public static final int LOCALTHREAD_INDEX = LOCAL_INDEX+1; 63 64 public static final int ISOLATED_INDEX = LOCALTHREAD_INDEX+1; 65 66 public static final int EXTERNAL_INDEX = ISOLATED_INDEX+1; 67 68 69 70 public static final ExecutionMode LOCAL= 71 new ExecutionMode("local",LOCAL_INDEX); 72 73 74 public static final ExecutionMode LOCALTHREAD= 75 new ExecutionMode("localthread",LOCALTHREAD_INDEX); 76 77 78 public static final ExecutionMode ISOLATED= 79 new ExecutionMode("isolated",ISOLATED_INDEX); 80 81 82 public static final ExecutionMode EXTERNAL= 83 new ExecutionMode("external",EXTERNAL_INDEX); 84 85 86 89 public ExecutionMode() 90 { 91 super(); 92 } 93 94 95 100 private ExecutionMode(String v, int i) 101 { 102 super(v); 103 } 104 105 106 111 public String [] getValues() 112 { 113 return new String [] {"local", "localthread", 114 "isolated", "external"}; 115 }; 116 117 118 119 125 public static ExecutionMode from(int i) 126 { 127 if (i==LOCAL.index) { return LOCAL; } 128 if (i==ISOLATED.index) { return ISOLATED; } 129 if (i==EXTERNAL.index) { return EXTERNAL; } 130 if (i==LOCALTHREAD.index) { return LOCALTHREAD; } 131 return null; 132 } 133 134 135 142 public static ExecutionMode from(int i, ExecutionMode dflt) 143 { 144 ExecutionMode choice= from(i); 145 return (choice==null) ? dflt : choice; 146 } 147 148 149 154 public static ExecutionMode from(String s) 155 { 156 if (s!=null && s.length()>1) { 157 s = Tk.lowercaseFrom(s); 158 if (Character.isDigit(s.charAt(0))) { 159 try { return from(Integer.parseInt(s)); } 160 catch(Exception nfx) {} 161 } else { 162 if (LOCAL.value.equals(s)) { return LOCAL; } 163 if (ISOLATED.value.equals(s)) { return ISOLATED; } 164 if (EXTERNAL.value.equals(s)) { return EXTERNAL; } 165 if (Strings.DEFAULT.equals(s)) { return ISOLATED; } 166 if (LOCALTHREAD.value.equals(s)){ return LOCALTHREAD; } 167 } 168 } 169 return null; 170 } 171 172 173 180 public static ExecutionMode from(String s, ExecutionMode dflt) 181 { 182 ExecutionMode choice= from(s); 183 return (choice==null) ? dflt : choice; 184 } 185 } 186 187 188 | Popular Tags |