de.pewpewproject.lasertag.lasertaggame.state.server.implementation.SettingsPresetsState   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromJson(String) 0 5 1
A toJson() 0 1 1
A createNewPresetsMap() 0 8 1
1
package de.pewpewproject.lasertag.lasertaggame.state.server.implementation;
2
3
import com.google.gson.Gson;
4
import com.google.gson.GsonBuilder;
5
import com.google.gson.ToNumberPolicy;
6
import de.pewpewproject.lasertag.lasertaggame.state.synced.implementation.SettingsState;
7
8
import java.util.HashMap;
9
10
/**
11
 * State resembling the presets currently saved by the player
12
 *
13
 * @author Étienne Muser
14
 */
15
public class SettingsPresetsState extends HashMap<String, SettingsState> {
16
17
    public static SettingsPresetsState createNewPresetsMap() {
18
19
        var presetsMap = new SettingsPresetsState();
20
21
        // Put default presets
22
        presetsMap.put("default", SettingsState.createBaseSettings());
23
24
        return presetsMap;
25
    }
26
27
    public static SettingsPresetsState fromJson(String json) {
28
        return new GsonBuilder()
29
                .setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
30
                .create()
31
                .fromJson(json, SettingsPresetsState.class);
32
    }
33
34
    public String toJson() { return new Gson().toJson(this); }
35
}
36