rinde.sim.util.spec.CompositeSpecification Maven / Gradle / Ivy
/**
*
*/
package rinde.sim.util.spec;
/**
* @author Rinde van Lon
*
*/
public abstract class CompositeSpecification>
implements ISpecification {
@Override
public abstract boolean isSatisfiedBy(T context);
@Override
public U and(U other) {
return wrap(new AndSpecification((U) this, other));
}
@Override
public U or(U other) {
return wrap(new OrSpecification((U) this, other));
}
@Override
public U not() {
return wrap(new NotSpecification((U) this));
}
protected abstract U wrap(ISpecification spec);
public final class AndSpecification>
extends CompositeSpecification {
private final U spec1;
private final U spec2;
AndSpecification(U one, U other) {
spec1 = one;
spec2 = other;
}
@Override
public boolean isSatisfiedBy(T context) {
return spec1.isSatisfiedBy(context) && spec2.isSatisfiedBy(context);
}
@Override
protected U wrap(ISpecification spec) {
return null;
}
}
public final class OrSpecification>
extends CompositeSpecification {
private final U spec1;
private final U spec2;
OrSpecification(U one, U other) {
spec1 = one;
spec2 = other;
}
@Override
public boolean isSatisfiedBy(T context) {
return spec1.isSatisfiedBy(context) || spec2.isSatisfiedBy(context);
}
@Override
protected U wrap(ISpecification spec) {
return null;
}
}
public final class NotSpecification>
extends CompositeSpecification {
private final U spec;
NotSpecification(U specification) {
spec = specification;
}
@Override
public boolean isSatisfiedBy(T context) {
return !spec.isSatisfiedBy(context);
}
@Override
protected U wrap(ISpecification spec) {
return null;
}
}
}