01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/podcasts/tags/sakai_2-4-1/podcasts-impl/impl/src/java/org/sakaiproject/component/app/podcasts/PodcastComparator.java $
03: * $Id: PodcastComparator.java 14725 2006-09-15 16:01:17Z lance@indiana.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 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.component.app.podcasts;
21:
22: import java.util.Comparator;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.sakaiproject.content.api.ContentResource;
27: import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
28: import org.sakaiproject.entity.api.EntityPropertyTypeException;
29: import org.sakaiproject.time.api.Time;
30:
31: public class PodcastComparator implements Comparator {
32:
33: private Log LOG = LogFactory.getLog(PodcastServiceImpl.class);
34:
35: private String m_property = null;
36:
37: private boolean m_ascending = true;
38:
39: /**
40: * Construct.
41: *
42: * @param property
43: * The property name used for the sort.
44: * @param asc
45: * true if the sort is to be ascending (false for descending).
46: */
47: public PodcastComparator(String property, boolean ascending) {
48: m_property = property;
49: m_ascending = ascending;
50:
51: } // PodcastComparator
52:
53: public int compare(Object o1, Object o2) {
54: int rv = 0;
55:
56: try {
57: Time t1 = ((ContentResource) o1).getProperties()
58: .getTimeProperty(m_property);
59: Time t2 = ((ContentResource) o2).getProperties()
60: .getTimeProperty(m_property);
61:
62: rv = t1.compareTo(t2);
63:
64: if (!m_ascending)
65: rv = -rv;
66:
67: } catch (EntityPropertyTypeException ignore) {
68: LOG
69: .warn("EntityPropertyTypeException while comparing podcast dates. "
70: + ignore.getMessage());
71:
72: } catch (EntityPropertyNotDefinedException ignore) {
73: LOG
74: .warn("EntityPropertyNotDefinedException while comparing podcast dates. "
75: + ignore.getMessage());
76:
77: }
78:
79: return rv;
80: }
81: }
|