blob: 32f31e32be6bfc39b64bc905c4b812177c838fd4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package cuchaz.enigma;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import cuchaz.enigma.api.service.EnigmaServiceType;
import cuchaz.enigma.translation.mapping.MappingFileNameFormat;
import cuchaz.enigma.translation.mapping.MappingSaveParameters;
import javax.annotation.Nullable;
import java.io.Reader;
import java.util.Map;
import java.util.Optional;
public final class EnigmaProfile {
public static final EnigmaProfile EMPTY = new EnigmaProfile(ImmutableMap.of());
private static final MappingSaveParameters DEFAULT_MAPPING_SAVE_PARAMETERS = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF);
private static final Gson GSON = new Gson();
@SerializedName("services")
private final Map<String, Service> serviceProfiles;
@SerializedName("mapping_save_parameters")
private final MappingSaveParameters mappingSaveParameters = null;
private EnigmaProfile(Map<String, Service> serviceProfiles) {
this.serviceProfiles = serviceProfiles;
}
public static EnigmaProfile parse(Reader reader) {
return GSON.fromJson(reader, EnigmaProfile.class);
}
@Nullable
public Service getServiceProfile(EnigmaServiceType<?> serviceType) {
return serviceProfiles.get(serviceType.key);
}
public MappingSaveParameters getMappingSaveParameters() {
//noinspection ConstantConditions
return mappingSaveParameters == null ? EnigmaProfile.DEFAULT_MAPPING_SAVE_PARAMETERS : mappingSaveParameters;
}
public static class Service {
private final String id;
private final Map<String, String> args;
Service(String id, Map<String, String> args) {
this.id = id;
this.args = args;
}
public boolean matches(String id) {
return this.id.equals(id);
}
public Optional<String> getArgument(String key) {
return args != null ? Optional.ofNullable(args.get(key)) : Optional.empty();
}
}
}
|