bad8e94186ec0cf1333631378128edc6c4263cfc
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / java / PHPCompletionProposalComparator.java
1 package net.sourceforge.phpdt.internal.ui.text.java;
2
3 import java.util.Comparator;
4
5 public class PHPCompletionProposalComparator implements Comparator {
6
7         private boolean fOrderAlphabetically;
8
9         /**
10          * Constructor for CompletionProposalComparator.
11          */
12         // public PHPCompletionProposalComparator() {
13         // fOrderAlphabetically= false;
14         // }
15         public void setOrderAlphabetically(boolean orderAlphabetically) {
16                 fOrderAlphabetically = orderAlphabetically;
17         }
18
19         /*
20          * (non-Javadoc)
21          * 
22          * @see Comparator#compare(Object, Object)
23          */
24         public int compare(Object o1, Object o2) {
25                 IPHPCompletionProposal c1 = (IPHPCompletionProposal) o1;
26                 IPHPCompletionProposal c2 = (IPHPCompletionProposal) o2;
27                 if (!fOrderAlphabetically) {
28                         int relevanceDif = c2.getRelevance() - c1.getRelevance();
29                         if (relevanceDif != 0) {
30                                 return relevanceDif;
31                         }
32                 }
33                 return c1.getDisplayString().compareToIgnoreCase(c2.getDisplayString());
34         }
35
36 }