fr.arakne.swflangloader.lang.JsonMapGetter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 58
ccs 4
cts 4
cp 1
rs 10
wmc 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
json(String) 0 1 ?
A integer(String) 0 2 1
A string(String) 0 2 1
A bool(String) 0 2 1
A decimal(String) 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.lang;
21
22
import com.google.gson.JsonElement;
23
24
import java.util.Optional;
25
26
/**
27
 * Get a JSON value from the swf structure
28
 */
29
public interface JsonMapGetter {
30
    /**
31
     * Get a string lang value
32
     *
33
     * @param variable The variable name
34
     *
35
     * @return The lang value as string
36
     * @throws java.util.NoSuchElementException When variable is not found
37
     */
38
    default public String string(String variable) {
39 1
        return Optional.ofNullable(json(variable)).map(JsonElement::getAsString).orElse(null);
40
    }
41
42
    /**
43
     * Get a integer lang value
44
     *
45
     * @param variable The variable name
46
     *
47
     * @return The lang value as integer
48
     * @throws java.util.NoSuchElementException When variable is not found
49
     */
50
    default public int integer(String variable) {
51 1
        return json(variable).getAsInt();
52
    }
53
54
    /**
55
     * Get a decimal lang value
56
     *
57
     * @param variable The variable name
58
     *
59
     * @return The lang value as double
60
     * @throws java.util.NoSuchElementException When variable is not found
61
     */
62
    default public double decimal(String variable) {
63 1
        return json(variable).getAsDouble();
64
    }
65
66
    /**
67
     * Get a boolean lang value
68
     *
69
     * @param variable The variable name
70
     *
71
     * @return The lang value as boolean
72
     * @throws java.util.NoSuchElementException When variable is not found
73
     */
74
    default public boolean bool(String variable) {
75 1
        return json(variable).getAsBoolean();
76
    }
77
78
    /**
79
     * Get a raw JSON element value
80
     *
81
     * @param variable The variable name
82
     *
83
     * @return The variable value
84
     * @throws java.util.NoSuchElementException When variable is not found
85
     */
86
    public JsonElement json(String variable);
87
}
88