01: /*
02: * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
03: *
04: * Project: OpenSubsystems
05: *
06: * $Id: BlogCaptionComparator.java,v 1.1 2007/03/05 07:28:12 bastafidli Exp $
07: *
08: * This program is free software; you can redistribute it and/or modify
09: * 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;
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 {
37: // Cached values ////////////////////////////////////////////////////////////
38:
39: /**
40: * Shared comparator instance. Must be named this way to avoid Checkstyle
41: * warning.
42: */
43: private static Comparator s_instance = new BlogCaptionComparator();
44:
45: // Public methods ///////////////////////////////////////////////////////////
46:
47: /**
48: * Get shared comparator instance.
49: *
50: * @return Comparator - shared comparator instance
51: */
52: public static Comparator getInstance() {
53: return s_instance;
54: }
55:
56: /**
57: * Compare captions of two Blog data objects.
58: *
59: * @param o1 - Blog #1
60: * @param o2 - Blog #2
61: * @return int - -1 if o1 < o2,
62: * 0 if o1 == o2
63: * 1 if o1 > o2
64: */
65: public int compare(Object o1, Object o2) {
66: String strCaption1 = ((Blog) o1).getCaption();
67: String strCaption2 = ((Blog) o2).getCaption();
68:
69: return strCaption1.compareTo(strCaption2);
70: }
71: }
|