1 | /**
|
---|
2 | * CharUtility.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.greenstone;
|
---|
20 |
|
---|
21 | public class CharUtility {
|
---|
22 |
|
---|
23 | /** Returns an int value that is negative if cCompare comes before cRef in the alphabet, zero if
|
---|
24 | * the two are equal, and positive if cCompare comes after cRef in the alphabet.
|
---|
25 | */
|
---|
26 | public static int compareCharsAlphabetically(char cCompare, char cRef) {
|
---|
27 | return (alphabetizeChar(cCompare) - alphabetizeChar(cRef));
|
---|
28 | }
|
---|
29 |
|
---|
30 | private static int alphabetizeChar(char c) {
|
---|
31 | if(c < 65) return c;
|
---|
32 | if(c < 89) return (2 * c) - 65;
|
---|
33 | if(c < 97) return c + 24;
|
---|
34 | if(c < 121) return (2 * c) - 128;
|
---|
35 | return c;
|
---|
36 | }
|
---|
37 |
|
---|
38 | }
|
---|