diff --git a/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyDataSet.java b/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyDataSet.java deleted file mode 100644 index d9a8c83bb..000000000 --- a/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyDataSet.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.gmail.nossr50.datatypes.dirtydata; - -import com.gmail.nossr50.datatypes.mutableprimitives.MutableBoolean; -import com.google.common.base.Objects; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.stream.Stream; - -public class DirtyDataSet { - - private final @NotNull MutableBoolean dirtyFlag; //Can be pointed at a reference - private @NotNull Set dataSet; - - public DirtyDataSet(@NotNull Set data, @NotNull MutableBoolean referenceFlag) { - this.dataSet = data; - this.dirtyFlag = referenceFlag; - } - - public boolean isDirty() { - return dirtyFlag.getImmutableCopy(); - } - - private void setDirty() { - dirtyFlag.setBoolean(true); - } - - public void setData(@NotNull Set dataSet) { - this.dataSet = dataSet; - setDirty(); - } - - public @NotNull Set getDataSet() { - setDirty(); - return dataSet; - } - - /* Set Interface Delegates */ - - public int size() { - return dataSet.size(); - } - - public boolean isEmpty() { - return dataSet.isEmpty(); - } - - public boolean contains(Object o) { - return dataSet.contains(o); - } - - public Iterator iterator() { - return dataSet.iterator(); - } - - public Object[] toArray() { - return dataSet.toArray(); - } - - public T[] toArray(@NotNull T[] ts) { - return dataSet.toArray(ts); - } - - public boolean add(E e) { - return dataSet.add(e); - } - - public boolean remove(Object o) { - return dataSet.remove(o); - } - - public boolean containsAll(@NotNull Collection collection) { - return dataSet.containsAll(collection); - } - - public boolean addAll(@NotNull Collection collection) { - return dataSet.addAll(collection); - } - - public boolean retainAll(@NotNull Collection collection) { - return dataSet.retainAll(collection); - } - - public boolean removeAll(@NotNull Collection collection) { - return dataSet.removeAll(collection); - } - - public void clear() { - dataSet.clear(); - } - - public Spliterator spliterator() { - return dataSet.spliterator(); - } - - public boolean removeIf(Predicate filter) { - return dataSet.removeIf(filter); - } - - public Stream stream() { - return dataSet.stream(); - } - - public Stream parallelStream() { - return dataSet.parallelStream(); - } - - public void forEach(Consumer action) { - dataSet.forEach(action); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - DirtyDataSet that = (DirtyDataSet) o; - return Objects.equal(getDataSet(), that.getDataSet()); - } - - @Override - public int hashCode() { - return Objects.hashCode(getDataSet()); - } -} diff --git a/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyMap.java b/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyMap.java index 1b3cd175f..d5e04ad37 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyMap.java +++ b/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtyMap.java @@ -54,10 +54,12 @@ public class DirtyMap implements Map { return map.get(key); } + @Override public int size() { return map.size(); } + @Override public boolean isEmpty() { return map.isEmpty(); } @@ -72,21 +74,25 @@ public class DirtyMap implements Map { return map.containsValue(value); } + @Override public V put(K key, V value) { setDirty(); return map.put(key, value); } + @Override public V remove(Object key) { setDirty(); return map.remove(key); } + @Override public void putAll(@NotNull Map m) { setDirty(); map.putAll(m); } + @Override public void clear() { setDirty(); map.clear(); diff --git a/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtySet.java b/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtySet.java new file mode 100644 index 000000000..f3b670d17 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/dirtydata/DirtySet.java @@ -0,0 +1,164 @@ +package com.gmail.nossr50.datatypes.dirtydata; + +import com.gmail.nossr50.datatypes.mutableprimitives.MutableBoolean; +import com.google.common.base.Objects; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class DirtySet implements Set { + + private final @NotNull MutableBoolean dirtyFlag; //Can be pointed at a reference + private @NotNull Set set; + + public DirtySet(@NotNull Set data, @NotNull MutableBoolean referenceFlag) { + this.set = data; + this.dirtyFlag = referenceFlag; + } + + public boolean isDirty() { + return dirtyFlag.getImmutableCopy(); + } + + private void setDirty() { + dirtyFlag.setBoolean(true); + } + + /** + * Assign the inner wrapped set to a new value + * @param dataSet the new value to assign the inner wrapped set + */ + public void setSet(@NotNull Set dataSet) { + this.set = dataSet; + setDirty(); + } + + /** + * Get the wrapped set of this DirtySet + * @return the inner wrapped Set of this DirtySet + */ + public @NotNull Set unwrapSet() { + setDirty(); + return set; + } + + /* Set Interface Delegates */ + + @Override + public int size() { + return set.size(); + } + + @Override + public boolean isEmpty() { + return set.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return set.contains(o); + } + + @Override + public @NotNull Iterator iterator() { + return set.iterator(); + } + + @Override + public Object[] toArray() { + return set.toArray(); + } + + @Override + public T[] toArray(@NotNull T[] ts) { + return set.toArray(ts); + } + + @Override + public boolean add(E e) { + setDirty(); + return set.add(e); + } + + @Override + public boolean remove(Object o) { + setDirty(); + return set.remove(o); + } + + @Override + public boolean containsAll(@NotNull Collection collection) { + return set.containsAll(collection); + } + + @Override + public boolean addAll(@NotNull Collection collection) { + setDirty(); + return set.addAll(collection); + } + + @Override + public boolean retainAll(@NotNull Collection collection) { + setDirty(); + return set.retainAll(collection); + } + + @Override + public boolean removeAll(@NotNull Collection collection) { + setDirty(); + return set.removeAll(collection); + } + + @Override + public void clear() { + setDirty(); + set.clear(); + } + + @Override + public Spliterator spliterator() { + setDirty(); + return set.spliterator(); + } + + @Override + public boolean removeIf(Predicate filter) { + return set.removeIf(filter); + } + + @Override + public Stream stream() { + return set.stream(); + } + + @Override + public Stream parallelStream() { + return set.parallelStream(); + } + + @Override + public void forEach(Consumer action) { + set.forEach(action); + } + + /* Equals & Hash Overrides */ + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DirtySet dirtySet = (DirtySet) o; + return Objects.equal(set, dirtySet.set); + } + + @Override + public int hashCode() { + return Objects.hashCode(set); + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/PersistentPartyData.java b/src/main/java/com/gmail/nossr50/datatypes/party/PersistentPartyData.java index 113cdb4ec..1d5f26b6f 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/PersistentPartyData.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/PersistentPartyData.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.datatypes.party; import com.gmail.nossr50.datatypes.dirtydata.DirtyData; -import com.gmail.nossr50.datatypes.dirtydata.DirtyDataSet; +import com.gmail.nossr50.datatypes.dirtydata.DirtySet; import com.gmail.nossr50.datatypes.mutableprimitives.MutableBoolean; import com.gmail.nossr50.datatypes.mutableprimitives.MutableString; import com.google.common.base.Objects; @@ -14,13 +14,13 @@ public class PersistentPartyData { private final @NotNull MutableBoolean dirtyFlag; //Dirty values in this class will change this flag as needed private final @NotNull DirtyData partyName; - private final @NotNull DirtyDataSet partyMembers; //TODO: Add cache for subsets + private final @NotNull DirtySet partyMembers; //TODO: Add cache for subsets public PersistentPartyData(@NotNull String partyName, @NotNull Set partyMembers) { dirtyFlag = new MutableBoolean(false); this.partyName = new DirtyData<>(new MutableString(partyName), dirtyFlag); - this.partyMembers = new DirtyDataSet<>(new HashSet<>(partyMembers), dirtyFlag); + this.partyMembers = new DirtySet<>(new HashSet<>(partyMembers), dirtyFlag); } public String getPartyName() { @@ -28,7 +28,7 @@ public class PersistentPartyData { } public Set getPartyMembers() { - return partyMembers.getDataSet(); + return partyMembers; } public boolean isDataDirty() { diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java b/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java index 2fdccdd54..f430b565e 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/PersistentPlayerData.java @@ -5,7 +5,7 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.MobHealthBarType; import com.gmail.nossr50.datatypes.dirtydata.DirtyData; -import com.gmail.nossr50.datatypes.dirtydata.DirtyDataMap; +import com.gmail.nossr50.datatypes.dirtydata.DirtyMap; import com.gmail.nossr50.datatypes.mutableprimitives.MutableBoolean; import com.gmail.nossr50.datatypes.mutableprimitives.MutableInteger; import com.gmail.nossr50.datatypes.mutableprimitives.MutableLong; @@ -38,11 +38,11 @@ public class PersistentPlayerData { private final @NotNull DirtyData mobHealthBarType; /* Skill Data */ - private final @NotNull DirtyDataMap skillLevelValues; - private final @NotNull DirtyDataMap skillExperienceValues; - private final @NotNull DirtyDataMap abilityDeactivationTimestamps; // Ability & Cooldown - private final @NotNull DirtyDataMap uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..) - private final @NotNull DirtyDataMap barStateMap; + private final @NotNull DirtyMap skillLevelValues; + private final @NotNull DirtyMap skillExperienceValues; + private final @NotNull DirtyMap abilityDeactivationTimestamps; // Ability & Cooldown + private final @NotNull DirtyMap uniquePlayerData; //Misc data that doesn't fit into other categories (chimaera wing, etc..) + private final @NotNull DirtyMap barStateMap; /* Special Flags */ private final @NotNull DirtyData partyChatSpying; @@ -66,10 +66,10 @@ public class PersistentPlayerData { this.playerUUID = playerUUID; this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag); - this.skillLevelValues = new DirtyDataMap<>(new EnumMap<>(PrimarySkillType.class), dirtyFlag); - this.skillExperienceValues = new DirtyDataMap<>(new EnumMap<>(PrimarySkillType.class), dirtyFlag); - this.abilityDeactivationTimestamps = new DirtyDataMap<>(new EnumMap<>(SuperAbilityType.class), dirtyFlag); - this.uniquePlayerData = new DirtyDataMap<>(new EnumMap<>(UniqueDataType.class), dirtyFlag); + this.skillLevelValues = new DirtyMap<>(new EnumMap<>(PrimarySkillType.class), dirtyFlag); + this.skillExperienceValues = new DirtyMap<>(new EnumMap<>(PrimarySkillType.class), dirtyFlag); + this.abilityDeactivationTimestamps = new DirtyMap<>(new EnumMap<>(SuperAbilityType.class), dirtyFlag); + this.uniquePlayerData = new DirtyMap<>(new EnumMap<>(UniqueDataType.class), dirtyFlag); this.mobHealthBarType = new DirtyData<>(Config.getInstance().getMobHealthbarDefault(), dirtyFlag); this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(0), dirtyFlag); @@ -88,7 +88,7 @@ public class PersistentPlayerData { this.partyChatSpying = new DirtyData<>(new MutableBoolean(false), dirtyFlag); - this.barStateMap = new DirtyDataMap<>(MMOExperienceBarManager.generateDefaultBarStateMap(), dirtyFlag); + this.barStateMap = new DirtyMap<>(MMOExperienceBarManager.generateDefaultBarStateMap(), dirtyFlag); this.lastLogin = new DirtyData<>(new MutableLong(0), dirtyFlag); //Value of 0 will represent that the user hasn't been seen online this.leaderBoardExclusion = new DirtyData<>(new MutableBoolean(false), dirtyFlag); } @@ -128,22 +128,22 @@ public class PersistentPlayerData { this.dirtyFlag = new MutableBoolean(false); //Set this one first validateMap(skillLevelValues); - this.skillLevelValues = new DirtyDataMap<>(skillLevelValues, dirtyFlag); + this.skillLevelValues = new DirtyMap<>(skillLevelValues, dirtyFlag); validateMap(skillExperienceValues); - this.skillExperienceValues = new DirtyDataMap<>(skillExperienceValues, dirtyFlag); + this.skillExperienceValues = new DirtyMap<>(skillExperienceValues, dirtyFlag); validateMap(abilityDeactivationTimestamps); - this.abilityDeactivationTimestamps = new DirtyDataMap<>(abilityDeactivationTimestamps, dirtyFlag); + this.abilityDeactivationTimestamps = new DirtyMap<>(abilityDeactivationTimestamps, dirtyFlag); - this.uniquePlayerData = new DirtyDataMap<>(uniquePlayerData, dirtyFlag); + this.uniquePlayerData = new DirtyMap<>(uniquePlayerData, dirtyFlag); this.scoreboardTipsShown = new DirtyData<>(new MutableInteger(scoreboardTipsShown), dirtyFlag); this.mobHealthBarType = new DirtyData<>(mobHealthBarType, dirtyFlag); this.playerUUID = playerUUID; this.playerName = new DirtyData<>(new MutableString(playerName), dirtyFlag); - this.barStateMap = new DirtyDataMap<>(barStateMap, dirtyFlag); + this.barStateMap = new DirtyMap<>(barStateMap, dirtyFlag); this.partyChatSpying = new DirtyData<>(new MutableBoolean(partyChatSpying), dirtyFlag); this.lastLogin = new DirtyData<>(new MutableLong(lastLogin), dirtyFlag); @@ -347,30 +347,30 @@ public class PersistentPlayerData { * @return the bar state map for this player */ public @NotNull Map getBarStateMap() { - return barStateMap.getDataMap(); - } - - /** - * Get the {@link DirtyDataMap} for the related {@link com.gmail.nossr50.util.experience.MMOExperienceBarManager.BarState}'s of this player - * @return the dirty bar state map for this player - */ - public @NotNull DirtyDataMap getDirtyBarStateMap() { return barStateMap; } /** - * Get the {@link DirtyDataMap} for the skill levels of this player + * Get the {@link DirtyMap} for the related {@link com.gmail.nossr50.util.experience.MMOExperienceBarManager.BarState}'s of this player + * @return the dirty bar state map for this player + */ + public @NotNull DirtyMap getDirtyBarStateMap() { + return barStateMap; + } + + /** + * Get the {@link DirtyMap} for the skill levels of this player * @return the dirty skill level map for this player */ - public @NotNull DirtyDataMap getDirtySkillLevelMap() { + public @NotNull DirtyMap getDirtySkillLevelMap() { return skillLevelValues; } /** - * Get the {@link DirtyDataMap} for the skill experience values of this player + * Get the {@link DirtyMap} for the skill experience values of this player * @return the dirty skill experience values map for this player */ - public @NotNull DirtyDataMap getDirtyExperienceValueMap() { + public @NotNull DirtyMap getDirtyExperienceValueMap() { return skillExperienceValues; } @@ -387,7 +387,7 @@ public class PersistentPlayerData { * @return the map of skill levels for this player */ public @NotNull Map getSkillLevelsMap() { - return skillLevelValues.getDataMap(); + return skillLevelValues; } /** @@ -395,7 +395,7 @@ public class PersistentPlayerData { * @return the experience values map for this player */ public @NotNull Map getSkillsExperienceMap() { - return skillExperienceValues.getDataMap(); + return skillExperienceValues; } /** @@ -403,7 +403,7 @@ public class PersistentPlayerData { * @return the ability deactivation timestamps map for this player */ public @NotNull Map getAbilityDeactivationTimestamps() { - return abilityDeactivationTimestamps.getDataMap(); + return abilityDeactivationTimestamps; } /** @@ -411,7 +411,7 @@ public class PersistentPlayerData { * @return a map of unique data for this player */ public @NotNull Map getUniquePlayerData() { - return uniquePlayerData.getDataMap(); + return uniquePlayerData; } /**