1 package com.puppycrawl.tools.checkstyle.api; 20 21 import java.io.Serializable ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 33 public final class SeverityLevel implements Comparable , Serializable 34 { 35 36 private static final int SEVERITYCODE_IGNORE = 10; 37 38 private static final int SEVERITYCODE_INFO = 20; 39 40 private static final int SEVERITYCODE_WARNING = 30; 41 42 private static final int SEVERITYCODE_ERROR = 40; 43 44 45 46 private static final String SEVERITYNAME_IGNORE = "ignore"; 47 48 private static final String SEVERITYNAME_INFO = "info"; 49 50 private static final String SEVERITYNAME_WARNING = "warning"; 51 52 private static final String SEVERITYNAME_ERROR = "error"; 53 54 55 public static final SeverityLevel IGNORE = 56 new SeverityLevel(SEVERITYCODE_IGNORE, SEVERITYNAME_IGNORE); 57 58 59 public static final SeverityLevel INFO = 60 new SeverityLevel(SEVERITYCODE_INFO, SEVERITYNAME_INFO); 61 62 63 public static final SeverityLevel WARNING = 64 new SeverityLevel(SEVERITYCODE_WARNING, SEVERITYNAME_WARNING); 65 66 67 public static final SeverityLevel ERROR = 68 new SeverityLevel(SEVERITYCODE_ERROR, SEVERITYNAME_ERROR); 69 70 71 private static final Map NAME_TO_LEVEL = new HashMap (); 72 static { 73 NAME_TO_LEVEL.put(SEVERITYNAME_IGNORE, IGNORE); 74 NAME_TO_LEVEL.put(SEVERITYNAME_INFO, INFO); 75 NAME_TO_LEVEL.put(SEVERITYNAME_WARNING, WARNING); 76 NAME_TO_LEVEL.put(SEVERITYNAME_ERROR, ERROR); 77 } 78 79 80 private final int mCode; 81 82 83 private final String mName; 84 85 88 public String toString() 89 { 90 return "Severity[" + mCode + " (" + mName + ")]"; 91 } 92 93 96 public String getName() 97 { 98 return mName; 99 } 100 101 104 public int compareTo(Object aObject) 105 { 106 final SeverityLevel severity = (SeverityLevel) aObject; 107 return this.mCode - severity.mCode; 108 } 109 110 118 public boolean equals(Object aObj) 119 { 120 boolean result = false; 121 122 if ((aObj instanceof SeverityLevel) 123 && (((SeverityLevel) aObj).mCode == this.mCode)) 124 { 125 result = true; 126 } 127 128 return result; 129 } 130 131 136 public int hashCode() 137 { 138 return mCode; 139 } 140 141 147 private SeverityLevel(int aCode, String aName) 148 { 149 mCode = aCode; 150 mName = aName; 151 } 152 153 160 public static SeverityLevel getInstance(String aSeverityName) 161 { 162 final String severityName = aSeverityName.trim().toLowerCase(); 164 165 final SeverityLevel retVal = 166 (SeverityLevel) NAME_TO_LEVEL.get(severityName); 167 if (retVal == null) { 168 throw new IllegalArgumentException (severityName); 169 } 170 return retVal; 171 } 172 173 180 private Object readResolve() 181 { 182 return getInstance(mName); 183 } 184 } 185 | Popular Tags |