1 package net.sourceforge.pmd; 2 3 /** 4 * These are the possible Rule priority values. 5 * 6 * For backward compatibility, priorities range in value from 1 to 5, with 5 7 * being the lowest priority. This means the ordinal value of the Enum should 8 * be avoided in favor of {@link RulePriority#getPriority()} and 9 * {@link RulePriority#valueOf(int)} 10 */ 11 public enum RulePriority { 12 HIGH(1, "High"), 13 MEDIUM_HIGH(2, "Medium High"), 14 MEDIUM(3, "Medium"), 15 MEDIUM_LOW(4, "Medium Low"), 16 LOW(5, "Low"); 17 18 private final int priority; 19 private final String name; 20 21 private RulePriority(int priority, String name) { 22 this.priority = priority; 23 this.name = name; 24 } 25 26 /** 27 * Get the priority value as a number. This is the value to be used in 28 * the externalized form of a priority (e.g. in RuleSet XML). 29 * @return The <code>int</code> value of the priority. 30 */ 31 public int getPriority() { 32 return priority; 33 } 34 35 /** 36 * Get the descriptive name of this priority. 37 * @return The descriptive name. 38 */ 39 public String getName() { 40 return name; 41 } 42 43 /** 44 * Returns the descriptive name of the priority. 45 */ 46 @Override 47 public String toString() { 48 return name; 49 } 50 51 /** 52 * Get the priority which corresponds to the given number as returned 53 * by {@link RulePriority#getPriority()}. If the number is an invalid 54 * value, then {@link RulePriority#LOW} will be returned. 55 * @param priority The numeric priority value. 56 * @return The priority. 57 */ 58 public static RulePriority valueOf(int priority) { 59 try { 60 return RulePriority.values()[priority - 1]; 61 } catch (ArrayIndexOutOfBoundsException e) { 62 return LOW; 63 } 64 } 65 }