001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/api/src/java/org/theospi/portfolio/matrix/model/EvaluationContentComparator.java $
003: * $Id: EvaluationContentComparator.java 18220 2006-11-17 21:57:46Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.matrix.model;
021:
022: import java.util.Comparator;
023:
024: import org.theospi.portfolio.shared.model.EvaluationContentWrapper;
025:
026: public class EvaluationContentComparator implements Comparator {
027:
028: public static final String SORT_DATE = "date";
029: public static final String SORT_OWNER = "owner";
030: public static final String SORT_TITLE = "title";
031: public static final String SORT_TYPE = "type";
032: public static final String SORT_SITE = "site";
033:
034: // the criteria
035: private String criteria = null;
036:
037: // the criteria - asc
038: private boolean asc = true;
039:
040: /**
041: * constructor
042: * @param criteria The sort criteria string
043: * @param asc The sort order string. "true" if ascending; "false" otherwise.
044: */
045: public EvaluationContentComparator(String criteria, boolean asc) {
046: this .criteria = criteria;
047: this .asc = asc;
048:
049: } // constructor
050:
051: /**
052: * implementing the compare function
053: * @param o1 The first object
054: * @param o2 The second object
055: * @return The compare result. 1 is o1 < o2; -1 otherwise
056: */
057: public int compare(Object o1, Object o2) {
058: int result = -1;
059:
060: if (criteria.equals(SORT_TITLE)) {
061: // sorted by the discussion message subject
062: result = ((EvaluationContentWrapper) o1).getTitle()
063: .compareToIgnoreCase(
064: ((EvaluationContentWrapper) o2).getTitle());
065: }
066:
067: else if (criteria.equals(SORT_DATE)) {
068: // sorted by the date
069: if (((EvaluationContentWrapper) o1).getSubmittedDate()
070: .before(
071: ((EvaluationContentWrapper) o2)
072: .getSubmittedDate())) {
073: result = -1;
074: } else {
075: result = 1;
076: }
077: } else if (criteria.equals(SORT_OWNER)) {
078: // sorted by the owner
079: result = ((EvaluationContentWrapper) o1).getOwner()
080: .getSortName().compareToIgnoreCase(
081: ((EvaluationContentWrapper) o2).getOwner()
082: .getSortName());
083: } else if (criteria.equals(SORT_TYPE)) {
084: // sorted by the owner
085: result = ((EvaluationContentWrapper) o1).getEvalType()
086: .compareToIgnoreCase(
087: ((EvaluationContentWrapper) o2)
088: .getEvalType());
089: } else if (criteria.equals(SORT_SITE)) {
090: // sorted by the site
091: result = ((EvaluationContentWrapper) o1).getSiteTitle()
092: .compareToIgnoreCase(
093: ((EvaluationContentWrapper) o2)
094: .getSiteTitle());
095: }
096:
097: // sort ascending or descending
098: if (!asc) {
099: result = -result;
100: }
101: return result;
102:
103: } // compare
104:
105: }
|