fr.arakne.swflangloader.parser.SimpleAssignationType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 15
ccs 5
cts 7
cp 0.7143
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseSimple(String,String) 0 6 2
A SimpleAssignationType(Class) 0 2 1
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;
21
22
import com.google.gson.Gson;
23
import com.google.gson.JsonSyntaxException;
24
25
/**
26
 * Simple variable assignation
27
 */
28
final public class SimpleAssignationType implements AssignationType {
29 1
    final static private Gson GSON = new Gson();
30
31
    final private Class<?> type;
32
33 1
    public SimpleAssignationType(Class<?> type) {
34 1
        this.type = type;
35 1
    }
36
37
    @Override
38
    public Assignation parseSimple(String varName, String value) {
39
        try {
40 1
            return Assignation.simple(varName, GSON.fromJson(value, type));
41
        } catch (JsonSyntaxException e) {
42
            return Assignation.NULL;
43
        }
44
    }
45
}
46