01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/integration/helper/standalone/FacadeUtils.java $
03: * $Id: FacadeUtils.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 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.tool.assessment.integration.helper.standalone;
21:
22: import java.util.*;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.sakaiproject.section.api.coursemanagement.EnrollmentRecord;
27:
28: /**
29: * borrowed gradebook's FacadeUtils class
30: */
31: public class FacadeUtils {
32: private static final Log log = LogFactory.getLog(FacadeUtils.class);
33:
34: // Enforce noninstantiability.
35: private FacadeUtils() {
36: }
37:
38: /**
39: * A comparator that sorts enrollments by student sortName
40: */
41: public static final Comparator ENROLLMENT_NAME_COMPARATOR = new Comparator() {
42: public int compare(Object o1, Object o2) {
43: return ((EnrollmentRecord) o1).getUser().getSortName()
44: .compareToIgnoreCase(
45: ((EnrollmentRecord) o2).getUser()
46: .getSortName());
47: }
48: };
49:
50: /**
51: * A comparator that sorts enrollments by student display UID (for installations
52: * where a student UID is not a number)
53: */
54: public static final Comparator ENROLLMENT_DISPLAY_UID_COMPARATOR = new Comparator() {
55: public int compare(Object o1, Object o2) {
56: return ((EnrollmentRecord) o1).getUser().getDisplayId()
57: .compareToIgnoreCase(
58: ((EnrollmentRecord) o2).getUser()
59: .getDisplayId());
60: }
61: };
62:
63: /**
64: * A comparator that sorts enrollments by student display UID (for installations
65: * where a student UID is a number)
66: */
67: public static final Comparator ENROLLMENT_DISPLAY_UID_NUMERIC_COMPARATOR = new Comparator() {
68: public int compare(Object o1, Object o2) {
69: long user1DisplayId = Long
70: .parseLong(((EnrollmentRecord) o1).getUser()
71: .getDisplayId());
72: long user2DisplayId = Long
73: .parseLong(((EnrollmentRecord) o2).getUser()
74: .getDisplayId());
75: return (int) (user1DisplayId - user2DisplayId);
76: }
77: };
78:
79: /**
80: * A convenience method for UID-based filtering.
81: */
82: public static Set getStudentUids(Collection enrollments) {
83: Set studentUids = new HashSet();
84: for (Iterator iter = enrollments.iterator(); iter.hasNext();) {
85: EnrollmentRecord enr = (EnrollmentRecord) iter.next();
86: studentUids.add(enr.getUser().getUserUid());
87: }
88: return studentUids;
89: }
90:
91: }
|