diff options
| author | 2019-06-19 18:51:31 +0100 | |
|---|---|---|
| committer | 2019-06-19 18:51:31 +0100 | |
| commit | 546c617598b10c341fe6549678803f6ac0c95619 (patch) | |
| tree | d818bcebf7634ed5b716ee29619725fdc29a04e8 /src/main/java/cuchaz/enigma/EnigmaProfile.java | |
| parent | fix unwanted declaration navigation during Quick Find (diff) | |
| parent | Parse profile json from cli args (diff) | |
| download | enigma-fork-546c617598b10c341fe6549678803f6ac0c95619.tar.gz enigma-fork-546c617598b10c341fe6549678803f6ac0c95619.tar.xz enigma-fork-546c617598b10c341fe6549678803f6ac0c95619.zip | |
Merge pull request #135 from gegy1000/proposal-tweak
Plugin rework
Diffstat (limited to 'src/main/java/cuchaz/enigma/EnigmaProfile.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/EnigmaProfile.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/EnigmaProfile.java b/src/main/java/cuchaz/enigma/EnigmaProfile.java new file mode 100644 index 0000000..9dc5ff2 --- /dev/null +++ b/src/main/java/cuchaz/enigma/EnigmaProfile.java | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | package cuchaz.enigma; | ||
| 2 | |||
| 3 | import com.google.common.collect.ImmutableMap; | ||
| 4 | import com.google.gson.Gson; | ||
| 5 | import com.google.gson.annotations.SerializedName; | ||
| 6 | import cuchaz.enigma.api.service.EnigmaServiceType; | ||
| 7 | |||
| 8 | import javax.annotation.Nullable; | ||
| 9 | import java.io.Reader; | ||
| 10 | import java.util.Map; | ||
| 11 | import java.util.Optional; | ||
| 12 | |||
| 13 | public final class EnigmaProfile { | ||
| 14 | public static final EnigmaProfile EMPTY = new EnigmaProfile(ImmutableMap.of()); | ||
| 15 | |||
| 16 | private static final Gson GSON = new Gson(); | ||
| 17 | |||
| 18 | @SerializedName("services") | ||
| 19 | private final Map<String, Service> serviceProfiles; | ||
| 20 | |||
| 21 | private EnigmaProfile(Map<String, Service> serviceProfiles) { | ||
| 22 | this.serviceProfiles = serviceProfiles; | ||
| 23 | } | ||
| 24 | |||
| 25 | public static EnigmaProfile parse(Reader reader) { | ||
| 26 | return GSON.fromJson(reader, EnigmaProfile.class); | ||
| 27 | } | ||
| 28 | |||
| 29 | @Nullable | ||
| 30 | public Service getServiceProfile(EnigmaServiceType<?> serviceType) { | ||
| 31 | return serviceProfiles.get(serviceType.key); | ||
| 32 | } | ||
| 33 | |||
| 34 | public static class Service { | ||
| 35 | private final String id; | ||
| 36 | private final Map<String, String> args; | ||
| 37 | |||
| 38 | Service(String id, Map<String, String> args) { | ||
| 39 | this.id = id; | ||
| 40 | this.args = args; | ||
| 41 | } | ||
| 42 | |||
| 43 | public boolean matches(String id) { | ||
| 44 | return this.id.equals(id); | ||
| 45 | } | ||
| 46 | |||
| 47 | public Optional<String> getArgument(String key) { | ||
| 48 | return Optional.ofNullable(args.get(key)); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||