1 28 29 package com.idaremedia.antx.feedback; 30 31 import com.idaremedia.antx.NoiseLevel; 32 import com.idaremedia.antx.helpers.Tk; 33 import com.idaremedia.antx.parameters.EnumSkeleton; 34 35 45 46 public final class IndicatorZone extends EnumSkeleton 47 { 48 49 public static final int PROBLEMS_INDEX= 0; 50 51 public static final int STATUS_INDEX= PROBLEMS_INDEX+1; 52 53 public static final int DIAGNOSTICS_INDEX= STATUS_INDEX+1; 54 55 56 public static final IndicatorZone PROBLEMS = 57 new IndicatorZone("problems",PROBLEMS_INDEX); 58 59 public static final IndicatorZone STATUS = 60 new IndicatorZone("status",STATUS_INDEX); 61 62 public static final IndicatorZone DIAGNOSTICS = 63 new IndicatorZone("diagnostics",DIAGNOSTICS_INDEX); 64 65 66 69 public IndicatorZone() 70 { 71 super(); 72 } 73 74 75 79 private IndicatorZone(String v, int i) 80 { 81 super(v); 82 } 83 84 85 89 public String [] getValues() 90 { 91 return new String [] {"problems","status","diagnostics"}; 92 }; 93 94 95 96 101 public static IndicatorZone from(int i) 102 { 103 if (i==DIAGNOSTICS.index) { return DIAGNOSTICS; } 104 if (i==STATUS.index) { return STATUS; } 105 if (i==PROBLEMS.index) { return PROBLEMS; } 106 return null; 107 } 108 109 110 117 public static IndicatorZone from(int i, IndicatorZone dflt) 118 { 119 IndicatorZone iz= from(i); 120 return (iz==null) ? dflt : iz; 121 } 122 123 124 129 public static IndicatorZone from(NoiseLevel nl) 130 { 131 if (nl!=null) { 132 switch(nl.getIndex()) { 133 case NoiseLevel.FATAL_INDEX: 134 case NoiseLevel.ERROR_INDEX: 135 case NoiseLevel.WARNING_INDEX: { 136 return PROBLEMS; 137 } 138 case NoiseLevel.INFO_INDEX: { 139 return STATUS; 140 } 141 default: { 142 return DIAGNOSTICS; 143 } 144 } 145 } 146 return null; 147 } 148 149 150 157 public static IndicatorZone from(NoiseLevel nl, IndicatorZone dflt) 158 { 159 IndicatorZone iz= from(nl); 160 return (iz==null) ? dflt : iz; 161 } 162 163 164 170 public static IndicatorZone from(String s) 171 { 172 if (s!=null && s.length()>1) { 173 s = Tk.lowercaseFrom(s); 174 if (Character.isDigit(s.charAt(0))) { 175 try { return from(Integer.parseInt(s)); } 176 catch(Exception nfx) {} 177 } else { 178 if (DIAGNOSTICS.value.equals(s)) { return DIAGNOSTICS; } 179 if (STATUS.value.equals(s)) { return STATUS; } 180 if (PROBLEMS.value.equals(s)) { return PROBLEMS; } 181 182 NoiseLevel nl= NoiseLevel.from(s); 183 if (nl!=null) { 184 return from(nl); 185 } 186 } 187 } 188 return null; 189 } 190 191 192 199 public static IndicatorZone from(String s, IndicatorZone dflt) 200 { 201 IndicatorZone iz= from(s); 202 return (iz==null) ? dflt : iz; 203 } 204 } 205 206 207 | Popular Tags |