Source code: com/fm/rss/comparator/rssDateComparator.java
1 /****************************************************************************
2 * Copyright (c) 2003 Andrew Duka | aduka@users.sourceforge.net
3 * All right reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 ****************************************************************************/
11 package com.fm.rss.comparator;
12
13 import com.fm.rss.rssItem;
14
15 /**
16 * Compares RSS items by creation date
17 *
18 * @author Andrew Duka
19 */
20 public class rssDateComparator extends RssItemComparator
21 {
22 boolean isReverse;
23
24 public rssDateComparator() {
25 isReverse = false;
26 }
27
28 public rssDateComparator(boolean isR) {
29 isReverse = isR;
30 }
31
32 public int compare(Object o1, Object o2) {
33 if (o1 == o2)
34 return 0;
35
36 if ((o1 == null) & (o2 != null))
37 return -1;
38
39 if ((o2 == null) & (o1 != null))
40 return 1;
41
42 if ((o1 instanceof rssItem) & !(o2 instanceof rssItem))
43 return 1;
44
45 if (!(o1 instanceof rssItem) & (o2 instanceof rssItem))
46 return -1;
47
48 // reversing results if isRevers true (returnig +1 instead of -1 and e.t.c)
49 if (isReverse)
50 return -(((rssItem) o1).getDateCreated().compareTo(((rssItem) o2).getDateCreated()));
51
52 return ((rssItem) o1).getDateCreated().compareTo(((rssItem) o2).getDateCreated());
53
54 }
55
56 public boolean equals(Object o) {
57 return (o == this) ? true : false;
58 }
59 }