1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.myfaces.custom.schedule.util;
21
22 import java.io.Serializable;
23 import java.util.Comparator;
24
25 import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
26
27 /**
28 * <p>
29 * Comparator for ScheduleEntry objects. This is needed for correctly
30 * rendering the schedule.
31 * </p>
32 *
33 * @author Jurgen Lust (latest modification by $Author: schof $)
34 * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
35 * @version $Revision: 381473 $
36 */
37 public class ScheduleEntryComparator implements Comparator, Serializable
38 {
39 private static final long serialVersionUID = 6863061256811196989L;
40
41 //~ Methods ----------------------------------------------------------------
42
43 /**
44 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
45 */
46 public int compare(Object o1, Object o2)
47 {
48 if (o1 instanceof ScheduleEntry && o2 instanceof ScheduleEntry)
49 {
50 ScheduleEntry entry1 = (ScheduleEntry) o1;
51 ScheduleEntry entry2 = (ScheduleEntry) o2;
52
53 int returnint = entry1.getStartTime().compareTo(
54 entry2.getStartTime());
55 if (returnint == 0)
56 {
57 returnint = entry1.getEndTime().compareTo(entry2.getEndTime());
58 }
59 if (returnint == 0)
60 {
61 returnint = entry1.getId().compareTo(entry2.getId());
62 }
63
64 return returnint;
65 }
66
67 return 1;
68 }
69 }
70 //The End