Content deleted Content added
→Python: bugfixes |
|||
Line 418:
{
return new NotSpecification<T>(*this);
}
</syntaxhighlight>
=== [[TypeScript|TypeScript]] ===
<syntaxhighlight lang="typescript">
export interface ISpecification {
isSatisfiedBy(candidate: unknown): boolean;
and(other: ISpecification): ISpecification;
andNot(other: ISpecification): ISpecification;
or(other: ISpecification): ISpecification;
orNot(other: ISpecification): ISpecification;
not(): ISpecification;
}
abstract class CompositeSpecification implements ISpecification {
abstract isSatisfiedBy(candidate: unknown): boolean;
and(other: ISpecification): ISpecification {
return new AndSpecification(this, other);
}
andNot(other: ISpecification): ISpecification {
return new AndNotSpecification(this, other);
}
or(other: ISpecification): ISpecification {
return new OrSpecification(this, other);
}
orNot(other: ISpecification): ISpecification {
return new OrNotSpecification(this, other);
}
not(): ISpecification {
return new NotSpecification(this);
}
}
class AndSpecification extends CompositeSpecification {
private leftCondition: ISpecification;
private rightCondition: ISpecification;
constructor(left: ISpecification, right: ISpecification) {
super();
this.leftCondition = left;
this.rightCondition = right;
}
isSatisfiedBy(candidate: unknown): boolean {
return this.leftCondition.isSatisfiedBy(candidate) && this.rightCondition.isSatisfiedBy(candidate);
}
}
class AndNotSpecification extends CompositeSpecification {
private leftCondition: ISpecification;
private rightCondition: ISpecification;
constructor(left: ISpecification, right: ISpecification) {
super();
this.leftCondition = left;
this.rightCondition = right;
}
isSatisfiedBy(candidate: unknown): boolean {
return this.leftCondition.isSatisfiedBy(candidate) && this.rightCondition.isSatisfiedBy(candidate) !== true;
}
}
class OrSpecification extends CompositeSpecification {
private leftCondition: ISpecification;
private rightCondition: ISpecification;
constructor(left: ISpecification, right: ISpecification) {
super();
this.leftCondition = left;
this.rightCondition = right;
}
isSatisfiedBy(candidate: unknown): boolean {
return this.leftCondition.isSatisfiedBy(candidate) || this.rightCondition.isSatisfiedBy(candidate);
}
}
class OrNotSpecification extends CompositeSpecification {
private leftCondition: ISpecification;
private rightCondition: ISpecification;
constructor(left: ISpecification, right: ISpecification) {
super();
this.leftCondition = left;
this.rightCondition = right;
}
isSatisfiedBy(candidate: unknown): boolean {
return this.leftCondition.isSatisfiedBy(candidate) || this.rightCondition.isSatisfiedBy(candidate) !== true;
}
}
class NotSpecification extends CompositeSpecification {
private wrapped: ISpecification;
constructor(spec: ISpecification) {
super();
this.wrapped = spec;
}
isSatisfiedBy(candidate: unknown): boolean {
return !this.wrapped.isSatisfiedBy(candidate);
}
}
|