View Javadoc

    1   package net.sourceforge.pmd;
    2
    3    /**
    4     * Enumeration of the types of source code.
    5     *
    6     * @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
    7     */
    8    public final class SourceType implements Comparable<SourceType> {
    9        public static final SourceType JAVA_13 = new SourceType("java 1.3");
    10       public static final SourceType JAVA_14 = new SourceType("java 1.4");
    11       public static final SourceType JAVA_15 = new SourceType("java 1.5");
    12       public static final SourceType JAVA_16 = new SourceType("java 1.6");
    13       public static final SourceType JAVA_17 = new SourceType("java 1.7");
    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, JAVA_17, 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 (SourceType sourceType : sourceTypes) {
    38               if (sourceType.getId().equalsIgnoreCase(id)) {
    39                   return sourceType;
    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(SourceType other) {
    58           return getId().compareTo(other.getId());
    59       }
    60
    61       public String toString() {
    62           return "SourceType [" + getId() + "]";
    63       }
    64   }