X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fdemoscenemusic%2Fdata%2FProperties.java;h=3b72223824a7dd7edbac34f87fe18c9e678c5cf1;hb=f18bc73cc517d841045c0a133a491c6020602cd9;hp=dfdb83619466c74544cf8d2528dbb28c96152d4a;hpb=0dba6059126d63506663488f7f0f5bacd9a91e0f;p=demoscenemusic.git diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/Properties.java b/src/main/java/net/pterodactylus/demoscenemusic/data/Properties.java index dfdb836..3b72223 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/Properties.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/Properties.java @@ -33,6 +33,9 @@ public class Properties implements Iterable> { /** The properties. */ private final Map properties = new HashMap(); + /** The “dirty” flag. */ + private boolean dirty = false; + // // ACCESSORS // @@ -59,6 +62,9 @@ public class Properties implements Iterable> { * @return These properties */ public Properties set(String property, String value) { + if (!properties.containsKey(property) || (((value != null) && (!value.equals(properties.get(property))) || ((value == null) && (properties.get(property) != null))))) { + dirty = true; + } properties.put(property, value); return this; } @@ -71,6 +77,9 @@ public class Properties implements Iterable> { * @return These properties */ public Properties remove(String property) { + if (properties.containsKey(property)) { + dirty = true; + } properties.remove(property); return this; } @@ -81,10 +90,34 @@ public class Properties implements Iterable> { * @return These properties */ public Properties removeAll() { + if (!properties.isEmpty()) { + dirty = true; + } properties.clear(); return this; } + /** + * Returns whether these properties have been modified. + * + * @return {@code true} if the properties have been modified since they were + * created or the last time {@link #resetDirty()} was called, + * {@code false} if they have not been modified + */ + public boolean isDirty() { + return dirty; + } + + /** + * Resets the dirty flag. + * + * @return These properties + */ + public Properties resetDirty() { + dirty = false; + return this; + } + // // ITERABLE METHODS //