diff --git a/desktop/src/main/java/io/github/krlvm/powertunnel/desktop/configuration/AdvancedConfiguration.java b/desktop/src/main/java/io/github/krlvm/powertunnel/desktop/configuration/AdvancedConfiguration.java index 63dec06e..e0ed03bb 100644 --- a/desktop/src/main/java/io/github/krlvm/powertunnel/desktop/configuration/AdvancedConfiguration.java +++ b/desktop/src/main/java/io/github/krlvm/powertunnel/desktop/configuration/AdvancedConfiguration.java @@ -19,48 +19,52 @@ import io.github.krlvm.powertunnel.configuration.ConfigurationStore; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; public class AdvancedConfiguration extends ConfigurationStore { - private final Collection immutableKeys; + private final Collection immutableKeys = new HashSet<>(); + private final Map preImmutableData = new HashMap<>(); - public AdvancedConfiguration() { - this(new ArrayList<>()); - } - - public AdvancedConfiguration(Collection immutableKeys) { - this.immutableKeys = immutableKeys; - } - - public void protect(String key) { - this.immutableKeys.add(key); + private void saveOriginalKey(String key) { + String originalVal = get(key, null); + if (originalVal != null) { + preImmutableData.put(key, originalVal); + } } public void protect(String key, String value) { this.immutableKeys.add(key); + saveOriginalKey(key); set(key, value); } public void protectInt(String key, int value) { this.immutableKeys.add(key); + saveOriginalKey(key); setInt(key, value); } public void protectBoolean(String key, boolean value) { this.immutableKeys.add(key); + saveOriginalKey(key); setBoolean(key, value); } @Override protected Set> entries() { - return super.entries().stream() - .filter(entry -> !immutableKeys.contains(entry.getKey())) - .collect(Collectors.toSet()); + Set> entries = new HashSet<>(); + + for (Map.Entry entry : super.entries()) { + if (immutableKeys.contains(entry.getKey())) { + if (!preImmutableData.containsKey(entry.getKey())) continue; + entry = new AbstractMap.SimpleEntry<>(entry.getKey(), preImmutableData.get(entry.getKey())); + } + entries.add(entry); + } + + return entries; } public Collection getImmutableKeys() {