Class FieldComparator

  • All Implemented Interfaces:
    java.util.Comparator<Hit>

    public class FieldComparator
    extends ChainableComparator
    Comparator used for ordering hits using the field values and a sorting specification.

    Note: this comparator imposes orderings that are inconsistent with equals.

    Author:
    Steinar Knutsen
    • Constructor Summary

      Constructors 
      Constructor Description
      FieldComparator​(Sorting sorting)
      Creates a field comparator using a sort order and having no chained comparator
      FieldComparator​(Sorting sorting, java.util.Comparator<Hit> secondaryComparator)
      Creates a field comparator using a sort order with a chained comparator
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Hit first, Hit second)
      Compares hits based on a sorting specification and values stored in hit fields.0
      static FieldComparator create​(Sorting sorting)
      Creates a comparator given a sorting, or returns null if the given sorting is null
      java.lang.Object getField​(Hit hit, java.lang.String key)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • FieldComparator

        public FieldComparator​(Sorting sorting)
        Creates a field comparator using a sort order and having no chained comparator
      • FieldComparator

        public FieldComparator​(Sorting sorting,
                               java.util.Comparator<Hit> secondaryComparator)
        Creates a field comparator using a sort order with a chained comparator
    • Method Detail

      • create

        public static FieldComparator create​(Sorting sorting)
        Creates a comparator given a sorting, or returns null if the given sorting is null
      • compare

        public int compare​(Hit first,
                           Hit second)
        Compares hits based on a sorting specification and values stored in hit fields.0

        When one of the hits has the requested property and the other has not, the the hit containing the property precedes the one that does not.

        There is no locale based sorting here, as the backend does not do that either.

        Specified by:
        compare in interface java.util.Comparator<Hit>
        Overrides:
        compare in class ChainableComparator
        Returns:
        -1, 0, 1 if first should be sorted before, equal to or after second
      • getField

        public java.lang.Object getField​(Hit hit,
                                         java.lang.String key)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object