From 2a92ed0be17333c9303666efc5b7f4d156e23727 Mon Sep 17 00:00:00 2001 From: Tom Czarniecki Date: Fri, 5 Jul 2024 13:58:42 +1000 Subject: [PATCH] make sure that we don't break import state checks --- .../java/com/tomczarniecki/jpasskeep/Entry.java | 8 ++++++++ .../tomczarniecki/jpasskeep/MainListModel.java | 15 ++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/tomczarniecki/jpasskeep/Entry.java b/src/main/java/com/tomczarniecki/jpasskeep/Entry.java index f550d43..889cc6e 100644 --- a/src/main/java/com/tomczarniecki/jpasskeep/Entry.java +++ b/src/main/java/com/tomczarniecki/jpasskeep/Entry.java @@ -99,6 +99,14 @@ public void setNotes(String notes) { this.notes = notes; } + public void updateFrom(Entry other) { + this.setDescription(other.getDescription()); + this.setCategory(other.getCategory()); + this.setUsername(other.getUsername()); + this.setPassword(other.getPassword()); + this.setNotes(other.getNotes()); + } + public int compareTo(Entry other) { return this.getDescription().compareToIgnoreCase(other.getDescription()); } diff --git a/src/main/java/com/tomczarniecki/jpasskeep/MainListModel.java b/src/main/java/com/tomczarniecki/jpasskeep/MainListModel.java index 845f871..de117f0 100644 --- a/src/main/java/com/tomczarniecki/jpasskeep/MainListModel.java +++ b/src/main/java/com/tomczarniecki/jpasskeep/MainListModel.java @@ -73,11 +73,8 @@ public void setEntry(Entry entry) { entries.put(entry.getKey(), entry); } else if (state.equals(ImportState.Changed)) { for (Entry current : entries.values()) { - if (current.getDescription().equals(entry.getDescription())) { - current.setCategory(entry.getCategory()); - current.setUsername(entry.getUsername()); - current.setPassword(entry.getPassword()); - current.setNotes(entry.getNotes()); + if (current.compareTo(entry) == 0) { + current.updateFrom(entry); } } } @@ -143,10 +140,10 @@ private boolean show(Entry entry) { }; } - public ImportState stateForEntry(Entry otherEntry) { - for (Entry entry : entries.values()) { - if (entry.getDescription().equals(otherEntry.getDescription())) { - if (entry.equals(otherEntry)) { + public ImportState stateForEntry(Entry entry) { + for (Entry current : entries.values()) { + if (current.compareTo(entry) == 0) { + if (current.equals(entry)) { return ImportState.Equal; } return ImportState.Changed;