| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.phoenix.report; |
| 34 | | | |
| 35 | | | import java.io.Serializable; |
| 36 | | | import java.util.Arrays; |
| 37 | | | import java.util.Collections; |
| 38 | | | import java.util.HashMap; |
| 39 | | | import java.util.List; |
| 40 | | | import java.util.Map; |
| 41 | | | import edu.umd.cs.findbugs.Detector; |
| 42 | | | |
| 43 | | | |
| 44 | | | |
| 45 | | | |
| 46 | | | <p> |
| 47 | | | |
| 48 | | | |
| 49 | | | </p> |
| 50 | | | |
| 51 | | | <p> |
| 52 | | | {@link } |
| 53 | | | |
| 54 | | | </p> |
| 55 | | | |
| 56 | | | <p></p> |
| 57 | | | |
| 58 | | | <p> |
| 59 | | | <ol> |
| 60 | | | <li>{@link }</li> |
| 61 | | | <li>{@link }</li> |
| 62 | | | <li>{@link }</li> |
| 63 | | | <li>{@link }</li> |
| 64 | | | <li>{@link }</li> |
| 65 | | | <li>{@link }</li> |
| 66 | | | <li>{@link }</li> |
| 67 | | | </ol> |
| 68 | | | </p> |
| 69 | | | |
| 70 | | | @author |
| 71 | | | |
| 72 | | | public final class Severity |
| 73 | | | implements Serializable, Comparable |
| 74 | | | { |
| 75 | | | |
| 76 | | | |
| 77 | | | <code></code> |
| 78 | | | |
| 79 | | | public static final int PENALTY_SCALE = 10; |
| 80 | | | |
| 81 | | | |
| 82 | | | private static final long serialVersionUID = 2L; |
| 83 | | | |
| 84 | | | |
| 85 | 100 | | private static int sNextOrdinal = 0; |
| 86 | | | |
| 87 | | | |
| 88 | 100 | | private final int mOrdinal = sNextOrdinal++; |
| 89 | | | |
| 90 | | | |
| 91 | | | |
| 92 | | | |
| 93 | | | private final transient int mPenalty; |
| 94 | | | |
| 95 | | | |
| 96 | | | private final transient String mName; |
| 97 | | | |
| 98 | | | |
| 99 | 100 | | private static final Map FROM_STRING = new HashMap(); |
| 100 | | | |
| 101 | | | |
| 102 | | | |
| 103 | | | <p> |
| 104 | | | |
| 105 | | | </p> |
| 106 | | | <p></p> |
| 107 | | | |
| 108 | 100 | | public static final Severity FILTERED = new Severity("filtered", 0); |
| 109 | | | |
| 110 | | | |
| 111 | | | |
| 112 | | | |
| 113 | 100 | | public static final Severity OK = new Severity("ok", 0); |
| 114 | | | |
| 115 | | | |
| 116 | | | |
| 117 | | | |
| 118 | | | |
| 119 | | | <p></p> |
| 120 | | | |
| 121 | 100 | | public static final Severity INFO = new Severity("info", 0); |
| 122 | | | |
| 123 | | | |
| 124 | | | |
| 125 | | | <p> |
| 126 | | | |
| 127 | | | </p> |
| 128 | | | <p></p> |
| 129 | | | |
| 130 | 100 | | public static final Severity CODE_STYLE = new Severity("code-style", 5); |
| 131 | | | |
| 132 | | | |
| 133 | | | |
| 134 | | | <p> |
| 135 | | | </p> |
| 136 | | | <p></p> |
| 137 | | | |
| 138 | 100 | | public static final Severity COVERAGE = new Severity("coverage", 8); |
| 139 | | | |
| 140 | | | |
| 141 | | | |
| 142 | | | <p> |
| 143 | | | {@link } |
| 144 | | | {@link }</p> |
| 145 | | | <p></p> |
| 146 | | | |
| 147 | 100 | | public static final Severity DESIGN = new Severity("design", 30); |
| 148 | | | |
| 149 | | | |
| 150 | | | |
| 151 | | | <p></p> |
| 152 | | | |
| 153 | 100 | | public static final Severity WARNING = new Severity("warning", 50); |
| 154 | | | |
| 155 | | | |
| 156 | | | |
| 157 | | | <p> |
| 158 | | | </p> |
| 159 | | | <p></p> |
| 160 | | | |
| 161 | 100 | | public static final Severity CPD = new Severity("cpd", 100); |
| 162 | | | |
| 163 | | | |
| 164 | | | |
| 165 | | | <p> |
| 166 | | | |
| 167 | | | </p> |
| 168 | | | <p> |
| 169 | | | </p> |
| 170 | | | |
| 171 | 100 | | public static final Severity ERROR = new Severity("error", 100); |
| 172 | | | |
| 173 | | | |
| 174 | | | |
| 175 | | | {@link } |
| 176 | | | |
| 177 | 100 | | public static final Severity MAX_SEVERITY = ERROR; |
| 178 | | | |
| 179 | | | |
| 180 | 100 | | public static final int MAX_SEVERITY_INT = MAX_SEVERITY.toInt(); |
| 181 | | | |
| 182 | | | |
| 183 | 100 | | private static final Severity[] PRIVATE_VALUES = |
| 184 | | | { |
| 185 | | | Severity.FILTERED, |
| 186 | | | Severity.OK, |
| 187 | | | Severity.COVERAGE, |
| 188 | | | Severity.INFO, |
| 189 | | | Severity.CODE_STYLE, |
| 190 | | | Severity.DESIGN, |
| 191 | | | Severity.WARNING, |
| 192 | | | Severity.CPD, |
| 193 | | | Severity.ERROR |
| 194 | | | }; |
| 195 | | | |
| 196 | | | |
| 197 | 100 | | public static final List VALUES = |
| 198 | | | Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES)); |
| 199 | | | |
| 200 | | | |
| 201 | | | |
| 202 | | | private Severity (String name, int penalty) |
| 203 | 100 | | { |
| 204 | 100 | | mName = name; |
| 205 | 100 | | mPenalty = penalty; |
| 206 | 100 | | FROM_STRING.put(mName, this); |
| 207 | 100 | | } |
| 208 | | | |
| 209 | | | |
| 210 | | | |
| 211 | | | |
| 212 | | | @param |
| 213 | | | @return |
| 214 | | | @throws |
| 215 | | | |
| 216 | | | |
| 217 | | | public static Severity fromInt (int i) |
| 218 | | | throws IllegalArgumentException |
| 219 | | | { |
| 220 | | | try |
| 221 | | | { |
| 222 | 0 | | return PRIVATE_VALUES[i]; |
| 223 | | | } |
| 224 | 0 | | catch (ArrayIndexOutOfBoundsException e) |
| 225 | | | { |
| 226 | 0 | | final IllegalArgumentException ex = new IllegalArgumentException( |
| 227 | | | "Illegal int representation " + i + " of Severity"); |
| 228 | 0 | | ex.initCause(e); |
| 229 | 0 | | throw ex; |
| 230 | | | } |
| 231 | | | } |
| 232 | | | |
| 233 | | | |
| 234 | | | |
| 235 | | | |
| 236 | | | @param |
| 237 | | | |
| 238 | | | @return |
| 239 | | | @throws |
| 240 | | | |
| 241 | | | |
| 242 | | | public static Severity fromString (String str) |
| 243 | | | throws IllegalArgumentException |
| 244 | | | { |
| 245 | 0 | | final Severity result = (Severity) FROM_STRING.get(str); |
| 246 | 0 | | if (result == null) |
| 247 | | | { |
| 248 | 0 | | throw new IllegalArgumentException( |
| 249 | | | "Illegal string representation " + str + " of Severity"); |
| 250 | | | } |
| 251 | 0 | | return result; |
| 252 | | | } |
| 253 | | | |
| 254 | | | |
| 255 | | | |
| 256 | | | @return |
| 257 | | | |
| 258 | | | public int toInt () |
| 259 | | | { |
| 260 | 100 | | return mOrdinal; |
| 261 | | | } |
| 262 | | | |
| 263 | | | |
| 264 | | | |
| 265 | | | @return |
| 266 | | | |
| 267 | | | public String toString () |
| 268 | | | { |
| 269 | 0 | | return mName; |
| 270 | | | } |
| 271 | | | |
| 272 | | | |
| 273 | | | |
| 274 | | | |
| 275 | | | |
| 276 | | | @return |
| 277 | | | |
| 278 | | | public int getPenalty () |
| 279 | | | { |
| 280 | 0 | | return mPenalty; |
| 281 | | | } |
| 282 | | | |
| 283 | | | {@inheritDoc} |
| 284 | | | public int compareTo (Object o) |
| 285 | | | { |
| 286 | 0 | | return mOrdinal - ((Severity) o).mOrdinal; |
| 287 | | | } |
| 288 | | | |
| 289 | | | {@inheritDoc} |
| 290 | | | public boolean equals (Object o) |
| 291 | | | { |
| 292 | 0 | | return (o instanceof Severity) |
| 293 | | | && (mOrdinal == ((Severity) o).mOrdinal); |
| 294 | | | } |
| 295 | | | |
| 296 | | | {@inheritDoc} |
| 297 | | | public int hashCode () |
| 298 | | | { |
| 299 | 0 | | return mOrdinal; |
| 300 | | | } |
| 301 | | | |
| 302 | | | |
| 303 | | | |
| 304 | | | @param |
| 305 | | | @return |
| 306 | | | |
| 307 | | | public static Severity fromFindBugsPriority (String priority) |
| 308 | | | { |
| 309 | | | final Severity ret; |
| 310 | 0 | | switch (Integer.parseInt(priority)) |
| 311 | | | { |
| 312 | | | case Detector.IGNORE_PRIORITY: |
| 313 | 0 | | ret = Severity.FILTERED; |
| 314 | 0 | | break; |
| 315 | | | case Detector.EXP_PRIORITY: |
| 316 | | | |
| 317 | | | case Detector.LOW_PRIORITY: |
| 318 | 0 | | ret = Severity.INFO; |
| 319 | 0 | | break; |
| 320 | | | case Detector.NORMAL_PRIORITY: |
| 321 | 0 | | ret = Severity.WARNING; |
| 322 | 0 | | break; |
| 323 | | | case Detector.HIGH_PRIORITY: |
| 324 | 0 | | ret = Severity.ERROR; |
| 325 | 0 | | break; |
| 326 | | | |
| 327 | | | default : |
| 328 | 0 | | throw new RuntimeException("Unknown priority from FindBugs: " |
| 329 | | | + priority); |
| 330 | | | } |
| 331 | 0 | | return ret; |
| 332 | | | } |
| 333 | | | |
| 334 | | | |
| 335 | | | |
| 336 | | | @return |
| 337 | | | |
| 338 | | | public String toFindBugsPriority () |
| 339 | | | { |
| 340 | | | final String ret; |
| 341 | 0 | | if (Severity.ERROR == this) |
| 342 | | | { |
| 343 | 0 | | ret = String.valueOf(Detector.HIGH_PRIORITY); |
| 344 | | | } |
| 345 | 0 | | else if (Severity.WARNING == this) |
| 346 | | | { |
| 347 | 0 | | ret = String.valueOf(Detector.NORMAL_PRIORITY); |
| 348 | | | } |
| 349 | 0 | | else if (Severity.FILTERED == this) |
| 350 | | | { |
| 351 | 0 | | ret = String.valueOf(Detector.IGNORE_PRIORITY); |
| 352 | | | } |
| 353 | | | else |
| 354 | | | { |
| 355 | 0 | | ret = String.valueOf(Detector.LOW_PRIORITY); |
| 356 | | | } |
| 357 | 0 | | return ret; |
| 358 | | | } |
| 359 | | | |
| 360 | | | |
| 361 | | | |
| 362 | | | @param |
| 363 | | | @return |
| 364 | | | |
| 365 | | | public Severity max (Severity other) |
| 366 | | | { |
| 367 | | | final Severity result; |
| 368 | | | |
| 369 | 0 | | if (compareTo(other) > 0) |
| 370 | | | { |
| 371 | 0 | | result = this; |
| 372 | | | } |
| 373 | | | else |
| 374 | | | { |
| 375 | 0 | | result = other; |
| 376 | | | } |
| 377 | 0 | | return result; |
| 378 | | | } |
| 379 | | | |
| 380 | | | |
| 381 | | | |
| 382 | | | |
| 383 | | | |
| 384 | | | private Object readResolve () |
| 385 | | | { |
| 386 | 0 | | return PRIVATE_VALUES[mOrdinal]; |
| 387 | | | } |
| 388 | | | } |