Skip to content

Commit

Permalink
Fix Shared Database Tests (#7040)
Browse files Browse the repository at this point in the history
* Fix Shared Database Tests

Fix FieldChangeEvent Delta computation

* Use length directly foir comparision

* upgrade postgres to 13
rename delta to majorCharacterChange

* revert unrelated change
  • Loading branch information
Siedlerchr authored Nov 3, 2020
1 parent 73a8193 commit b5bcea4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:10.8
image: postgres:13-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public synchronized void listen(BibDatabaseContextChangedEvent event) {
boolean isChangedEntry = lastEntryChanged.filter(e -> !e.equals(fieldChange.getBibEntry())).isPresent();
boolean isEditChanged = !isNewEdit && (isChangedField || isChangedEntry);
// Only deltas of 1 when typing in manually, major change means pasting something (more than one character)
boolean isMajorChange = fieldChange.getDelta() > 1;
boolean isMajorChange = fieldChange.getMajorCharacterChange() > 1;

fieldChange.setFilteredOut(!(isEditChanged || isMajorChange));
// Post each FieldChangedEvent - even the ones being marked as "filtered"
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/org/jabref/model/entry/event/FieldChangedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FieldChangedEvent extends EntryChangedEvent {
private final Field field;
private final String newValue;
private final String oldValue;
private int delta = 0;
private int majorCharacterChange = 0;

/**
* @param bibEntry Affected BibEntry object
Expand All @@ -27,7 +27,7 @@ public FieldChangedEvent(BibEntry bibEntry, Field field, String newValue, String
this.field = field;
this.newValue = newValue;
this.oldValue = oldValue;
this.delta = computeDelta(oldValue, newValue);
this.majorCharacterChange = computeMajorCharacterChange(oldValue, newValue);
}

/**
Expand All @@ -40,7 +40,7 @@ public FieldChangedEvent(BibEntry bibEntry, Field field, String newValue, String
this.field = field;
this.newValue = newValue;
this.oldValue = oldValue;
this.delta = computeDelta(oldValue, newValue);
this.majorCharacterChange = computeMajorCharacterChange(oldValue, newValue);
}

/**
Expand All @@ -51,20 +51,22 @@ public FieldChangedEvent(FieldChange fieldChange, EntriesEventSource location) {
this.field = fieldChange.getField();
this.newValue = fieldChange.getNewValue();
this.oldValue = fieldChange.getOldValue();
this.delta = computeDelta(oldValue, newValue);
this.majorCharacterChange = computeMajorCharacterChange(oldValue, newValue);
}

public FieldChangedEvent(FieldChange fieldChange) {
this(fieldChange, EntriesEventSource.LOCAL);
}

private int computeDelta(String oldValue, String newValue) {
private int computeMajorCharacterChange(String oldValue, String newValue) {
if (oldValue == newValue) {
return 0;
} else if (oldValue == null && newValue != null) {
} else if ((oldValue == null) && (newValue != null)) {
return newValue.length();
} else if (newValue == null && oldValue != null) {
} else if ((newValue == null) && (oldValue != null)) {
return oldValue.length();
} else if ((oldValue.length() == newValue.length()) && !oldValue.equals(newValue)) {
return newValue.length();
} else {
return Math.abs(newValue.length() - oldValue.length());
}
Expand All @@ -82,7 +84,7 @@ public String getOldValue() {
return oldValue;
}

public int getDelta() {
return delta;
public int getMajorCharacterChange() {
return majorCharacterChange;
}
}

0 comments on commit b5bcea4

Please sign in to comment.