Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jgift/search/AvailabilityComparator.java


1   /*
2    * This file is part of jgiFT.
3    * Copyright (c) 2003, Jason Shobe
4    *
5    * jgiFT is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * jgiFT is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with jgiFT; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  package jgift.search;
20  
21  /**
22   * Compares search results based on the number of available slots.
23   *
24   * @author  Jason Shobe
25   * @version $Revision: 1.1 $
26   */
27  public class AvailabilityComparator extends SearchResultComparator {
28     /**
29      * Compare two search results for order.
30      *
31      * @param r1 the first result to be compared.
32      * @param r2 the second result to be compared.
33      *
34      * @return -1 if r1 is less than r2, 0 if the objects are equivelent, or
35      *         1 if r1 is greater than r2.
36      */
37     protected int compareResults(SearchResult r1, SearchResult r2) {
38        int a1 = r1.getAvailability();
39        int a2 = r2.getAvailability();
40        
41        if(a1 < a2) {
42           return -1;
43        }
44        else if(a1 > a2) {
45           return 1;
46        }
47        
48        return 0;
49     }
50  }
51