KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > ui > text > java > AbstractProposalSorter


1 /*******************************************************************************
2  * Copyright (c) 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.jdt.ui.text.java;
12
13 import java.util.Comparator JavaDoc;
14
15 import org.eclipse.core.runtime.IConfigurationElement;
16
17 import org.eclipse.jface.text.contentassist.ICompletionProposal;
18
19 /**
20  * Abstract base class for sorters contributed to the
21  * <code>org.eclipse.jdt.ui.javaCompletionProposalSorters</code> extension point.
22  * <p>
23  * Subclasses need to implement {@link #compare(ICompletionProposal, ICompletionProposal)} and may
24  * override {@link #beginSorting(ContentAssistInvocationContext) beginSorting} and
25  * {@link #endSorting() endSorting}.
26  * </p>
27  * <p>
28  * The orderings imposed by a subclass need not be consistent with equals.
29  * </p>
30  *
31  * @since 3.2
32  */

33 public abstract class AbstractProposalSorter implements Comparator JavaDoc {
34
35     /**
36      * Creates a new sorter. Note that subclasses must provide a zero-argument constructor to be
37      * instantiatable via {@link IConfigurationElement#createExecutableExtension(String)}.
38      */

39     protected AbstractProposalSorter() {
40     }
41
42     /**
43      * Called once before sorting.
44      * <p>
45      * Clients may override, the default implementation does nothing.
46      * </p>
47      *
48      * @param context the context of the content assist invocation
49      */

50     public void beginSorting(ContentAssistInvocationContext context) {
51     }
52
53     /**
54      * Implements the same contract as {@link Comparator#compare(Object, Object)} but with
55      * completion proposals as parameters. This method will implement the {@link Comparator}
56      * interface if this class is ever converted to extend
57      * <code>Comparator&lt;ICompletionProposal&gt;</code>.
58      * <p>
59      * The orderings imposed by an implementation need not be consistent with equals.
60      * </p>
61      *
62      * @param p1 the first proposal to be compared
63      * @param p2 the second proposal to be compared
64      * @return a negative integer, zero, or a positive integer as the first argument is less than,
65      * equal to, or greater than the second.
66      */

67     public abstract int compare(ICompletionProposal p1, ICompletionProposal p2);
68
69     /**
70      * Called once after sorting.
71      * <p>
72      * Clients may override, the default implementation does nothing.
73      * </p>
74      */

75     public void endSorting() {
76     }
77
78     /**
79      * This method delegates to {@link #compare(ICompletionProposal, ICompletionProposal)} and may
80      * be removed if the class is ever converted to extend
81      * <code>Comparator&lt;ICompletionProposal&gt;</code>.
82      *
83      * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
84      */

85     public final int compare(Object JavaDoc o1, Object JavaDoc o2) {
86         ICompletionProposal p1= (ICompletionProposal) o1;
87         ICompletionProposal p2= (ICompletionProposal) o2;
88
89         return compare(p1, p2);
90     }
91 }
92
Popular Tags