Skip to content

Commit

Permalink
Fxed an element duplication error
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Parfitt committed Mar 25, 2022
1 parent 25dd743 commit 9cb938e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/system_utils/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ public boolean import_element_choices(String file_path) {
String[] elem_and_elems = line.split(":");
Element main_elem = Element.valueOf(elem_and_elems[0]);
ElementCorrelationInfo eci = correlations.get(main_elem);
eci.clear_selection();
for (String s : elem_and_elems[1].split(",")) {
eci.add_selected(Element.valueOf(s));
}
Expand Down
20 changes: 18 additions & 2 deletions src/system_utils/ElementCorrelationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,14 @@ public ArrayList<CorrelationInfo> get_selected() {
}

public boolean is_selected(Element secondary) {
CorrelationInfo corr = this.all_correlations.get(secondary);
return corr.in_use();
if (this.all_correlations.containsKey(secondary)) {
CorrelationInfo corr = this.all_correlations.get(secondary);
if (corr == null) {
return false;
}
return corr.in_use();
}
return false;
}

// These set methods are used by datastore to pass along changes
Expand All @@ -338,6 +344,16 @@ public void remove_selected(Element secondary) {
this.selected_elements.remove(corr);
}

public void clear_selection() {
for (Element e : Element.values()) {
if (is_selected(e)) {

remove_selected(e);

}
}
}

public ArrayList<Element> get_selected_names() {
ArrayList<Element> sel = new ArrayList<Element>();
for (CorrelationInfo corr : get_selected()) {
Expand Down

0 comments on commit 9cb938e

Please sign in to comment.