KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > search > SorterByScore


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.search;
12 import org.eclipse.help.internal.search.*;
13 import org.eclipse.jface.viewers.*;
14 /**
15  * Sorts results of help sarch in search view by rank.
16  */

17 public class SorterByScore extends ViewerSorter {
18     /**
19      * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer,java.lang.Object,java.lang.Object)
20      */

21     public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
22         try {
23             float rank1 = ((SearchHit) e1).getScore();
24             float rank2 = ((SearchHit) e2).getScore();
25             if (rank1 - rank2 > 0) {
26                 return -1;
27             } else if (rank1 == rank2) {
28                 return 0;
29             } else {
30                 return 1;
31             }
32         } catch (Exception JavaDoc e) {
33         }
34         return super.compare(viewer, e1, e2);
35     }
36 }
Popular Tags