jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1428764 - in /jackrabbit/oak/trunk/oak-mk/src: main/java/org/apache/jackrabbit/mk/model/Id.java test/java/org/apache/jackrabbit/mk/model/ test/java/org/apache/jackrabbit/mk/model/IdTest.java
Date Fri, 04 Jan 2013 09:27:15 GMT
Author: stefan
Date: Fri Jan  4 09:27:15 2013
New Revision: 1428764

URL: http://svn.apache.org/viewvc?rev=1428764&view=rev
Log:
OAK-539: Wrong compareTo in micro-kernel Id class

Added:
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/model/
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/model/IdTest.java
Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java?rev=1428764&r1=1428763&r2=1428764&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java (original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java Fri Jan
 4 09:27:15 2013
@@ -113,7 +113,9 @@ public class Id implements Comparable<Id
         
         for (int i = 0; i < len; i++) {
             if (raw[i] != other[i]) {
-                return raw[i] - other[i];
+                final int rawValue = raw[i] & 0xFF; // unsigned value
+                final int otherValue = other[i] & 0xFF; // unsigned value
+                return rawValue - otherValue;
             }
         }
         return raw.length - other.length;

Added: jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/model/IdTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/model/IdTest.java?rev=1428764&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/model/IdTest.java (added)
+++ jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/model/IdTest.java Fri
Jan  4 09:27:15 2013
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.model;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class IdTest {
+
+    @Test
+    public void idCompareToEqualsTest() {
+        final Id id1 = Id.fromString("00000000000002cc");
+        final Id id2 = Id.fromString("00000000000002cc");
+
+        assertTrue(id1 + " should be equals to " + id2, id1.compareTo(id2) == 0);
+    }
+
+    @Test
+    public void idCompareToGreaterThanOneDigitTest() {
+        final Id id1 = Id.fromString("0000000000000007");
+        final Id id2 = Id.fromString("000000000000000c");
+
+        assertTrue(id1 + " should be less than " + id2, id1.compareTo(id2) < 0);
+    }
+
+    @Test
+    public void idCompareToGreaterThanOneByteTest() {
+        final Id id1 = Id.fromString("0000000000000070");
+        final Id id2 = Id.fromString("00000000000000c0");
+
+        assertTrue(id1 + " should be less than " + id2, id1.compareTo(id2) < 0);
+    }
+
+    @Test
+    public void idCompareToGreaterThanTwoBytesTest() {
+        final Id id1 = Id.fromString("0000000000000270");
+        final Id id2 = Id.fromString("00000000000002c0");
+
+        assertTrue(id1 + " should be less than " + id2, id1.compareTo(id2) < 0);
+    }
+}
\ No newline at end of file



Mime
View raw message