01: package net.sourceforge.pmd;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: /**
07: * Enumeration of languages for which a rule can be written.
08: * <p/>
09: * 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<String, Language> mapNameOnRuleLanguage = new HashMap<String, Language>();
16:
17: private static final String JSP_RULE_LANGUAGE_NAME = "jsp";
18: private static final String JAVA_RULE_LANGUAGE_NAME = "java";
19:
20: public static final Language JAVA = new Language(
21: JAVA_RULE_LANGUAGE_NAME);
22: public static final Language JSP = new Language(
23: JSP_RULE_LANGUAGE_NAME);
24:
25: /**
26: * Get the RuleLanguage that corresponds to the given name.
27: *
28: * @param name the common name of the rule language; this must correspond to one of
29: * the name constants.
30: * @return the corresponding RuleLanuage; or null if the name is not recognized
31: */
32: public static Language getByName(String name) {
33: return mapNameOnRuleLanguage.get(name);
34: }
35:
36: private String name;
37:
38: /**
39: * Public constructor.
40: *
41: * @param name the common name of the rule language
42: */
43: private Language(String name) {
44: this .name = name;
45: mapNameOnRuleLanguage.put(name, this );
46: }
47:
48: /**
49: * @return Returns the name.
50: */
51: public String getName() {
52: return name;
53: }
54:
55: /*
56: * (non-Javadoc)
57: *
58: * @see java.lang.Object#equals(java.lang.Object)
59: */
60: public boolean equals(Object obj) {
61: if (obj instanceof Language) {
62: return ((Language) obj).getName().equals(name);
63: } else {
64: return false;
65: }
66: }
67:
68: /*
69: * (non-Javadoc)
70: *
71: * @see java.lang.Object#hashCode()
72: */
73: public int hashCode() {
74: return name.hashCode();
75: }
76:
77: /* (non-Javadoc)
78: * @see java.lang.Object#toString()
79: */
80: public String toString() {
81: return "Language [" + name + "]";
82: }
83: }
|