Class LiteralComparator<T extends Comparable<T>>

java.lang.Object
com.opencsv.bean.comparator.LiteralComparator<T>
Type Parameters:
T - The type to be sorted
All Implemented Interfaces:
Serializable, Comparator<T>

@Deprecated public class LiteralComparator<T extends Comparable<T>> extends Object implements Comparator<T>, Serializable
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<>()));
This 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.
Since:
4.3
See Also:
  • Field Details

  • Constructor Details

    • LiteralComparator

      public LiteralComparator(T[] predefinedOrder)
      Deprecated.
      Constructor.
      Parameters:
      predefinedOrder - Objects that define the order of comparison
  • Method Details