|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AccessResult | Line # 30 | 100% |
1.0
|
11 | 18 | 11 | 11 | 0.61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (9) | |||
| Result | |||
|
0.8666667
|
com.puppycrawl.tools.checkstyle.checks.imports.AccessResultTest.testNormal
com.puppycrawl.tools.checkstyle.checks.imports.AccessResultTest.testNormal
|
1 PASS | |
|
0.26666668
|
com.puppycrawl.tools.checkstyle.checks.imports.AccessResultTest.testSerial
com.puppycrawl.tools.checkstyle.checks.imports.AccessResultTest.testSerial
|
1 PASS | |
|
0.23333333
|
com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheckTest.testOne
com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheckTest.testOne
|
1 PASS | |
|
0.23333333
|
com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheckTest.testTwo
com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheckTest.testTwo
|
1 PASS | |
|
0.2
|
com.puppycrawl.tools.checkstyle.checks.imports.GuardTest.testClassGuard
com.puppycrawl.tools.checkstyle.checks.imports.GuardTest.testClassGuard
|
1 PASS | |
|
0.2
|
com.puppycrawl.tools.checkstyle.checks.imports.PkgControlTest.testCheckAccess
com.puppycrawl.tools.checkstyle.checks.imports.PkgControlTest.testCheckAccess
|
1 PASS | |
|
0.2
|
com.puppycrawl.tools.checkstyle.checks.imports.GuardTest.testPkgGuard1
com.puppycrawl.tools.checkstyle.checks.imports.GuardTest.testPkgGuard1
|
1 PASS | |
|
0.2
|
com.puppycrawl.tools.checkstyle.checks.imports.AccessResultTest.testBadname
com.puppycrawl.tools.checkstyle.checks.imports.AccessResultTest.testBadname
|
1 PASS | |
|
0.2
|
com.puppycrawl.tools.checkstyle.checks.imports.GuardTest.testPkgGuard2
com.puppycrawl.tools.checkstyle.checks.imports.GuardTest.testPkgGuard2
|
1 PASS | |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2005 Oliver Burn | |
| 4 | // | |
| 5 | // This library is free software; you can redistribute it and/or | |
| 6 | // modify it under the terms of the GNU Lesser General Public | |
| 7 | // License as published by the Free Software Foundation; either | |
| 8 | // version 2.1 of the License, or (at your option) any later version. | |
| 9 | // | |
| 10 | // This library is distributed in the hope that it will be useful, | |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | // Lesser General Public License for more details. | |
| 14 | // | |
| 15 | // You should have received a copy of the GNU Lesser General Public | |
| 16 | // License along with this library; if not, write to the Free Software | |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 | //////////////////////////////////////////////////////////////////////////////// | |
| 19 | 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 | /** | |
| 26 | * Represents the result of an access check. | |
| 27 | * | |
| 28 | * @author Oliver Burn | |
| 29 | */ | |
| 30 | final class AccessResult | |
| 31 | implements Serializable | |
| 32 | { | |
| 33 | /** Numeric value for access result ALLOWED. */ | |
| 34 | private static final int CODE_ALLOWED = 10; | |
| 35 | /** Numeric value for access result DISALLOWED. */ | |
| 36 | private static final int CODE_DISALLOWED = 20; | |
| 37 | /** Numeric value for access result UNKNOWN. */ | |
| 38 | private static final int CODE_UNKNOWN = 30; | |
| 39 | /** Label for access result ALLOWED. */ | |
| 40 | private static final String LABEL_ALLOWED = "ALLOWED"; | |
| 41 | /** Label for access result DISALLOWED. */ | |
| 42 | private static final String LABEL_DISALLOWED = "DISALLOWED"; | |
| 43 | /** Label for access result UNKNOWN. */ | |
| 44 | private static final String LABEL_UNKNOWN = "UNKNOWN"; | |
| 45 | ||
| 46 | /** Represents that access is allowed. */ | |
| 47 | public static final AccessResult ALLOWED = new AccessResult(CODE_ALLOWED, | |
| 48 | LABEL_ALLOWED); | |
| 49 | /** Represents that access is disallowed. */ | |
| 50 | public static final AccessResult DISALLOWED = new AccessResult( | |
| 51 | CODE_DISALLOWED, LABEL_DISALLOWED); | |
| 52 | /** Represents that access is unknown. */ | |
| 53 | public static final AccessResult UNKNOWN = new AccessResult(CODE_UNKNOWN, | |
| 54 | LABEL_UNKNOWN); | |
| 55 | ||
| 56 | /** map from results names to the respective result */ | |
| 57 | private static final Map NAME_TO_LEVEL = new HashMap(); | |
| 58 | 1 |
static { |
| 59 | 1 | NAME_TO_LEVEL.put(LABEL_ALLOWED, ALLOWED); |
| 60 | 1 | NAME_TO_LEVEL.put(LABEL_DISALLOWED, DISALLOWED); |
| 61 | 1 | NAME_TO_LEVEL.put(LABEL_UNKNOWN, UNKNOWN); |
| 62 | } | |
| 63 | ||
| 64 | /** Code for the access result. */ | |
| 65 | private final int mCode; | |
| 66 | /** Label for the access result. */ | |
| 67 | private final String mLabel; | |
| 68 | ||
| 69 | /** | |
| 70 | * Constructs an instance. | |
| 71 | * | |
| 72 | * @param aCode the code for the result. | |
| 73 | * @param aLabel the label for the result. | |
| 74 | */ | |
| 75 | 3 |
private AccessResult(final int aCode, final String aLabel) |
| 76 | { | |
| 77 | 3 | mCode = aCode; |
| 78 | 3 | mLabel = aLabel.trim(); |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * @return the label for the result. | |
| 83 | */ | |
| 84 | 4 |
String getLabel() |
| 85 | { | |
| 86 | 4 | return mLabel; |
| 87 | } | |
| 88 | ||
| 89 | /** {@inheritDoc} */ | |
| 90 | 1 |
public String toString() |
| 91 | { | |
| 92 | 1 | return getLabel(); |
| 93 | } | |
| 94 | ||
| 95 | /** {@inheritDoc} */ | |
| 96 | 34 |
public boolean equals(Object aObj) |
| 97 | { | |
| 98 | 34 | boolean result = false; |
| 99 | ||
| 100 | 34 | if ((aObj instanceof AccessResult) |
| 101 | && (((AccessResult) aObj).mCode == this.mCode)) | |
| 102 | { | |
| 103 | 29 | result = true; |
| 104 | } | |
| 105 | ||
| 106 | 34 | return result; |
| 107 | } | |
| 108 | ||
| 109 | /** {@inheritDoc} */ | |
| 110 | 2 |
public int hashCode() |
| 111 | { | |
| 112 | 2 | return mCode; |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * SeverityLevel factory method. | |
| 117 | * | |
| 118 | * @param aName access result name. | |
| 119 | * @return the {@link AccessResult} associated with the supplied name. | |
| 120 | */ | |
| 121 | 3 |
public static AccessResult getInstance(String aName) |
| 122 | { | |
| 123 | // canonicalize argument | |
| 124 | 3 | final String arName = aName.trim(); |
| 125 | ||
| 126 | 3 | final AccessResult retVal = (AccessResult) NAME_TO_LEVEL.get(arName); |
| 127 | 3 | if (retVal == null) { |
| 128 | 1 | throw new IllegalArgumentException(arName); |
| 129 | } | |
| 130 | 2 | return retVal; |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Ensures that we don't get multiple instances of one SeverityLevel | |
| 135 | * during deserialization. See Section 3.6 of the Java Object | |
| 136 | * Serialization Specification for details. | |
| 137 | * | |
| 138 | * @return the serialization replacement object | |
| 139 | */ | |
| 140 | 1 |
private Object readResolve() |
| 141 | { | |
| 142 | 1 | return getInstance(mLabel); |
| 143 | } | |
| 144 | ||
| 145 | } | |
|
|||||||||||||