1 2 package net.sourceforge.pmd; 3 4 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 23 private SourceType(String id) { 24 this.id = id; 25 } 26 27 public String getId() { 28 return id; 29 } 30 31 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 } 65 | Popular Tags |