Top Description Fields Constructors Methods
org.jabref.logic.bibtex.comparator

public Class EntryComparator

extends Object
implements Comparator<BibEntry>
Class Inheritance
All Implemented Interfaces
java.util.Comparator
Imports
java.util.Comparator, .Locale, .Objects, org.jabref.model.entry.AuthorList, .BibEntry, org.jabref.model.entry.field.Field, .FieldProperty, .InternalField

This implementation of Comparator takes care of most of the details of sorting BibTeX entries in JabRef. It is structured as a node in a linked list of comparators, where each node can contain a link to a new comparator that decides the ordering (by recursion) if this one can't find a difference. The next node, if any, is given at construction time, and an arbitrary number of nodes can be included. If the entries are equal by this comparator, and there is no next entry, the entries' unique IDs will decide the ordering.

Field Summary

Modifier and TypeField and Description
private final boolean
private final boolean
private final Comparator<BibEntry>
private final Field

Constructor Summary

AccessConstructor and Description
public
EntryComparator(boolean
true: the presence of fields is checked; false: the content of the fields is compared
binary
,
boolean
true: if the most different entry should get the highest score
descending
,
Field
the field to sort on
field
,
Comparator<BibEntry>
the next comparator to use (if the current comparator results in equality)
next
)

public
EntryComparator(boolean binary, boolean descending, Field field)

Method Summary

Modifier and TypeMethod and Description
public int
compare(BibEntry
the first object to be compared.
e1
,
BibEntry
the second object to be compared.
e2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

private static int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

binaryback to summary
private final boolean binary
descendingback to summary
private final boolean descending
nextback to summary
private final Comparator<BibEntry> next
sortFieldback to summary
private final Field sortField

Constructor Detail

EntryComparatorback to summary
public EntryComparator(boolean binary, boolean descending, Field field, Comparator<BibEntry> next)
Parameters
binary:boolean

true: the presence of fields is checked; false: the content of the fields is compared

descending:boolean

true: if the most different entry should get the highest score

field:Field

the field to sort on

next:Comparator<BibEntry>

the next comparator to use (if the current comparator results in equality)

EntryComparatorback to summary
public EntryComparator(boolean binary, boolean descending, Field field)

Method Detail

compareback to summary
public int compare(BibEntry e1, BibEntry e2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
e1:BibEntry

the first object to be compared.

e2:BibEntry

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
idCompareback to summary
private static int idCompare(BibEntry b1, BibEntry b2)