Deprecated
This exact behavior can be had using comparators from Apache
Commons Collections, which opencsv includes as a dependency. The following
code gives the same result:
List<T> predefinedList = Arrays.<T>asList(predefinedOrder);
FixedOrderComparator<T> fixedComparator = new FixedOrderComparator<>(predefinedList);
fixedComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.AFTER);
Comparator<T> c = new ComparatorChain<>(Arrays.<Comparator<T>>asList(
fixedComparator,
new NullComparator<>(false),
new ComparableComparator<>()));
java.util.Comparator takes an array of literals that define an
order.
Anything not included in the array is placed after anything in the array and
is then sorted according to its natural order.
| Modifier and Type | Field and Description |
|---|---|
| private Comparator | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int |
| c | back to summary |
|---|---|
| private Comparator<T> c | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| LiteralComparator | back to summary |
|---|---|
| public LiteralComparator(T[] predefinedOrder) Constructor.
| |
| compare | back to summary |
|---|---|
| public int compare(T o1, T o2) Implements java. Doc from java. 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
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that
| |