View Javadoc

    1   package net.sourceforge.pmd;
    2
    3   import java.util.HashMap;
    4   import java.util.Map;
    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<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(JAVA_RULE_LANGUAGE_NAME);
    21      public static final 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 name) {
    32          return mapNameOnRuleLanguage.get(name);
    33      }
    34
    35      private String name;
    36
    37      /**
    38       * Public constructor.
    39       *
    40       * @param name the common name of the rule language
    41       */
    42      private Language(String name) {
    43          this.name = name;
    44          mapNameOnRuleLanguage.put(name, this);
    45      }
    46
    47      /**
    48       * @return Returns the name.
    49       */
    50      public String 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 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 toString() {
    80          return "Language [" + name + "]";
    81      }
    82  }