01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */package com.bm.ejb3guice.matcher;
16:
17: /**
18: * Implements {@code and()} and {@code or()}.
19: *
20: * @author crazybob@google.com (Bob Lee)
21: */
22: public abstract class AbstractMatcher<T> implements Matcher<T> {
23:
24: public Matcher<T> and(final Matcher<? super T> other) {
25: return new AndMatcher<T>(this , other);
26: }
27:
28: public Matcher<T> or(Matcher<? super T> other) {
29: return new OrMatcher<T>(this , other);
30: }
31:
32: static class AndMatcher<T> extends AbstractMatcher<T> {
33:
34: final Matcher<? super T> a, b;
35:
36: public AndMatcher(Matcher<? super T> a, Matcher<? super T> b) {
37: this .a = a;
38: this .b = b;
39: }
40:
41: public boolean matches(T t) {
42: return a.matches(t) && b.matches(t);
43: }
44: }
45:
46: static class OrMatcher<T> extends AbstractMatcher<T> {
47:
48: final Matcher<? super T> a, b;
49:
50: public OrMatcher(Matcher<? super T> a, Matcher<? super T> b) {
51: this .a = a;
52: this .b = b;
53: }
54:
55: public boolean matches(T t) {
56: return a.matches(t) || b.matches(t);
57: }
58: }
59: }
|