Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 10737 invoked from network); 14 Mar 2006 17:08:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 14 Mar 2006 17:08:23 -0000 Received: (qmail 15195 invoked by uid 500); 14 Mar 2006 17:08:20 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 15147 invoked by uid 500); 14 Mar 2006 17:08:19 -0000 Mailing-List: contact axis-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-dev@ws.apache.org Received: (qmail 15136 invoked by uid 99); 14 Mar 2006 17:08:19 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Mar 2006 09:08:19 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Mar 2006 09:08:18 -0800 Received: from ajax (localhost.localdomain [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id C8CD8D49F9 for ; Tue, 14 Mar 2006 17:07:57 +0000 (GMT) Message-ID: <1330012135.1142356077627.JavaMail.jira@ajax> Date: Tue, 14 Mar 2006 17:07:57 +0000 (GMT) From: "Alan M. Feldstein (JIRA)" To: axis-dev@ws.apache.org Subject: [jira] Commented: (AXIS2-488) UnsignedLong would be improved by implementing the Comparable interface In-Reply-To: <1715819456.1142191441226.JavaMail.jira@ajax> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/AXIS2-488?page=comments#action_12370372 ] Alan M. Feldstein commented on AXIS2-488: ----------------------------------------- Index: modules/adb/src/org/apache/axis2/databinding/types/UnsignedLong.java =================================================================== --- modules/adb/src/org/apache/axis2/databinding/types/UnsignedLong.java (revision 385823) +++ modules/adb/src/org/apache/axis2/databinding/types/UnsignedLong.java (working copy) @@ -22,7 +22,7 @@ * * @see XML Schema 3.3.21 */ -public class UnsignedLong extends java.lang.Number { +public class UnsignedLong extends java.lang.Number implements Comparable { private static final long serialVersionUID = -5919942584284897583L; @@ -117,4 +117,73 @@ return lValue.floatValue(); } + public int compareTo( Object o ) + throws ClassCastException, NullPointerException + { + int retVal = 0; // arbitrary default value in case of exception; required return value in case this object is equal to the specified object + + try { + if ( o == null ) + { + throw new NullPointerException( "Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException." ); + } + if ( ! ( o instanceof UnsignedLong ) ) + { + throw new ClassCastException( "The argument is not an UnsignedLong." ); + } + // Only need to change retVal if this object is not equal to the specified object. + if ( ! equals( o ) ) + { + long thisLong = longValue(); + long thatLong = ( (UnsignedLong) o ).longValue(); + boolean isLessThan; // This is less than that. + + // Prepare the most significant half of the data for comparison. + // The shift distance can be any number from 1 to 32 inclusive (1 is probably fastest). + // A shift distance of one is sufficient to move the significant data off of the sign bit, allowing for a signed comparison of positive numbers (i.e. an unsigned comparison). + long thisHalfLong = ( thisLong & 0xffffffff00000000L ) >>> 1; + long thatHalfLong = ( thatLong & 0xffffffff00000000L ) >>> 1; + + if ( thisHalfLong == thatHalfLong ) + { + // We must also look at the least significant half of the data. + + // Prepare the least significant half of the data for comparison. + thisHalfLong = ( thisLong & 0x00000000ffffffffL ); + thatHalfLong = ( thatLong & 0x00000000ffffffffL ); + + // We already know that the data is not equal. + isLessThan = thisHalfLong < thatHalfLong; + } + else + { + // The answer is in the most significant half of the data. + isLessThan = thisHalfLong < thatHalfLong; + } + + if ( isLessThan ) + { + retVal = -1; // Returns a negative integer as this object is less than than the specified object. + } + else + { + retVal = 1; // Returns a positive integer as this object is greater than than the specified object. + } + } + } + + catch ( NullPointerException nullPointerException ) { + throw nullPointerException; + } + + catch ( ClassCastException classCastException ) { + throw classCastException; + } + + finally { + return retVal; + } + + } + } > UnsignedLong would be improved by implementing the Comparable interface > ----------------------------------------------------------------------- > > Key: AXIS2-488 > URL: http://issues.apache.org/jira/browse/AXIS2-488 > Project: Apache Axis 2.0 (Axis2) > Type: Improvement > Components: databinding > Versions: 0.94 > Environment: Java 2 Platform SE 5.0 > java.util.TreeSet< UnsignedLong > > Reporter: Alan M. Feldstein > Priority: Minor > > All elements inserted into the set must implement the Comparable interface. > Workaround is to use > org.apache.axis.types.UnsignedLong -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira