Skip to content

Commit

Permalink
Fix saving triggers metadata changed
Browse files Browse the repository at this point in the history
Fixes #9159

Generate new equals, hashcode for FieldFormatterCleanup and toString methods
  • Loading branch information
Siedlerchr committed Sep 19, 2022
1 parent ab48277 commit 91db0ce
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- The global default directory for storing PDFs is now the subdirectory "JabRef" in the user's home.
- We reworked the Define study parameters dialog. [#9123](https://github.com/JabRef/jabref/pull/9123)
- We simplified the actions to fast-resolve duplicates to 'Keep Left', 'Keep Right', 'Keep Both' and 'Keep Merged'. [#9056](https://github.com/JabRef/jabref/issues/9056)

- We fixed an issue where a message about changed metadata would occur on saving although nothing changed [#9159](https://github.com/JabRef/jabref/issues/9159)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public Formatter getFormatter() {
}

@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o instanceof FieldFormatterCleanup) {
FieldFormatterCleanup that = (FieldFormatterCleanup) o;
return Objects.equals(field, that.field) && Objects.equals(formatter, that.formatter);
if (!(obj instanceof FieldFormatterCleanup)) {
return false;
}
return false;
FieldFormatterCleanup other = (FieldFormatterCleanup) obj;
return Objects.equals(field, other.field) && Objects.equals(formatter, other.formatter);
}

@Override
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,26 @@ private static Formatter getFormatterFromString(String formatterName) {
}
return new IdentityFormatter();
}

@Override
public int hashCode() {
return Objects.hash(actions, enabled);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof FieldFormatterCleanups)) {
return false;
}
FieldFormatterCleanups other = (FieldFormatterCleanups) obj;
return Objects.equals(actions, other.actions) && (enabled == other.enabled);
}

@Override
public String toString() {
return "FieldFormatterCleanups [enabled=" + enabled + ", actions=" + actions + "]";
}
}
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/model/metadata/ContentSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if ((o == null) || (getClass() != o.getClass())) {
return false;
}

Expand All @@ -35,6 +35,11 @@ public boolean equals(Object o) {
Objects.equals(values, that.values);
}

@Override
public String toString() {
return "ContentSelector [field=" + field + ", values=" + values + "]";
}

@Override
public int hashCode() {
return Objects.hash(field, values);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/jabref/model/metadata/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,14 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(groupsRoot.getValue(), encoding, encodingExplicitlySupplied, saveOrderConfig, citeKeyPatterns, userFileDirectory,
defaultCiteKeyPattern, saveActions, mode, isProtected, defaultFileDirectory);
return Objects.hash(isProtected, groupsRoot.getValue(), encoding, encodingExplicitlySupplied, saveOrderConfig, citeKeyPatterns, userFileDirectory,
laTexFileDirectory, defaultCiteKeyPattern, saveActions, mode, defaultFileDirectory, contentSelectors);
}

@Override
public String toString() {
return "MetaData [citeKeyPatterns=" + citeKeyPatterns + ", userFileDirectory=" + userFileDirectory + ", laTexFileDirectory=" + laTexFileDirectory + ", groupsRoot=" + groupsRoot + ", encoding=" + encoding + ", saveOrderConfig=" + saveOrderConfig + ", defaultCiteKeyPattern=" + defaultCiteKeyPattern + ", saveActions=" + saveActions + ", mode=" + mode + ", isProtected=" + isProtected + ", defaultFileDirectory=" + defaultFileDirectory + ", contentSelectors=" + contentSelectors + ", encodingExplicitlySupplied=" + encodingExplicitlySupplied + "]";
}


}

0 comments on commit 91db0ce

Please sign in to comment.