diff options
| author | 2019-06-16 23:49:25 +0200 | |
|---|---|---|
| committer | 2019-06-16 23:49:25 +0200 | |
| commit | e27d5967029f4f3da8889dd673ba516dcd9f3ac8 (patch) | |
| tree | 71c98afad01cafdb2884da288e494e8761c2a8ff /src/main/java/cuchaz/enigma/EnigmaProfile.java | |
| parent | Merge remote-tracking branch 'origin/master' into proposal-tweak (diff) | |
| download | enigma-fork-e27d5967029f4f3da8889dd673ba516dcd9f3ac8.tar.gz enigma-fork-e27d5967029f4f3da8889dd673ba516dcd9f3ac8.tar.xz enigma-fork-e27d5967029f4f3da8889dd673ba516dcd9f3ac8.zip | |
Plugin rework along with API rework: Enigma split from EnigmaProject; plugins now provide services configurable via a profile
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 | } | ||