KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > WorkingSetComparator


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

11 package org.eclipse.ui.internal;
12
13 import com.ibm.icu.text.Collator;
14 import java.util.Comparator JavaDoc;
15
16 import org.eclipse.ui.IWorkingSet;
17
18 /**
19  * Compares two working sets by name.
20  */

21 public class WorkingSetComparator implements Comparator JavaDoc {
22     
23     /**
24      * Static instance of this class.
25      * @since 3.2
26      */

27     public static WorkingSetComparator INSTANCE = new WorkingSetComparator();
28     
29     private Collator fCollator = Collator.getInstance();
30
31     /**
32      * Implements Comparator.
33      *
34      * @see Comparator#compare(Object, Object)
35      */

36     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
37         String JavaDoc name1 = null;
38         String JavaDoc name2 = null;
39
40         if (o1 instanceof IWorkingSet) {
41             name1 = ((IWorkingSet) o1).getLabel();
42         }
43
44         if (o2 instanceof IWorkingSet) {
45             name2 = ((IWorkingSet) o2).getLabel();
46         }
47
48         int result = fCollator.compare(name1, name2);
49         if (result == 0) { // okay, same name - now try the unique id
50

51             if (o1 instanceof IWorkingSet) {
52                 name1 = ((IWorkingSet) o1).getName();
53             }
54
55             if (o2 instanceof IWorkingSet) {
56                 name2 = ((IWorkingSet) o2).getName();
57             }
58             
59             result = fCollator.compare(name1, name2);
60         }
61         return result;
62     }
63 }
64
Popular Tags