Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose and/or matchers #1200

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions core/src/com/google/inject/matcher/AbstractMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.google.inject.matcher;

import java.io.Serializable;

/**
* Implements {@code and()} and {@code or()}.
*
Expand All @@ -34,70 +32,4 @@ public Matcher<T> and(final Matcher<? super T> other) {
public Matcher<T> or(Matcher<? super T> other) {
return new OrMatcher<T>(this, other);
}

private static class AndMatcher<T> extends AbstractMatcher<T> implements Serializable {
private final Matcher<? super T> a, b;

public AndMatcher(Matcher<? super T> a, Matcher<? super T> b) {
this.a = a;
this.b = b;
}

@Override
public boolean matches(T t) {
return a.matches(t) && b.matches(t);
}

@Override
public boolean equals(Object other) {
return other instanceof AndMatcher
&& ((AndMatcher) other).a.equals(a)
&& ((AndMatcher) other).b.equals(b);
}

@Override
public int hashCode() {
return 41 * (a.hashCode() ^ b.hashCode());
}

@Override
public String toString() {
return "and(" + a + ", " + b + ")";
}

private static final long serialVersionUID = 0;
}

private static class OrMatcher<T> extends AbstractMatcher<T> implements Serializable {
private final Matcher<? super T> a, b;

public OrMatcher(Matcher<? super T> a, Matcher<? super T> b) {
this.a = a;
this.b = b;
}

@Override
public boolean matches(T t) {
return a.matches(t) || b.matches(t);
}

@Override
public boolean equals(Object other) {
return other instanceof OrMatcher
&& ((OrMatcher) other).a.equals(a)
&& ((OrMatcher) other).b.equals(b);
}

@Override
public int hashCode() {
return 37 * (a.hashCode() ^ b.hashCode());
}

@Override
public String toString() {
return "or(" + a + ", " + b + ")";
}

private static final long serialVersionUID = 0;
}
}
52 changes: 52 additions & 0 deletions core/src/com/google/inject/matcher/AndMatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2006 Google Inc.
*
* 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.
*/

package com.google.inject.matcher;

import java.io.Serializable;

public class AndMatcher<T> extends AbstractMatcher<T> implements Serializable {
private final Matcher<? super T> a, b;

public AndMatcher(Matcher<? super T> a, Matcher<? super T> b) {
this.a = a;
this.b = b;
}

@Override
public boolean matches(T t) {
return a.matches(t) && b.matches(t);
}

@Override
public boolean equals(Object other) {
return other instanceof AndMatcher
&& ((AndMatcher) other).a.equals(a)
&& ((AndMatcher) other).b.equals(b);
}

@Override
public int hashCode() {
return 41 * (a.hashCode() ^ b.hashCode());
}

@Override
public String toString() {
return "and(" + a + ", " + b + ")";
}

private static final long serialVersionUID = 0;
}
52 changes: 52 additions & 0 deletions core/src/com/google/inject/matcher/OrMatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2006 Google Inc.
*
* 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.
*/

package com.google.inject.matcher;

import java.io.Serializable;

public class OrMatcher<T> extends AbstractMatcher<T> implements Serializable {
private final Matcher<? super T> a, b;

public OrMatcher(Matcher<? super T> a, Matcher<? super T> b) {
this.a = a;
this.b = b;
}

@Override
public boolean matches(T t) {
return a.matches(t) || b.matches(t);
}

@Override
public boolean equals(Object other) {
return other instanceof OrMatcher
&& ((OrMatcher) other).a.equals(a)
&& ((OrMatcher) other).b.equals(b);
}

@Override
public int hashCode() {
return 37 * (a.hashCode() ^ b.hashCode());
}

@Override
public String toString() {
return "or(" + a + ", " + b + ")";
}

private static final long serialVersionUID = 0;
}