KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > util > collection > NewsComparator


1  /*
2  -- GeiNuke --
3 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
4  http://www.hostingjava.it/-geinuke/
5
6 This file is part of GeiNuke.
7
8     GeiNuke is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     GeiNuke is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with GeiNuke; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */

22 package com.geinuke.util.collection;
23
24 import java.util.Comparator JavaDoc;
25
26 import com.geinuke.vo.NewsVO;
27
28
29
30 public class NewsComparator implements Comparator JavaDoc{
31     public static int ASC=0;
32     public static int DESC=0;
33     protected int ord=-1;
34
35     public NewsComparator(){
36         super();
37         this.ord=DESC;
38     }
39
40     public NewsComparator(int o){
41         super();
42         this.ord=o;
43     }
44
45     public int compare(Object JavaDoc first, Object JavaDoc second) {
46         NewsVO f=(NewsVO)first;
47         NewsVO s=(NewsVO)second;
48         if(this.ord==DESC)
49             return (new Long JavaDoc(s.getTime())).compareTo( new Long JavaDoc(f.getTime()) );
50         else
51             return (new Long JavaDoc(f.getTime())).compareTo( new Long JavaDoc(s.getTime()) );
52     }
53 }
54
Popular Tags