View Javadoc

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