fr.arakne.swflangloader.parser.mapper.ReflectionPropertyHydrator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 25
ccs 6
cts 10
cp 0.6
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get(T) 0 7 2
A ReflectionPropertyHydrator(Field) 0 4 1
A set(T,V) 0 6 2
1
/*
2
 * This file is part of ArakneLangLoader.
3
 *
4
 * ArakneLangLoader 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
 * ArakneLangLoader 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 ArakneLangLoader.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2020 Vincent Quatrevieux
18
 */
19
20
package fr.arakne.swflangloader.parser.mapper;
21
22
import java.lang.reflect.Field;
23
24
/**
25
 * Hydrator using reflection field
26
 */
27
final public class ReflectionPropertyHydrator<T, V> implements PropertyHydrator<T, V> {
28
    final private Field field;
29
30 1
    public ReflectionPropertyHydrator(Field field) {
31 1
        this.field = field;
32
33 1
        field.setAccessible(true);
34 1
    }
35
36
    @Override
37
    @SuppressWarnings("unchecked")
38
    public V get(T source) {
39
        try {
40 1
            return (V) field.get(source);
41
        } catch (IllegalAccessException e) {
42
            throw new RuntimeException(e); // Should not occurs
43
        }
44
    }
45
46
    @Override
47
    public void set(T target, V value) {
48
        try {
49 1
            field.set(target, value);
50
        } catch (IllegalAccessException e) {
51
            throw new RuntimeException(e); // Should not occurs
52 1
        }
53 1
    }
54
}
55