1 package com.puppycrawl.tools.checkstyle.checks.imports; 20 21 import java.io.Serializable ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 30 final class AccessResult 31 implements Serializable 32 { 33 34 private static final int CODE_ALLOWED = 10; 35 36 private static final int CODE_DISALLOWED = 20; 37 38 private static final int CODE_UNKNOWN = 30; 39 40 private static final String LABEL_ALLOWED = "ALLOWED"; 41 42 private static final String LABEL_DISALLOWED = "DISALLOWED"; 43 44 private static final String LABEL_UNKNOWN = "UNKNOWN"; 45 46 47 public static final AccessResult ALLOWED = new AccessResult(CODE_ALLOWED, 48 LABEL_ALLOWED); 49 50 public static final AccessResult DISALLOWED = new AccessResult( 51 CODE_DISALLOWED, LABEL_DISALLOWED); 52 53 public static final AccessResult UNKNOWN = new AccessResult(CODE_UNKNOWN, 54 LABEL_UNKNOWN); 55 56 57 private static final Map NAME_TO_LEVEL = new HashMap (); 58 static { 59 NAME_TO_LEVEL.put(LABEL_ALLOWED, ALLOWED); 60 NAME_TO_LEVEL.put(LABEL_DISALLOWED, DISALLOWED); 61 NAME_TO_LEVEL.put(LABEL_UNKNOWN, UNKNOWN); 62 } 63 64 65 private final int mCode; 66 67 private final String mLabel; 68 69 75 private AccessResult(final int aCode, final String aLabel) 76 { 77 mCode = aCode; 78 mLabel = aLabel.trim(); 79 } 80 81 84 String getLabel() 85 { 86 return mLabel; 87 } 88 89 90 public String toString() 91 { 92 return getLabel(); 93 } 94 95 96 public boolean equals(Object aObj) 97 { 98 boolean result = false; 99 100 if ((aObj instanceof AccessResult) 101 && (((AccessResult) aObj).mCode == this.mCode)) 102 { 103 result = true; 104 } 105 106 return result; 107 } 108 109 110 public int hashCode() 111 { 112 return mCode; 113 } 114 115 121 public static AccessResult getInstance(String aName) 122 { 123 final String arName = aName.trim(); 125 126 final AccessResult retVal = (AccessResult) NAME_TO_LEVEL.get(arName); 127 if (retVal == null) { 128 throw new IllegalArgumentException (arName); 129 } 130 return retVal; 131 } 132 133 140 private Object readResolve() 141 { 142 return getInstance(mLabel); 143 } 144 145 } 146 | Popular Tags |