Split ref pattern matching functionality out of SectionMatcher

Refactor SectionMatcher to extract the ref pattern matching part into
its own class, RefPatternMatcher, which can be reused in other classes.

Change-Id: Id66f636d3af6d0d5d4f51a10848dd8caeaf565d0
This commit is contained in:
Bruce Zu
2013-09-05 15:17:06 +08:00
committed by David Pursehouse
parent eb952c1c80
commit cb16623109
3 changed files with 136 additions and 123 deletions

View File

@@ -77,7 +77,7 @@ public class PermissionCollection {
boolean perUser = false;
Map<AccessSection, Project.NameKey> sectionToProject = Maps.newLinkedHashMap();
for (SectionMatcher matcher : matcherList) {
for (SectionMatcher sm : matcherList) {
// If the matcher has to expand parameters and its prefix matches the
// reference there is a very good chance the reference is actually user
// specific, even if the matcher does not match the reference. Since its
@@ -91,12 +91,12 @@ public class PermissionCollection {
// references are usually less frequent than the non-user references.
//
if (username != null && !perUser
&& matcher instanceof SectionMatcher.ExpandParameters) {
perUser = ((SectionMatcher.ExpandParameters) matcher).matchPrefix(ref);
&& sm.matcher instanceof RefPatternMatcher.ExpandParameters) {
perUser = ((RefPatternMatcher.ExpandParameters) sm.matcher).matchPrefix(ref);
}
if (matcher.match(ref, username)) {
sectionToProject.put(matcher.section, matcher.project);
if (sm.match(ref, username)) {
sectionToProject.put(sm.section, sm.project);
}
}
List<AccessSection> sections = Lists.newArrayList(sectionToProject.keySet());