mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-16 14:25:02 -05:00
Rewrite FilePreferences
This commit is contained in:
parent
a545c6d727
commit
bedbeb6384
@ -19,6 +19,7 @@ import java.util.Properties;
|
|||||||
public class PropertyFileBackingStore {
|
public class PropertyFileBackingStore {
|
||||||
|
|
||||||
private Path store;
|
private Path store;
|
||||||
|
private int modCount = 0;
|
||||||
|
|
||||||
private Map<String, Map<String, String>> nodes = new HashMap<String, Map<String, String>>();
|
private Map<String, Map<String, String>> nodes = new HashMap<String, Map<String, String>>();
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ public class PropertyFileBackingStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String setValue(String node, String key, String value) {
|
public synchronized String setValue(String node, String key, String value) {
|
||||||
|
modCount++;
|
||||||
return nodes.computeIfAbsent(node, this::newKeyValueMap).put(key, value);
|
return nodes.computeIfAbsent(node, this::newKeyValueMap).put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,11 +47,13 @@ public class PropertyFileBackingStore {
|
|||||||
public synchronized void removeValue(String node, String key) {
|
public synchronized void removeValue(String node, String key) {
|
||||||
Map<String, String> values = nodes.get(node);
|
Map<String, String> values = nodes.get(node);
|
||||||
if (values != null) {
|
if (values != null) {
|
||||||
|
modCount++;
|
||||||
values.remove(key);
|
values.remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void removeNode(String node) {
|
public synchronized void removeNode(String node) {
|
||||||
|
modCount++;
|
||||||
nodes.remove(node);
|
nodes.remove(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +119,10 @@ public class PropertyFileBackingStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
|
if (modCount == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
StringWriter buffer = new StringWriter();
|
StringWriter buffer = new StringWriter();
|
||||||
toProperties().store(buffer, null);
|
toProperties().store(buffer, null);
|
||||||
|
|
||||||
@ -126,6 +134,8 @@ public class PropertyFileBackingStore {
|
|||||||
out.truncate(out.position());
|
out.truncate(out.position());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modCount = 0; // reset
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user