WIP: dependency updates
[reguloj.git] / src / main / java / wtf / metio / reguloj / RuleImplementation.java
blob6a1bc7009aec3148daf0313a4f93390e831867f5
1 package wtf.metio.reguloj;
3 import java.util.Objects;
4 import java.util.function.Consumer;
5 import java.util.function.Predicate;
7 final class RuleImplementation<CONTEXT extends Context<?>> implements Rule<CONTEXT> {
9 private final String name;
10 private final Predicate<CONTEXT> predicate;
11 private final Consumer<CONTEXT> consumer;
13 RuleImplementation(final String name, final Predicate<CONTEXT> predicate, final Consumer<CONTEXT> consumer) {
14 this.name = name;
15 this.predicate = predicate;
16 this.consumer = consumer;
19 @Override
20 public void run(final CONTEXT context) {
21 if (fires(context)) {
22 consumer.accept(context);
26 @Override
27 public boolean fires(final CONTEXT context) {
28 return predicate.test(context);
31 @Override
32 public String getName() {
33 return name;
36 @Override
37 public int hashCode() {
38 return Objects.hash(name, predicate, consumer);
41 @Override
42 public boolean equals(final Object object) {
43 if (object instanceof RuleImplementation) {
44 final RuleImplementation<?> that = (RuleImplementation<?>) object;
46 return Objects.equals(name, that.name) && Objects.equals(predicate, that.predicate)
47 && Objects.equals(consumer, that.consumer);
49 return false;