update copyright
[reguloj.git] / src / main / java / wtf / metio / reguloj / JavaUtilFunctionRule.java
blob51443ed39e58ded8a4da9bb121eecea063cd2809
1 /*
2 * This file is part of reguloj. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of reguloj,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.reguloj;
10 import java.util.function.Consumer;
11 import java.util.function.Predicate;
13 /**
14 * Implementation of the {@link Rule} interface that uses the java.util.function package.
16 * @param <CONTEXT> The type of the context.
17 * @see java.util.function.Predicate
18 * @see java.util.function.Consumer
20 record JavaUtilFunctionRule<CONTEXT extends Context<?>>(
21 String name,
22 Predicate<CONTEXT> predicate,
23 Consumer<CONTEXT> consumer) implements Rule<CONTEXT> {
25 @Override
26 public void run(final CONTEXT context) {
27 if (fires(context)) {
28 consumer.accept(context);
32 @Override
33 public boolean fires(final CONTEXT context) {
34 return predicate.test(context);