01: package net.sourceforge.pmd;
02:
03: /**
04: * Enumeration of the types of source code.
05: *
06: * @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
07: */
08: public final class SourceType implements Comparable<SourceType> {
09: 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[] {
17: JAVA_13, JAVA_14, JAVA_15, JAVA_16, JAVA_17, JSP };
18:
19: private String id;
20:
21: /**
22: * Private constructor.
23: */
24: private SourceType(String id) {
25: this .id = id;
26: }
27:
28: public String getId() {
29: return id;
30: }
31:
32: /**
33: * Get the SourceType for a certain Id. Case insensitive.
34: *
35: * @return null if not found
36: */
37: public static SourceType getSourceTypeForId(String id) {
38: for (SourceType sourceType : sourceTypes) {
39: if (sourceType.getId().equalsIgnoreCase(id)) {
40: return sourceType;
41: }
42: }
43: return null;
44: }
45:
46: public boolean equals(Object other) {
47: if (other instanceof SourceType) {
48: return ((SourceType) other).getId().equals(getId());
49: }
50:
51: return false;
52: }
53:
54: public int hashCode() {
55: return getId().hashCode();
56: }
57:
58: public int compareTo(SourceType other) {
59: return getId().compareTo(other.getId());
60: }
61:
62: public String toString() {
63: return "SourceType [" + getId() + "]";
64: }
65: }
|