From 8d9f0c335b064f6f73fa4896901b7d7ac9e0f464 Mon Sep 17 00:00:00 2001 From: rensink Date: Wed, 13 Nov 2024 16:38:47 +0100 Subject: [PATCH] Regression bugs due to TypeFilter restructuring solved --- .../utwente/groove/gui/tree/TypeFilter.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/nl/utwente/groove/gui/tree/TypeFilter.java b/src/main/java/nl/utwente/groove/gui/tree/TypeFilter.java index 06d2d6d88..2ac9f4d34 100644 --- a/src/main/java/nl/utwente/groove/gui/tree/TypeFilter.java +++ b/src/main/java/nl/utwente/groove/gui/tree/TypeFilter.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.stream.Stream; @@ -121,7 +122,7 @@ void update(TypeGraph typeGraph) { this.entryMap = entryMap = new EntryMap(typeGraph); } else if (typeGraph != entryMap.typeGraph()) { // retrieve the selection status from the previous entry map - this.entryMap = entryMap = new EntryMap(typeGraph, entryMap.getSelected()); + this.entryMap = entryMap = new EntryMap(typeGraph, entryMap.getSelected(false)); } entryMap.entryStream().forEach(this::registerEntry); this.stale = false; @@ -191,13 +192,12 @@ static private record EntryMap(TypeGraph typeGraph, Map keyMa /** Constructs a fresh map from a given type graph, * taking a set of previously selected elements into account. */ - EntryMap(TypeGraph typeGraph, Collection selected) { + EntryMap(TypeGraph typeGraph, Collection unselected) { this(typeGraph); - keyMap().values().forEach(e -> e.setSelected(false)); - for (var key : selected) { + for (var key : unselected) { var entry = keyMap().get(key); if (entry != null) { - entry.setSelected(true); + entry.setSelected(false); } } } @@ -207,12 +207,12 @@ Stream entryStream() { return keyMap().values().stream(); } - /** Returns the set of currently selected type entries. */ - Collection getSelected() { + /** Returns the set of currently (un)selected type entries. */ + Collection getSelected(boolean selected) { return keyMap() .values() .stream() - .filter(TypeEntry::isSelected) + .filter(e -> e.isSelected() == selected) .map(TypeEntry::getType) .map(TypeElement::key) .toList(); @@ -335,7 +335,7 @@ public int hashCode() { return this.type.hashCode(); } else { TypeEdge edge = (TypeEdge) this.type; - return edge.source().label().hashCode() ^ edge.label().hashCode(); + return Objects.hash(edge.source().label(), edge.label(), edge.target().label()); } } @@ -350,17 +350,18 @@ public boolean equals(Object obj) { if (!this.type.label().equals(other.type.label())) { return false; } - if (this.type instanceof TypeNode) { + if (!(this.type instanceof TypeEdge edge)) { return other.type instanceof TypeNode; } - if (other.type instanceof TypeNode) { + if (!(other.type instanceof TypeEdge otherEdge)) { return false; } - TypeEdge edge = (TypeEdge) this.type; - TypeEdge otherEdge = (TypeEdge) other.type; if (!edge.source().label().equals(otherEdge.source().label())) { return false; } + if (!edge.target().label().equals(otherEdge.target().label())) { + return false; + } return true; }