-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
36 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/org/jabref/model/util/LinkedHashSetEqualsUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |