01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/trunk/sakai/admin-tools/su/src/java/org/sakaiproject/tool/su/SuTool.java $
03: * $Id: SuTool.java 6970 2006-03-23 23:25:04Z zach.thomas@txstate.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.user.tool;
21:
22: import java.util.Comparator;
23: import java.util.Locale;
24:
25: /**
26: * Comparator for sorting locale by DisplayName
27: */
28: public final class LocaleComparator implements Comparator {
29: /**
30: * * Compares Locale objects by comparing the DisplayName * *
31: *
32: * @param obj1
33: * 1st Locale Object for comparison *
34: * @param obj2
35: * 2nd Locale Object for comparison *
36: * @return negative, zero, or positive integer * (obj1 charge is less than, equal to, or greater than the obj2 charge)
37: */
38: public int compare(Object obj1, Object obj2) {
39: if (obj1 instanceof Locale && obj2 instanceof Locale) {
40: Locale localeOne = (Locale) obj1;
41: Locale localeTwo = (Locale) obj2;
42:
43: String displayNameOne = localeOne.getDisplayName();
44: String displayNameTwo = localeTwo.getDisplayName();
45:
46: return displayNameOne.compareTo(displayNameTwo);
47: } else {
48: throw new ClassCastException(
49: "Inappropriate object class for LocaleComparator");
50: }
51: }
52:
53: /**
54: * * Override of equals method * *
55: *
56: * @param obj
57: * LocaleComparator object *
58: * @return true if equal, false if not equal
59: */
60: public boolean equals(Object obj) {
61: if (obj instanceof LocaleComparator)
62: return super .equals(obj);
63: else
64: return false;
65: }
66: }
|