com.github.ruediste.salta.matchers.Matchers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of salta-core Show documentation
Show all versions of salta-core Show documentation
Core of the Salta Framework. Provides most of the infrastructure, but no API
package com.github.ruediste.salta.matchers;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
/**
* Matcher implementations. Supports matching classes and methods.
*
* @author [email protected] (Bob Lee)
*/
@SuppressWarnings("rawtypes")
public class Matchers {
private Matchers() {
}
static class AndMatcher implements Matcher, 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;
}
static class OrMatcher implements Matcher, 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;
}
/**
* Returns a matcher which matches any input.
*/
public static Matcher
© 2015 - 2024 Weber Informatics LLC | Privacy Policy