Skip to content

Commit

Permalink
Regression bugs due to TypeFilter restructuring solved
Browse files Browse the repository at this point in the history
  • Loading branch information
rensink committed Nov 13, 2024
1 parent 84430e1 commit 8d9f0c3
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main/java/nl/utwente/groove/gui/tree/TypeFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -191,13 +192,12 @@ static private record EntryMap(TypeGraph typeGraph, Map<TypeKey,TypeEntry> keyMa

/** Constructs a fresh map from a given type graph,
* taking a set of previously selected elements into account. */
EntryMap(TypeGraph typeGraph, Collection<TypeKey> selected) {
EntryMap(TypeGraph typeGraph, Collection<TypeKey> 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);
}
}
}
Expand All @@ -207,12 +207,12 @@ Stream<TypeEntry> entryStream() {
return keyMap().values().stream();
}

/** Returns the set of currently selected type entries. */
Collection<TypeKey> getSelected() {
/** Returns the set of currently (un)selected type entries. */
Collection<TypeKey> getSelected(boolean selected) {
return keyMap()
.values()
.stream()
.filter(TypeEntry::isSelected)
.filter(e -> e.isSelected() == selected)
.map(TypeEntry::getType)
.map(TypeElement::key)
.toList();
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 8d9f0c3

Please sign in to comment.