fr.quatrevieux.araknemu.data.living.constraint.ValueCheck   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkValue(V) 0 3 1
Checker.check(V) 0 1 ?
A ValueCheck(E,Getter,Checker) 0 3 1
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.data.living.constraint;
21
22
import org.checkerframework.checker.nullness.qual.NonNull;
23
24
/**
25
 * Check value using lambda
26
 *
27
 * @param <T> The entity type
28
 * @param <E> The error type
29
 * @param <V> The value type
30
 */
31
public final class ValueCheck<T, @NonNull E, V> extends AbstractValueConstraint<T, E, V> {
32
    private final Checker<V> checker;
33
34
    public ValueCheck(@NonNull E error, Getter<T, V> getter, Checker<V> checker) {
35 1
        super(error, getter);
36 1
        this.checker = checker;
37 1
    }
38
39
    @Override
40
    protected boolean checkValue(V value) {
41 1
        return checker.check(value);
42
    }
43
44
    @FunctionalInterface
45
    public interface Checker<V> {
46
        public boolean check(V value);
47
    }
48
}
49