1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: DateTimeComparator.java,v 1.4 2003/08/17 01:32:25 tanderson Exp $
44 *
45 * Date Author Changes
46 * $Date jimm Created
47 */
48
49
50 package org.exolab.jms.persistence;
51
52 import java.util.Comparator;
53
54 import javax.jms.JMSException;
55
56
57 /***
58 * A comparator class that iplements a date/time comparison for
59 * PersistentMessage
60 *
61 * @version $Revision: 1.4 $ $Date: 2003/08/17 01:32:25 $
62 * @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
63 */
64 public class DateTimeComparator implements Comparator {
65
66 /***
67 * Default constructor does nothing.
68 *
69 */
70 public DateTimeComparator() {
71
72 }
73
74
75 /***
76 * Implements the compare operator.
77 * Compares its two arguments for order. Returns a negative integer, zero,
78 * or a positive integer as the first argument is less than, equal to,
79 * or greater than the second.
80 *
81 * @param Object object 1 to compare
82 * @param Object object 2 ro compare to.
83 * @return int returns -1, 0, 1 if the first argument is less than,
84 * equal to, or greater than the second.
85 * @exception ClassCastException if object types are unknown
86 *
87 */
88 public int compare(Object o1, Object o2) throws ClassCastException {
89 int status;
90
91 if (o1 == null && o2 == null)
92 status = 0;
93 else if (o1 == null)
94 status = -1;
95 else if (o2 == null)
96 status = 1;
97 else if (o1 instanceof PersistentMessage &&
98 o2 instanceof PersistentMessage) {
99 PersistentMessage m1 = (PersistentMessage) o1;
100 PersistentMessage m2 = (PersistentMessage) o2;
101 long t1;
102 long t2;
103
104 try {
105 t1 = m1.getMessage().getJMSTimestamp();
106 } catch (JMSException e1) {
107 t1 = 0;
108 }
109 try {
110 t2 = m2.getMessage().getJMSTimestamp();
111 } catch (JMSException e2) {
112 t2 = 0;
113 }
114
115 if (t1 < t2)
116 status = -1;
117 else if (t1 == t2)
118 status = 0;
119 else
120 status = 1;
121 } else {
122 throw new ClassCastException("Unknown Object");
123 }
124 return status;
125 }
126
127
128 /***
129 * Indicates whether some other object is "equal to" this Comparator.
130 * This method must obey the general contract of Object.equals(Object).
131 *
132 * @param Object the object to compare to
133 * @return boolean true iff objects are equal
134 *
135 */
136 public boolean equals(Object ob) {
137 boolean status = false;
138
139 if (ob instanceof DateTimeComparator) status = true;
140
141 return status;
142 }
143
144
145 } // End DateTimeComparator
This page was automatically generated by Maven