01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.matcher;
19:
20: /**
21: * A pattern matcher that tries to match exactly the input with the expression, or match it as a
22: * pattern. <p/> The evaluation for matching is perform first by checking if expression and input
23: * are equals (via equals method) else it attempts to do it by trying to match the input using the
24: * expression as a regexp.
25: *
26: * @see ExactPatternMatcher
27: * @see RegexpPatternMatcher
28: */
29: public/* @Immutable */final class ExactOrRegexpPatternMatcher extends
30: AbstractPatternMatcher {
31:
32: public static final ExactOrRegexpPatternMatcher INSTANCE = new ExactOrRegexpPatternMatcher();
33:
34: public ExactOrRegexpPatternMatcher() {
35: super (EXACT_OR_REGEXP);
36: }
37:
38: protected Matcher newMatcher(String expression) {
39: return new ExactOrRegexpMatcher(expression);
40: }
41:
42: private static final class ExactOrRegexpMatcher implements Matcher {
43: private Matcher exact;
44:
45: private Matcher regexp;
46:
47: public ExactOrRegexpMatcher(String expression) {
48: exact = ExactPatternMatcher.INSTANCE.getMatcher(expression);
49: regexp = RegexpPatternMatcher.INSTANCE
50: .getMatcher(expression);
51: }
52:
53: public boolean matches(String input) {
54: if (input == null) {
55: throw new NullPointerException();
56: }
57: return exact.matches(input) || regexp.matches(input);
58: }
59:
60: public boolean isExact() {
61: return false;
62: }
63: }
64: }
|