import {predicate, predicateFn} from "../Interface"; import {Optional} from "./Optional"; import {Objects} from "../type/Objects"; import {Deprecate} from "../annotation/Deprecate"; /**** * @package lib-utils-ts.src * @class Predication * @interface predicate */ export class Predication implements predicate{ @Deprecate.Deprecated public test: predicateFn; /*** * * @param other */ public and?( other : predicate ) : predicate{ Objects.requireNotNull(other,"Predication [ other ] argument is null !"); let predication: predicateFn = (value)=> this.test(value)&& Optional.ofNullable>(other.test).orElse(()=>false).call(other,value); return new class extends Predication implements predicate{ /**@override**/ public test: predicateFn = predication; }; } /*** * * @param other */ public or?( other : predicate ) : predicate{ Objects.requireNotNull(other,"Predication [ other ] argument is null !"); let predication : predicateFn = (value:T) => this.test(value)||Optional.ofNullable>(other.test).orElse(()=>false).call(other,value); return new class extends Predication implements predicate{ /**@override**/ public test: predicateFn = predication; } } /*** * */ public negate?(): predicate {return Predication.of((value:T)=> !this.test(value));} /*** * @method isEqual * @param object */ public static isEqual(object: Object): predicate { let p: predicate = new Predication(); p.test = object===null? Objects.isNull : (value:T)=> value.equals(object); return p; } /*** * @static of * @param test */ public static of( test: predicateFn|Predication ): predicate { if(test instanceof Predication) return test; return new class Predicate extends Predication implements predicate{ /**@ts-ignore**/ public test: predicateFn = test; }; } } Object.package(this);