KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > content > comparators > PageByTitleComparator


1 /*
2  * Copyright (c) 2005 Your Corporation. All Rights Reserved.
3  */

4 package org.jahia.content.comparators;
5
6 import org.jahia.services.pages.ContentPage;
7 import org.jahia.params.ParamBean;
8
9 import java.util.Comparator JavaDoc;
10
11 /**
12  * Created by IntelliJ IDEA.
13  * User: Rincevent
14  * Date: 28 févr. 2005
15  * Time: 14:57:04
16  * To change this template use File | Settings | File Templates.
17  */

18 public class PageByTitleComparator implements Comparator JavaDoc {
19     private ParamBean paramBean;
20
21     public PageByTitleComparator(ParamBean paramBean) {
22         this.paramBean = paramBean;
23     }
24     private PageByTitleComparator() {
25     }
26     /**
27      * Compares its two arguments for order. Returns a negative integer,
28      * zero, or a positive integer as the first argument is less than, equal
29      * to, or greater than the second.<p>
30      * <p/>
31      * The implementor must ensure that <tt>sgn(compare(x, y)) ==
32      * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
33      * implies that <tt>compare(x, y)</tt> must throw an exception if and only
34      * if <tt>compare(y, x)</tt> throws an exception.)<p>
35      * <p/>
36      * The implementor must also ensure that the relation is transitive:
37      * <tt>((compare(x, y)&gt;0) &amp;&amp; (compare(y, z)&gt;0))</tt> implies
38      * <tt>compare(x, z)&gt;0</tt>.<p>
39      * <p/>
40      * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt>
41      * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
42      * <tt>z</tt>.<p>
43      * <p/>
44      * It is generally the case, but <i>not</i> strictly required that
45      * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking,
46      * any comparator that violates this condition should clearly indicate
47      * this fact. The recommended language is "Note: this comparator
48      * imposes orderings that are inconsistent with equals."
49      *
50      * @param o1 the first object to be compared.
51      * @param o2 the second object to be compared.
52      *
53      * @return a negative integer, zero, or a positive integer as the
54      * first argument is less than, equal to, or greater than the
55      * second.
56      *
57      * @throws ClassCastException if the arguments' types prevent them from
58      * being compared by this Comparator.
59      */

60     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
61
62         if(o1 instanceof ContentPage && o2 instanceof ContentPage) {
63             ContentPage page1 = (ContentPage) o1;
64             ContentPage page2 = (ContentPage) o2;
65             return page1.getTitle(paramBean).compareTo(page2.getTitle(paramBean));
66         }
67         return 0;
68     }
69 }
70
Popular Tags