[ 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 <a href="http://www.w3.org/TR/xmlschema-2/#unsignedLong">XML Schema 3.3.21</a> */ -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
