KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > Language


1 package net.sourceforge.pmd;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 /**
7  * Enumeration of languages for which a rule can be written.
8  * <p/>
9  * This has no 1-on-1 mapping to the SourceType enumeration, because rules will often
10  * apply to all versions of a programming language, and SourceType is version-specific.
11  *
12  * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
13  */

14 public final class Language {
15     private static Map JavaDoc mapNameOnRuleLanguage = new HashMap JavaDoc();
16
17     private static final String JavaDoc JSP_RULE_LANGUAGE_NAME = "jsp";
18     private static final String JavaDoc JAVA_RULE_LANGUAGE_NAME = "java";
19
20     public static Language JAVA = new Language(JAVA_RULE_LANGUAGE_NAME);
21     public static Language JSP = new Language(JSP_RULE_LANGUAGE_NAME);
22
23
24     /**
25      * Get the RuleLanguage that corresponds to the given name.
26      *
27      * @param name the common name of the rule language; this must correspond to one of
28      * the name constants.
29      * @return the corresponding RuleLanuage; or null if the name is not recognized
30      */

31     public static Language getByName(String JavaDoc name) {
32         return (Language) mapNameOnRuleLanguage.get(name);
33     }
34
35     private String JavaDoc name;
36
37     /**
38      * Public constructor.
39      *
40      * @param name the common name of the rule language
41      */

42     private Language(String JavaDoc name) {
43         this.name = name;
44         mapNameOnRuleLanguage.put(name, this);
45     }
46
47     /**
48      * @return Returns the name.
49      */

50     public String JavaDoc getName() {
51         return name;
52     }
53
54     /*
55      * (non-Javadoc)
56      *
57      * @see java.lang.Object#equals(java.lang.Object)
58      */

59     public boolean equals(Object JavaDoc obj) {
60         if (obj instanceof Language) {
61             return ((Language) obj).getName().equals(name);
62         } else {
63             return false;
64         }
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see java.lang.Object#hashCode()
71      */

72     public int hashCode() {
73         return name.hashCode();
74     }
75
76     /* (non-Javadoc)
77      * @see java.lang.Object#toString()
78      */

79     public String JavaDoc toString() {
80         return "Language [" + name + "]";
81     }
82 }
83
Popular Tags