Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.pde.spy.preferences.model;

import java.util.Objects;

public class PreferenceEntry extends AbstractModelObject {

public enum Fields {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -103,70 +98,23 @@ 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
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ public void DeletePreferenceEntries(
@UIEventTopic(PreferenceSpyEventTopics.PREFERENCESPY_PREFERENCE_ENTRIES_DELETE) List<PreferenceEntry> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Loading