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

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A MapAssignationType(Type,Class) 0 3 1
A parseAssociative(String,String,String) 0 10 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;
21
22
import com.google.gson.Gson;
23
import com.google.gson.JsonSyntaxException;
24
25
import java.lang.reflect.Type;
26
27
/**
28
 * Map variable assignation
29
 */
30
final public class MapAssignationType implements AssignationType {
31 1
    final static private Gson GSON = new Gson();
32
33
    final private Type keyType;
34
    final private Class<?> type;
35
36 1
    public MapAssignationType(Type keyType, Class<?> type) {
37 1
        this.keyType = keyType;
38 1
        this.type = type;
39 1
    }
40
41
    @Override
42
    public Assignation parseAssociative(String varName, String key, String value) {
43
        try {
44 1
            return new Assignation(
45
                varName,
46 1
                GSON.fromJson(key, keyType),
47 1
                GSON.fromJson(value, type)
48
            );
49 1
        } catch (JsonSyntaxException e) {
50 1
            return Assignation.NULL;
51
        }
52
    }
53
}
54