X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fdemoscenemusic%2Fdata%2FProperties.java;h=74bf52461d7414461e201f800f54cfd7d6ae4d32;hb=ab171583f8680b47b35699bacafb6a1f65563571;hp=dfdb83619466c74544cf8d2528dbb28c96152d4a;hpb=6824ff7746ed9f1d6d7b68d24d3d02686f2218ac;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..74bf524 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/Properties.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/Properties.java @@ -17,10 +17,10 @@ package net.pterodactylus.demoscenemusic.data; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; /** * Container for custom properties that can be attached to all data containers. @@ -31,7 +31,10 @@ import java.util.Map.Entry; public class Properties implements Iterable> { /** The properties. */ - private final Map properties = new HashMap(); + private final Map properties = new TreeMap(); + + /** 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 //