📄 datetimecomparator.java
字号:
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Exoffice Technologies. For written permission,
* please contact info@exolab.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Exoffice Technologies. Exolab is a registered
* trademark of Exoffice Technologies.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: DateTimeComparator.java,v 1.4 2003/08/17 01:32:25 tanderson Exp $
*
* Date Author Changes
* $Date jimm Created
*/
package org.exolab.jms.persistence;
import java.util.Comparator;
import javax.jms.JMSException;
/**
* A comparator class that iplements a date/time comparison for
* PersistentMessage
*
* @version $Revision: 1.4 $ $Date: 2003/08/17 01:32:25 $
* @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
*/
public class DateTimeComparator implements Comparator {
/**
* Default constructor does nothing.
*
*/
public DateTimeComparator() {
}
/**
* Implements the compare operator.
* Compares its two arguments for order. Returns a negative integer, zero,
* or a positive integer as the first argument is less than, equal to,
* or greater than the second.
*
* @param Object object 1 to compare
* @param Object object 2 ro compare to.
* @return int returns -1, 0, 1 if the first argument is less than,
* equal to, or greater than the second.
* @exception ClassCastException if object types are unknown
*
*/
public int compare(Object o1, Object o2) throws ClassCastException {
int status;
if (o1 == null && o2 == null)
status = 0;
else if (o1 == null)
status = -1;
else if (o2 == null)
status = 1;
else if (o1 instanceof PersistentMessage &&
o2 instanceof PersistentMessage) {
PersistentMessage m1 = (PersistentMessage) o1;
PersistentMessage m2 = (PersistentMessage) o2;
long t1;
long t2;
try {
t1 = m1.getMessage().getJMSTimestamp();
} catch (JMSException e1) {
t1 = 0;
}
try {
t2 = m2.getMessage().getJMSTimestamp();
} catch (JMSException e2) {
t2 = 0;
}
if (t1 < t2)
status = -1;
else if (t1 == t2)
status = 0;
else
status = 1;
} else {
throw new ClassCastException("Unknown Object");
}
return status;
}
/**
* Indicates whether some other object is "equal to" this Comparator.
* This method must obey the general contract of Object.equals(Object).
*
* @param Object the object to compare to
* @return boolean true iff objects are equal
*
*/
public boolean equals(Object ob) {
boolean status = false;
if (ob instanceof DateTimeComparator) status = true;
return status;
}
} // End DateTimeComparator
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -