Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 18875 invoked from network); 21 Dec 2006 14:29:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Dec 2006 14:29:00 -0000 Received: (qmail 4749 invoked by uid 500); 21 Dec 2006 14:29:07 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 4701 invoked by uid 500); 21 Dec 2006 14:29:07 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 4692 invoked by uid 99); 21 Dec 2006 14:29:07 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Dec 2006 06:29:07 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Dec 2006 06:28:59 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 25BBB1A981A; Thu, 21 Dec 2006 06:28:10 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r489369 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/uuid/UUID.java Date: Thu, 21 Dec 2006 14:28:09 -0000 To: commits@jackrabbit.apache.org From: tripod@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061221142810.25BBB1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tripod Date: Thu Dec 21 06:28:09 2006 New Revision: 489369 URL: http://svn.apache.org/viewvc?view=rev&rev=489369 Log: - JCR-687 UUID compareTo and hashCode - Adjusting source formatting Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/uuid/UUID.java Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/uuid/UUID.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/uuid/UUID.java?view=diff&rev=489369&r1=489368&r2=489369 ============================================================================== --- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/uuid/UUID.java (original) +++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/uuid/UUID.java Thu Dec 21 06:28:09 2006 @@ -85,7 +85,7 @@ * * @param input the datainput with 16 bytes to read in from. * @throws java.io.IOException exception if there is an IO problem also - * argument must contain 16 bytes. + * argument must contain 16 bytes. */ public UUID(DataInput input) throws IOException { msb = input.readLong(); @@ -96,10 +96,10 @@ * Constructs a UUID from two long values in most significant byte, and * least significant bytes order. * - * @param mostSignificant the most significant 8 bytes of the uuid to be - * constructed. + * @param mostSignificant the most significant 8 bytes of the uuid to be + * constructed. * @param leastSignificant the least significant 8 bytes of the uuid to be - * constructed. + * constructed. */ public UUID(long mostSignificant, long leastSignificant) { msb = mostSignificant; @@ -111,7 +111,7 @@ * * @param uuidString the String representing a UUID to construct this UUID * @throws IllegalArgumentException String must be a properly formatted UUID - * string + * string */ public UUID(String uuidString) throws IllegalArgumentException { // e.g. f81d4fae-7dec-11d0-a765-00a0c91e6bf6 @@ -122,22 +122,22 @@ } long[] words = new long[2]; int b = 0; - for (int i=0; i='a' && c<='f') { - h+=9; - } else if (c<'0' || c>'9') { + if (c >= 'a' && c <= 'f') { + h += 9; + } else if (c < '0' || c > '9') { throw new IllegalArgumentException(); } words[b] = words[b] << 4 | h; @@ -154,7 +154,7 @@ * @return Returns a UUID or null if the formatted string could * not be parsed. * @throws IllegalArgumentException the String must be a properly formatted - * UUID String. + * UUID String. */ public static UUID fromString(String uuidString) throws IllegalArgumentException { @@ -169,13 +169,13 @@ */ public String toString() { char[] chars = new char[UUID_FORMATTED_LENGTH]; - for (int i = 60, j = 0; i >= 0; i-=4) { + for (int i = 60, j = 0; i >= 0; i -= 4) { chars[j++] = hexDigits[(int) (msb >> i) & 0x0f]; if (j == 8 || j == 13 || j == 18) { chars[j++] = '-'; } } - for (int i = 60, j = 19; i >= 0; i-=4) { + for (int i = 60, j = 19; i >= 0; i -= 4) { chars[j++] = hexDigits[(int) (lsb >> i) & 0x0f]; if (j == 23) { chars[j++] = '-'; @@ -203,20 +203,23 @@ * @see Object#hashCode() */ public int hashCode() { - int result; - result = (int) (lsb ^ (lsb >>> 32)); - result = 29 * result + (int) (msb ^ (msb >>> 32)); - return result; + return (int) ((msb >>> 32) ^ msb ^ (lsb >>> 32) ^ lsb); } /** - * Compares two UUID's for equality + * Compares two UUIDs. * * @see Comparable#compareTo(Object) */ public int compareTo(Object compareTo) throws ClassCastException { final UUID u = (UUID) compareTo; - return (int) (u.msb == msb ? lsb - u.lsb : msb - u.msb); + if (msb == u.msb) { + if (lsb == u.lsb) { + return 0; + } + return lsb > u.lsb ? 1 : -1; + } + return msb > u.msb ? 1 : -1; } /**