KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > blog > logic > BlogCaptionComparator


1 /*
2  * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: BlogCaptionComparator.java,v 1.1 2007/03/05 07:28:12 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.blog.logic;
23
24 import java.util.Comparator JavaDoc;
25
26 import org.opensubsystems.blog.data.Blog;
27
28 /**
29  * Comparator to compare blog data objects based on their captions.
30  *
31  * @version $Id: BlogCaptionComparator.java,v 1.1 2007/03/05 07:28:12 bastafidli Exp $
32  * @author Miro Halas
33  * @code.reviewer Miro Halas
34  * @code.reviewed Initial revision
35  */

36 public class BlogCaptionComparator implements Comparator JavaDoc
37 {
38    // Cached values ////////////////////////////////////////////////////////////
39

40    /**
41     * Shared comparator instance. Must be named this way to avoid Checkstyle
42     * warning.
43     */

44    private static Comparator JavaDoc s_instance = new BlogCaptionComparator();
45
46    // Public methods ///////////////////////////////////////////////////////////
47

48    /**
49     * Get shared comparator instance.
50     *
51     * @return Comparator - shared comparator instance
52     */

53    public static Comparator JavaDoc getInstance(
54    )
55    {
56       return s_instance;
57    }
58
59    /**
60     * Compare captions of two Blog data objects.
61     *
62     * @param o1 - Blog #1
63     * @param o2 - Blog #2
64     * @return int - -1 if o1 < o2,
65     * 0 if o1 == o2
66     * 1 if o1 > o2
67     */

68    public int compare(
69       Object JavaDoc o1,
70       Object JavaDoc o2
71    )
72    {
73       String JavaDoc strCaption1 = ((Blog)o1).getCaption();
74       String JavaDoc strCaption2 = ((Blog)o2).getCaption();
75
76       return strCaption1.compareTo(strCaption2);
77    }
78 }
79
Popular Tags