| BookComparators.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 or later
5 * as published by the Free Software Foundation. This program is distributed
6 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * © CrossWire Bible Society, 2005 - 2016
18 *
19 */
20 package org.crosswire.jsword.book;
21
22 import java.util.Comparator;
23 import java.util.Locale;
24
25 /**
26 * Provides different ways to sort Books.
27 *
28 * @see gnu.lgpl.License The GNU Lesser General Public License for details.
29 * @author DM Smith
30 */
31 public final class BookComparators {
32 /**
33 * Ensure we can't be created
34 */
35 private BookComparators() {
36 }
37
38 /**
39 * Order by default Book ordering
40 *
41 * @return the desired Comparator
42 */
43 public static Comparator<Book> getDefault() {
44 return new Comparator<Book>() {
45 public int compare(Book o1, Book o2) {
46 return o1.compareTo(o2);
47 }
48 };
49 }
50
51 /**
52 * Order by Initials.
53 *
54 * @return the desired Comparator
55 */
56 public static Comparator<Book> getInitialComparator() {
57 return new Comparator<Book>() {
58 public int compare(Book o1, Book o2) {
59 return o1.getInitials().toUpperCase(Locale.ENGLISH).compareTo(o2.getInitials().toUpperCase(Locale.ENGLISH));
60 }
61 };
62 }
63 }
64