1 28 29 package com.idaremedia.antx.parameters; 30 31 import com.idaremedia.antx.helpers.Tk; 32 33 55 56 public class CaseTransform extends EnumSkeleton 57 { 58 60 62 63 public static final int NONE_INDEX = 0; 64 65 public static final int LOWERCASE_INDEX = NONE_INDEX+1; 66 67 public static final int UPPERCASE_INDEX = LOWERCASE_INDEX+1; 68 69 public static final int INVERTCASE_INDEX = UPPERCASE_INDEX+1; 70 71 public static final int CAPITALIZE_INDEX = INVERTCASE_INDEX+1; 72 73 76 protected static final int BASE_COUNT = CAPITALIZE_INDEX+1; 77 78 79 81 82 private static final String [] VALUES_= new String [] 83 {"none", "lowercase", "uppercase","invertcase","capitalize"}; 84 85 86 88 89 public static final CaseTransform NONE= 90 new CaseTransform(VALUES_[NONE_INDEX],NONE_INDEX); 91 92 public static final CaseTransform LOWERCASE= 93 new CaseTransform(VALUES_[LOWERCASE_INDEX],LOWERCASE_INDEX); 94 95 public static final CaseTransform UPPERCASE= 96 new CaseTransform(VALUES_[UPPERCASE_INDEX],UPPERCASE_INDEX); 97 98 public static final CaseTransform INVERTCASE= 99 new CaseTransform(VALUES_[INVERTCASE_INDEX],INVERTCASE_INDEX); 100 101 public static final CaseTransform CAPITALIZE= 102 new CaseTransform(VALUES_[CAPITALIZE_INDEX],CAPITALIZE_INDEX); 103 104 105 108 public CaseTransform() 109 { 110 super(); 111 } 112 113 114 118 private CaseTransform(String v, int i) 119 { 120 super(v); 121 } 122 123 124 125 132 public static String [] copyOfDefaultValues(String [] fillin) 133 { 134 if (fillin==null) { 135 fillin = new String [VALUES_.length]; 136 } 137 System.arraycopy(VALUES_,0,fillin,0,VALUES_.length); 138 return fillin; 139 } 140 141 142 143 147 public String [] getValues() 148 { 149 return CaseTransform.copyOfDefaultValues(null); 150 }; 151 152 153 154 159 public static CaseTransform from(int i) 160 { 161 if (i==LOWERCASE.index) { return LOWERCASE; } 162 if (i==UPPERCASE.index) { return UPPERCASE; } 163 if (i==INVERTCASE.index) { return INVERTCASE; } 164 if (i==CAPITALIZE.index) { return CAPITALIZE; } 165 if (i==NONE.index) { return NONE; } 166 return null; 167 } 168 169 170 177 public static CaseTransform from(int i, CaseTransform dflt) 178 { 179 CaseTransform choice= from(i); 180 return (choice==null) ? dflt : choice; 181 } 182 183 184 189 public static CaseTransform from(String s) 190 { 191 if (s!=null && s.length()>1) { 192 s = Tk.lowercaseFrom(s); 193 if (Character.isDigit(s.charAt(0))) { 194 try { return from(Integer.parseInt(s)); } 195 catch(Exception nfx) {} 196 } else { 197 if ("default".equals(s)) { return NONE; } 198 if (NONE.value.equals(s)) { return NONE; } 199 if (LOWERCASE.value.equals(s)) { return LOWERCASE; } 200 if (UPPERCASE.value.equals(s)) { return UPPERCASE;} 201 if (INVERTCASE.value.equals(s)) { return INVERTCASE;} 202 if (CAPITALIZE.value.equals(s)) { return CAPITALIZE; } 203 } 204 } 205 return null; 206 } 207 208 209 216 public static CaseTransform from(String s, CaseTransform dflt) 217 { 218 CaseTransform choice= from(s); 219 return (choice==null) ? dflt : choice; 220 } 221 } 222 223 224 | Popular Tags |