1 /**************************************************************************
2 Copyright 2005 Webstersmalley
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 *************************************************************************/
16
17
18
19 package com.webstersmalley.statuslog;
20
21 import java.util.Comparator;
22 import java.util.Date;
23
24 /***
25 * @author Matthew Smalley
26 */
27 public class StatusBeanComparator extends Object implements Comparator
28 {
29
30 private boolean ascending;
31 private int column;
32
33 public StatusBeanComparator(boolean ascending, int column)
34 {
35 this.ascending = ascending;
36 this.column = column;
37 }
38
39 public int compare(Object arg0, Object arg1)
40 {
41 if (arg0 == null || arg1 == null)
42 {
43 throw new RuntimeException("Error: comparator can only compare two non null SimpleMediaCollectionBeans");
44 }
45 if (arg0 instanceof StatusBean && arg1 instanceof StatusBean)
46 {
47 Comparable val0 = (Comparable)((StatusBean)arg0).getColumnValue(column);
48 Comparable val1 = (Comparable)((StatusBean)arg1).getColumnValue(column);
49 if (ascending)
50 {
51 return val0.compareTo(val1);
52 }
53 else
54 {
55 return val1.compareTo(val0);
56 }
57 }
58 else
59 {
60 throw new RuntimeException("Error: comparator can only compare two non null StatusBean");
61 }
62 }
63
64 }