01: //
02: // Informa -- RSS Library for Java
03: // Copyright (c) 2002 by Niko Schmuck
04: //
05: // Niko Schmuck
06: // http://sourceforge.net/projects/informa
07: // mailto:niko_schmuck@users.sourceforge.net
08: //
09: // This library is free software.
10: //
11: // You may redistribute it and/or modify it under the terms of the GNU
12: // Lesser General Public License as published by the Free Software Foundation.
13: //
14: // Version 2.1 of the license should be included with this distribution in
15: // the file LICENSE. If the license is not included with this distribution,
16: // you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17: // or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18: // MA 02139 USA.
19: //
20: // This library is distributed in the hope that it will be useful,
21: // but WITHOUT ANY WARRANTY; without even the implied waranty of
22: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23: // Lesser General Public License for more details.
24: //
25: // $Id: PriorityComparator.java,v 1.1 2004/08/23 14:39:26 spyromus Exp $
26: //
27:
28: package de.nava.informa.utils.poller;
29:
30: import de.nava.informa.utils.toolkit.ChannelRecord;
31:
32: import java.util.Comparator;
33:
34: /**
35: * Comparator for <code>ChannelRecord</code> class. Uses priority setting to decide which
36: * record goes first.
37: *
38: * @author Aleksey Gureev (spyromus@noizeramp.com)
39: */
40: public class PriorityComparator implements Comparator {
41: /**
42: * Compares its two arguments for order. Returns a negative integer,
43: * zero, or a positive integer as the first argument is less than, equal
44: * to, or greater than the second.<p>
45: *
46: * @param o1 the first object to be compared.
47: * @param o2 the second object to be compared.
48: * @return a negative integer, zero, or a positive integer as the
49: * first argument is less than, equal to, or greater than the
50: * second.
51: * @throws ClassCastException if the arguments' types prevent them from
52: * being compared by this Comparator.
53: */
54: public final int compare(Object o1, Object o2) {
55: final ChannelRecord r1 = (ChannelRecord) o1;
56: final ChannelRecord r2 = (ChannelRecord) o2;
57:
58: final int p1 = r1.getPriority();
59: final int p2 = r2.getPriority();
60:
61: int result = 0;
62:
63: if (p1 < p2) {
64: result = -1;
65: } else if (p2 > p1) {
66: result = 1;
67: }
68:
69: return result;
70: }
71: }
|