Skip to content

Commit

Permalink
try around with some more stuff
Browse files Browse the repository at this point in the history
still not saved correct in order argh
  • Loading branch information
Siedlerchr committed May 2, 2020
1 parent 13b2923 commit 1cbed25
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
20 changes: 11 additions & 9 deletions src/main/java/org/jabref/model/entry/BibEntryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import org.jabref.model.entry.field.OrFields;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.util.LinkedHashSetEqualsUtil;

public class BibEntryType implements Comparable<BibEntryType> {

private final EntryType type;
private final Set<OrFields> requiredFields;
private final Set<BibField> fields;
private final LinkedHashSet<OrFields> requiredFields;
private final LinkedHashSet<BibField> fields;

public BibEntryType(EntryType type, Collection<BibField> fields, Collection<OrFields> requiredFields) {
this.type = Objects.requireNonNull(type);
Expand Down Expand Up @@ -112,13 +113,14 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if ((o == null) || (getClass() != o.getClass())) {
return false;
}
BibEntryType that = (BibEntryType) o;
return type.equals(that.type) &&
requiredFields.equals(that.requiredFields) &&
fields.equals(that.fields);
LinkedHashSetEqualsUtil.linkedEquals(requiredFields, that.requiredFields)
&& LinkedHashSetEqualsUtil.linkedEquals(fields, that.fields);

}

@Override
Expand All @@ -129,10 +131,10 @@ public int hashCode() {
@Override
public String toString() {
return "BibEntryType{" +
"type=" + type +
", requiredFields=" + requiredFields +
", fields=" + fields +
'}';
"type=" + type +
", requiredFields=" + requiredFields +
", fields=" + fields +
'}';
}

@Override
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/jabref/model/entry/field/OrFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.StringJoiner;
import java.util.TreeSet;

public class OrFields extends TreeSet<Field> implements Comparable<OrFields> {
public class OrFields extends LinkedHashSet<Field> implements Comparable<OrFields> {

public OrFields(Field field) {
super(Comparator.comparing(Field::getName));
add(field);
}

public OrFields(Field... fields) {
super(Comparator.comparing(Field::getName));
addAll(Arrays.asList(fields));
}

public OrFields(Collection<Field> fields) {
super(Comparator.comparing(Field::getName));
addAll(fields);
}

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/jabref/model/util/LinkedHashSetEqualsUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jabref.model.util;

import java.util.Iterator;
import java.util.LinkedHashSet;

public class LinkedHashSetEqualsUtil {

public static <K> boolean linkedEquals(LinkedHashSet<K> left, LinkedHashSet<K> right) {
Iterator<K> leftItr = left.iterator();
Iterator<K> rightItr = right.iterator();

while (leftItr.hasNext() && rightItr.hasNext()) {
K leftEntry = leftItr.next();
K rightEntry = rightItr.next();

//AbstractList does null checks here but for sets we can assume you never get null entries
if (!leftEntry.equals(rightEntry)) {
return false;
}
}
return !(leftItr.hasNext() || rightItr.hasNext());
}
}

0 comments on commit 1cbed25

Please sign in to comment.