-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #40: Refactor the pattern components into separate class (Patte…
…rn is not a valid key in hashmaps) Also restructure testing infrastructure
- Loading branch information
1 parent
a29c91f
commit 1020ac4
Showing
10 changed files
with
114 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/de/thetaphi/forbiddenapis/ClassPatternRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.thetaphi.forbiddenapis; | ||
|
||
/* | ||
* (C) Copyright Uwe Schindler (Generics Policeman) and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public final class ClassPatternRule { | ||
|
||
public final Pattern pattern; | ||
public final String printout; | ||
|
||
public ClassPatternRule(String glob, String printout) { | ||
if (glob == null || printout == null) { | ||
throw new NullPointerException(); | ||
} | ||
this.pattern = AsmUtils.glob2Pattern(glob); | ||
assert this.pattern.flags() == 0 : "the pattern should have no flags (must be case-sensitive,...)"; | ||
this.printout = printout; | ||
} | ||
|
||
public boolean matches(String className) { | ||
return pattern.matcher(className).matches(); | ||
} | ||
|
||
// equals() / hashcode() use the string representation of pattern for comparisons | ||
// (Pattern unfortunately does not implement equals/hashCode) | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + pattern.pattern().hashCode(); | ||
result = prime * result + printout.hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null) return false; | ||
if (getClass() != obj.getClass()) return false; | ||
ClassPatternRule other = (ClassPatternRule) obj; | ||
if (!pattern.pattern().equals(other.pattern.pattern())) return false; | ||
if (!printout.equals(other.printout)) return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ClassPatternRule [pattern=" + pattern + ", printout=" + printout + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.