//# 0 errors, 22 messages
//#
/*
    //#searchhitbyscorecomparator.java:1:1: class: net.sourceforge.pebble.comparator.SearchHitByScoreComparator
    //#searchhitbyscorecomparator.java:1:1: method: net.sourceforge.pebble.comparator.SearchHitByScoreComparator.net.sourceforge.pebble.comparator.SearchHitByScoreComparator__static_init
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.comparator;

import net.sourceforge.pebble.search.SearchHit;

import java.util.Comparator;

/**
 * A comparator used to order SearchHit instances, in reverse order
 * of their date.
 *
 * @author    Simon Brown
 */
public class SearchHitByScoreComparator implements Comparator {
    //#searchhitbyscorecomparator.java:44: method: void net.sourceforge.pebble.comparator.SearchHitByScoreComparator.net.sourceforge.pebble.comparator.SearchHitByScoreComparator()
    //#searchhitbyscorecomparator.java:44: end of method: void net.sourceforge.pebble.comparator.SearchHitByScoreComparator.net.sourceforge.pebble.comparator.SearchHitByScoreComparator()

  /**
   * Compares two objects.
   *
   * @param o1  object 1
   * @param o2  object 2
   * @return  -n, 0 or +n if the score represented by the second hit is less than,
   *          the same as or greater than the first, respectively
   */
  public int compare(Object o1, Object o2) {
    SearchHit h1 = (SearchHit)o1;
    //#searchhitbyscorecomparator.java:55: method: int net.sourceforge.pebble.comparator.SearchHitByScoreComparator.compare(Object, Object)
    //#input(int compare(Object, Object)): o1
    //#input(int compare(Object, Object)): o2
    //#output(int compare(Object, Object)): return_value
    //#pre[1] (int compare(Object, Object)): o1 != null
    //#pre[2] (int compare(Object, Object)): o2 != null
    //#presumption(int compare(Object, Object)): net.sourceforge.pebble.search.SearchHit:getDate(...)@60 != null
    //#post(int compare(Object, Object)): init'ed(return_value)
    //#test_vector(int compare(Object, Object)): java.lang.Float:compare(...)@58: {-2_147_483_648..-1, 1..4_294_967_295}, {0}
    SearchHit h2 = (SearchHit)o2;

    int comparison = Float.compare(h2.getScore(), h1.getScore());
    //#searchhitbyscorecomparator.java:58: Warning: method not available
    //#    -- call on float net.sourceforge.pebble.search.SearchHit:getScore()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.comparator.SearchHitByScoreComparator
    //#    method: int compare(Object, Object)
    //#    unanalyzed callee: float net.sourceforge.pebble.search.SearchHit:getScore()
    if (comparison == 0) {
      return h2.getDate().compareTo(h1.getDate());
    //#searchhitbyscorecomparator.java:60: Warning: method not available
    //#    -- call on Date net.sourceforge.pebble.search.SearchHit:getDate()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.comparator.SearchHitByScoreComparator
    //#    method: int compare(Object, Object)
    //#    unanalyzed callee: Date net.sourceforge.pebble.search.SearchHit:getDate()
    } else {
      return comparison;
    //#searchhitbyscorecomparator.java:62: end of method: int net.sourceforge.pebble.comparator.SearchHitByScoreComparator.compare(Object, Object)
    }
  }

}
    //#output(net.sourceforge.pebble.comparator.SearchHitByScoreComparator__static_init): __Descendant_Table[net/sourceforge/pebble/comparator/SearchHitByScoreComparator]
    //#output(net.sourceforge.pebble.comparator.SearchHitByScoreComparator__static_init): __Dispatch_Table.compare(Ljava/lang/Object;Ljava/lang/Object;)I
    //#post(net.sourceforge.pebble.comparator.SearchHitByScoreComparator__static_init): __Descendant_Table[net/sourceforge/pebble/comparator/SearchHitByScoreComparator] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.comparator.SearchHitByScoreComparator__static_init): __Dispatch_Table.compare(Ljava/lang/Object;Ljava/lang/Object;)I == &compare
    //#searchhitbyscorecomparator.java:: end of method: net.sourceforge.pebble.comparator.SearchHitByScoreComparator.net.sourceforge.pebble.comparator.SearchHitByScoreComparator__static_init
    //#searchhitbyscorecomparator.java:: end of class: net.sourceforge.pebble.comparator.SearchHitByScoreComparator
