View Javadoc

    1
    2    package> net.sourceforge.pmd;
    3
    4    /***
    5     * Enumeration of the types of source code.
    6     *
    7     * @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
    8     */
    9    public final class SourceType implements Comparable {
    10       public static final SourceType JAVA_13 = new SourceType("java 1.3");
    11       public static final SourceType JAVA_14 = new SourceType("java 1.4");
    12       public static final SourceType JAVA_15 = new SourceType("java 1.5");
    13       public static final SourceType JAVA_16 = new SourceType("java 1.6");
    14       public static final SourceType JSP = new SourceType("jsp");
    15
    16       private static SourceType[] sourceTypes = new SourceType[]{JAVA_13, JAVA_14, JAVA_15, JAVA_16, JSP};
    17
    18       private String id;
    19
    20       /***
    21        * Private constructor.
    22        */
    23       private SourceType(String id) {
    24           this.id = id;
    25       }
    26
    27       public String getId() {
    28           return id;
    29       }
    30
    31       /***
    32        * Get the SourceType for a certain Id. Case insensitive.
    33        *
    34        * @return null if not found
    35        */
    36       public static SourceType getSourceTypeForId(String id) {
    37           for (int i = 0; i < sourceTypes.length; i++) {
    38               if (sourceTypes[i].getId().equalsIgnoreCase(id)) {
    39                   return sourceTypes[i];
    40               }
    41           }
    42           return null;
    43       }
    44
    45       public boolean equals(Object other) {
    46           if (other instanceof SourceType) {
    47               return ((SourceType) other).getId().equals(getId());
    48           }
    49
    50           return false;
    51       }
    52
    53       public int hashCode() {
    54           return getId().hashCode();
    55       }
    56
    57       public int compareTo(Object other) {
    58           return getId().compareTo(((SourceType) other).getId());
    59       }
    60
    61       public String toString() {
    62           return "SourceType [" + getId() + "]";
    63       }
    64   }