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
) {
15 this.predicate
= predicate
;
16 this.consumer
= consumer
;
20 public void run(final CONTEXT context
) {
22 consumer
.accept(context
);
27 public boolean fires(final CONTEXT context
) {
28 return predicate
.test(context
);
32 public String
getName() {
37 public int hashCode() {
38 return Objects
.hash(name
, predicate
, consumer
);
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
);