diff --git a/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/model/PreferenceEntry.java b/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/model/PreferenceEntry.java index 751a48f0048..4fc95742b43 100644 --- a/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/model/PreferenceEntry.java +++ b/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/model/PreferenceEntry.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.pde.spy.preferences.model; +import java.util.Objects; + public class PreferenceEntry extends AbstractModelObject { public enum Fields { @@ -48,13 +50,6 @@ public PreferenceEntry(String nodePath, String key, String oldValue, String newV this.newValue = newValue; } - public PreferenceEntry(PreferenceEntry parent, String nodePath, String key, String oldValue, String newValue) { - this.nodePath = nodePath; - this.key = key; - this.oldValue = oldValue; - this.newValue = newValue; - } - public PreferenceEntry getParent() { return parent; } @@ -103,17 +98,11 @@ public void setRecentlyChanged(boolean recentlyChanged) { firePropertyChange("recentlyChanged", this.recentlyChanged, this.recentlyChanged = recentlyChanged); } + // Identity is the (nodePath, key) pair. Mutable fields like oldValue/newValue/recentlyChanged + // must not participate, because instances are stored in a WritableSet and mutated in place. @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + ((newValue == null) ? 0 : newValue.hashCode()); - result = prime * result + ((nodePath == null) ? 0 : nodePath.hashCode()); - result = prime * result + ((oldValue == null) ? 0 : oldValue.hashCode()); - result = prime * result + ((parent == null) ? 0 : parent.hashCode()); - result = prime * result + (recentlyChanged ? 1231 : 1237); - return result; + return Objects.hash(nodePath, key); } @Override @@ -121,52 +110,11 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } PreferenceEntry other = (PreferenceEntry) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - if (newValue == null) { - if (other.newValue != null) { - return false; - } - } else if (!newValue.equals(other.newValue)) { - return false; - } - if (nodePath == null) { - if (other.nodePath != null) { - return false; - } - } else if (!nodePath.equals(other.nodePath)) { - return false; - } - if (oldValue == null) { - if (other.oldValue != null) { - return false; - } - } else if (!oldValue.equals(other.oldValue)) { - return false; - } - if (parent == null) { - if (other.parent != null) { - return false; - } - } else if (!parent.equals(other.parent)) { - return false; - } - if (recentlyChanged != other.recentlyChanged) { - return false; - } - return true; + return Objects.equals(nodePath, other.nodePath) && Objects.equals(key, other.key); } public long getTime() { diff --git a/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/parts/PreferenceSpyPart.java b/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/parts/PreferenceSpyPart.java index d799f03c0ee..d8518093d41 100644 --- a/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/parts/PreferenceSpyPart.java +++ b/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/parts/PreferenceSpyPart.java @@ -196,9 +196,13 @@ public void DeletePreferenceEntries( @UIEventTopic(PreferenceSpyEventTopics.PREFERENCESPY_PREFERENCE_ENTRIES_DELETE) List preferenceEntries) { if (preferenceEntries != null && !preferenceEntries.isEmpty()) { for (PreferenceEntry preferenceEntry : preferenceEntries) { - preferenceEntryManager.removeChildren(preferenceEntry); + PreferenceEntry parent = preferenceEntry.getParent(); + if (parent instanceof PreferenceNodeEntry parentNode) { + parentNode.removeChildren(preferenceEntry); + } else { + preferenceEntryManager.removeChildren(preferenceEntry); + } } - preferenceEntryManager.removeChildren(preferenceEntries); filteredTree.getViewer().refresh(); } } diff --git a/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/viewer/PreferenceEntryViewerComparator.java b/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/viewer/PreferenceEntryViewerComparator.java index fc2b06fb4ff..ef5a59b6483 100644 --- a/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/viewer/PreferenceEntryViewerComparator.java +++ b/ui/org.eclipse.pde.spy.preferences/src/org/eclipse/pde/spy/preferences/viewer/PreferenceEntryViewerComparator.java @@ -35,7 +35,7 @@ public int compare(Viewer viewer, Object e1, Object e2) { long time2 = entry2.getTime(); if (time != 0 && time2 != 0) { - return (int) (time2 - time); + return Long.compare(time2, time); } }