1
2
3
4 package com.webstersmalley.mediacollection.model;
5
6 import java.util.Comparator;
7
8 /**
9 */
10 public class SimpleMediaCollectionBeanComparator implements Comparator
11 {
12 private boolean ascending;
13 private int column;
14
15 public SimpleMediaCollectionBeanComparator(boolean ascending, int column)
16 {
17 this.ascending = ascending;
18 this.column = column;
19 }
20
21 public int compare(Object arg0, Object arg1)
22 {
23 if (arg0 == null || arg1 == null)
24 {
25 throw new RuntimeException("Error: comparator can only compare two non null SimpleMediaCollectionBeans");
26 }
27 if (arg0 instanceof SimpleMediaCollectionBean && arg1 instanceof SimpleMediaCollectionBean)
28 {
29 SimpleMediaCollectionBean bean0 = (SimpleMediaCollectionBean) arg0;
30 SimpleMediaCollectionBean bean1 = (SimpleMediaCollectionBean) arg1;
31 if (ascending)
32 {
33 return bean0.getColumn(column).compareTo(bean1.getColumn(column));
34 }
35 else
36 {
37 return bean1.getColumn(column).compareTo(bean0.getColumn(column));
38 }
39 }
40 else
41 {
42 throw new RuntimeException("Error: comparator can only compare two non null SimpleMediaCollectionBeans");
43 }
44 }
45
46 }