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 30 public final class Scope implements Comparable , Serializable 31 { 32 36 37 private static final int SCOPECODE_NOTHING = 0; 38 39 private static final int SCOPECODE_PUBLIC = 1; 40 41 private static final int SCOPECODE_PROTECTED = 2; 42 43 private static final int SCOPECODE_PACKAGE = 3; 44 45 private static final int SCOPECODE_PRIVATE = 4; 46 47 private static final int SCOPECODE_ANONINNER = 5; 48 49 50 private static final String SCOPENAME_NOTHING = "nothing"; 51 52 private static final String SCOPENAME_PUBLIC = "public"; 53 54 private static final String SCOPENAME_PROTECTED = "protected"; 55 56 private static final String SCOPENAME_PACKAGE = "package"; 57 58 private static final String SCOPENAME_PRIVATE = "private"; 59 60 private static final String SCOPENAME_ANONINNER = "anoninner"; 61 62 63 public static final Scope NOTHING = 64 new Scope(SCOPECODE_NOTHING, SCOPENAME_NOTHING); 65 66 67 public static final Scope PUBLIC = 68 new Scope(SCOPECODE_PUBLIC, SCOPENAME_PUBLIC); 69 70 71 public static final Scope PROTECTED = 72 new Scope(SCOPECODE_PROTECTED, SCOPENAME_PROTECTED); 73 74 75 public static final Scope PACKAGE = 76 new Scope(SCOPECODE_PACKAGE, SCOPENAME_PACKAGE); 77 78 79 public static final Scope PRIVATE = 80 new Scope(SCOPECODE_PRIVATE, SCOPENAME_PRIVATE); 81 82 83 public static final Scope ANONINNER = 84 new Scope(SCOPECODE_ANONINNER, SCOPENAME_ANONINNER); 85 86 87 private static final Map NAME_TO_SCOPE = new HashMap (); 88 static { 89 NAME_TO_SCOPE.put(SCOPENAME_NOTHING, NOTHING); 90 NAME_TO_SCOPE.put(SCOPENAME_PUBLIC, PUBLIC); 91 NAME_TO_SCOPE.put(SCOPENAME_PROTECTED, PROTECTED); 92 NAME_TO_SCOPE.put(SCOPENAME_PACKAGE, PACKAGE); 93 NAME_TO_SCOPE.put(SCOPENAME_PRIVATE, PRIVATE); 94 NAME_TO_SCOPE.put(SCOPENAME_ANONINNER, ANONINNER); 95 } 96 97 98 private final int mCode; 99 100 101 private final String mName; 102 103 106 public String toString() 107 { 108 return "Scope[" + mCode + " (" + mName + ")]"; 109 } 110 111 114 public String getName() 115 { 116 return mName; 117 } 118 119 122 public int compareTo(Object aObject) 123 { 124 final Scope s = (Scope) aObject; 125 return this.mCode - s.mCode; 126 } 127 128 135 public boolean isIn(Scope aScope) 136 { 137 return (compareTo(aScope) <= 0); 138 } 139 140 146 private Scope(int aCode, String aName) 147 { 148 mCode = aCode; 149 mName = aName; 150 } 151 152 158 public static Scope getInstance(String aScopeName) 159 { 160 final String scopeName = aScopeName.trim().toLowerCase(); 163 164 final Scope retVal = (Scope) NAME_TO_SCOPE.get(scopeName); 165 if (retVal == null) { 166 throw new IllegalArgumentException (scopeName); 167 } 168 return retVal; 169 } 170 171 178 private Object readResolve() 179 { 180 return getInstance(mName); 181 } 182 } 183 | Popular Tags |