UNPKG

arch-unit-ts

Version:
52 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConditionAggregator = void 0; const Optional_1 = require("../../../common/domain/Optional"); const Assert_1 = require("../../../error/domain/Assert"); class ConditionAggregator { addMode; condition; constructor(addMode, condition) { Assert_1.Assert.notNullOrUndefined('addMode', addMode); this.addMode = addMode; this.condition = condition; } static default() { return new ConditionAggregator(AddMode.and(), Optional_1.Optional.empty()); } getCondition() { return this.condition; } add(other) { return new ConditionAggregator(this.addMode, Optional_1.Optional.of(this.addMode.apply(this.condition, other))); } thatANDs() { return new ConditionAggregator(AddMode.and(), this.condition); } thatORs() { return new ConditionAggregator(AddMode.or(), this.condition); } getDescription() { return this.condition.map(condition => condition.description).orElse('(empty condition)'); } } exports.ConditionAggregator = ConditionAggregator; class AddMode { static and() { return new AndMode(); } static or() { return new OrMode(); } } class AndMode extends AddMode { apply(first, other) { return first.isPresent() ? first.orElseThrow().and(other) : other; } } class OrMode extends AddMode { apply(first, other) { return first.isPresent() ? first.orElseThrow().or(other) : other; } } //# sourceMappingURL=ConditionAggregator.js.map