|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Expressif.Predicates.Operators; |
| 7 | + |
| 8 | +namespace Expressif.Predicates; |
| 9 | +public class PredicateCombiner |
| 10 | +{ |
| 11 | + protected UnaryOperatorFactory UnaryFactory { get; } |
| 12 | + protected BinaryOperatorFactory BinaryFactory { get; } |
| 13 | + |
| 14 | + public PredicateCombiner() |
| 15 | + : this(new(), new()) { } |
| 16 | + |
| 17 | + public PredicateCombiner(UnaryOperatorFactory unaryFactory , BinaryOperatorFactory binaryFactory) |
| 18 | + => (UnaryFactory, BinaryFactory) = (unaryFactory, binaryFactory); |
| 19 | + |
| 20 | + public PredicateRightCombiner With(IPredicate left) |
| 21 | + => new(UnaryFactory, BinaryFactory, left); |
| 22 | + |
| 23 | + public PredicateRightCombiner WithNot(IPredicate left) |
| 24 | + => new(UnaryFactory, BinaryFactory, UnaryFactory.Instantiate("!", left)); |
| 25 | + |
| 26 | + public class PredicateRightCombiner |
| 27 | + { |
| 28 | + protected UnaryOperatorFactory UnaryFactory { get; } |
| 29 | + protected BinaryOperatorFactory BinaryFactory { get; } |
| 30 | + private IPredicate State { get; } |
| 31 | + |
| 32 | + internal PredicateRightCombiner(UnaryOperatorFactory unaryFactory, BinaryOperatorFactory binaryFactory, IPredicate state) |
| 33 | + => (UnaryFactory, BinaryFactory, State) = (unaryFactory, binaryFactory, state); |
| 34 | + |
| 35 | + public PredicateRightCombiner Or(IPredicate right) |
| 36 | + => new(UnaryFactory, BinaryFactory, BinaryFactory.Instantiate("OR", State, right)); |
| 37 | + |
| 38 | + public PredicateRightCombiner OrNot(IPredicate right) |
| 39 | + => Or(UnaryFactory.Instantiate("!", right)); |
| 40 | + |
| 41 | + public PredicateRightCombiner And(IPredicate right) |
| 42 | + => new(UnaryFactory, BinaryFactory, BinaryFactory.Instantiate("AND", State, right)); |
| 43 | + |
| 44 | + public PredicateRightCombiner AndNot(IPredicate right) |
| 45 | + => And(UnaryFactory.Instantiate("!", right)); |
| 46 | + |
| 47 | + public PredicateRightCombiner Xor(IPredicate right) |
| 48 | + => new(UnaryFactory, BinaryFactory, BinaryFactory.Instantiate("XOR", State, right)); |
| 49 | + |
| 50 | + public PredicateRightCombiner XorNot(IPredicate right) |
| 51 | + => Xor(UnaryFactory.Instantiate("!", right)); |
| 52 | + |
| 53 | + public IPredicate Build() |
| 54 | + => State!; |
| 55 | + } |
| 56 | +} |
0 commit comments