jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1526699 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: api/ plugins/memory/ plugins/segment/ plugins/value/ spi/query/
Date Thu, 26 Sep 2013 21:20:05 GMT
Author: jukka
Date: Thu Sep 26 21:20:05 2013
New Revision: 1526699

URL: http://svn.apache.org/r1526699
Log:
OAK-1049: Blobs shouldn't be Comparable

Drop the Comparable interface from Blob

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyStateValue.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyValues.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java?rev=1526699&r1=1526698&r2=1526699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java Thu
Sep 26 21:20:05 2013
@@ -25,7 +25,7 @@ import javax.annotation.Nonnull;
 /**
  * Immutable representation of a binary value of finite length.
  */
-public interface Blob extends Comparable<Blob> {
+public interface Blob {
 
     /**
      * Returns a new stream for this value object. Multiple calls to this
@@ -47,4 +47,5 @@ public interface Blob extends Comparable
      * @return
      */
     byte[] sha256();
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java?rev=1526699&r1=1526698&r2=1526699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
Thu Sep 26 21:20:05 2013
@@ -26,7 +26,6 @@ import com.google.common.base.Optional;
 import com.google.common.hash.HashCode;
 import com.google.common.hash.Hasher;
 import com.google.common.hash.Hashing;
-import com.google.common.io.ByteStreams;
 
 import org.apache.jackrabbit.oak.api.Blob;
 import org.slf4j.Logger;
@@ -109,33 +108,4 @@ public abstract class AbstractBlob imple
         }
     }
 
-    @Override
-    public int compareTo(Blob o) {
-        return compare(getNewStream(), o.getNewStream()) ? 0 : 1;
-    }
-
-    private static boolean compare(InputStream in2, InputStream in1) {
-        try {
-            try {
-                byte[] buf1 = new byte[0x1000];
-                byte[] buf2 = new byte[0x1000];
-
-                while (true) {
-                    int read1 = ByteStreams.read(in1, buf1, 0, 0x1000);
-                    int read2 = ByteStreams.read(in2, buf2, 0, 0x1000);
-                    if (read1 != read2 || !Arrays.equals(buf1, buf2)) {
-                        return false;
-                    } else if (read1 != 0x1000) {
-                        return true;
-                    }
-                }
-            } finally {
-                in1.close();
-                in2.close();
-            }
-        } catch (IOException e) {
-            return false;
-        }
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java?rev=1526699&r1=1526698&r2=1526699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentBlob.java
Thu Sep 26 21:20:05 2013
@@ -20,7 +20,6 @@ import static com.google.common.base.Pre
 
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.plugins.memory.AbstractBlob;
 
 public class SegmentBlob extends AbstractBlob {
@@ -50,17 +49,6 @@ public class SegmentBlob extends Abstrac
     }
 
     @Override
-    public int compareTo(Blob blob) {
-        if (blob instanceof SegmentBlob) {
-            SegmentBlob that = (SegmentBlob) blob;
-            if (recordId.equals(that.recordId)) {
-                return 0;
-            }
-        }
-        return super.compareTo(blob);
-    }
-
-    @Override
     public boolean equals(Object object) {
         if (object instanceof SegmentBlob) {
             SegmentBlob that = (SegmentBlob) object;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java?rev=1526699&r1=1526698&r2=1526699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueImpl.java
Thu Sep 26 21:20:05 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.Calendar;
+
 import javax.jcr.Binary;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -29,6 +30,8 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 
+import com.google.common.base.Objects;
+
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 
@@ -263,7 +266,14 @@ public class ValueImpl implements Value 
     public boolean equals(Object other) {
         if (other instanceof ValueImpl) {
             ValueImpl that = (ValueImpl) other;
-            return compare(propertyState, index, that.propertyState, that.index) == 0;
+            Type<?> type = propertyState.getType();
+            if (type.isArray()) {
+                type = type.getBaseType();
+            }
+            return type.tag() == that.propertyState.getType().tag()
+                    && Objects.equal(
+                            propertyState.getValue(type, index),
+                            that.propertyState.getValue(type, that.index));
         } else {
             return false;
         }
@@ -286,36 +296,4 @@ public class ValueImpl implements Value 
         return getOakString();
     }
 
-    private static int compare(PropertyState p1, int i1, PropertyState p2, int i2) {
-        if (p1.getType().tag() != p2.getType().tag()) {
-            return Integer.signum(p1.getType().tag() - p2.getType().tag());
-        }
-        switch (p1.getType().tag()) {
-            case PropertyType.BINARY:
-                return compare(p1.getValue(Type.BINARY, i1), p2.getValue(Type.BINARY, i2));
-            case PropertyType.DOUBLE:
-                return compare(p1.getValue(Type.DOUBLE, i1), p2.getValue(Type.DOUBLE, i2));
-            case PropertyType.LONG:
-                return compare(p1.getValue(Type.LONG, i1), p2.getValue(Type.LONG, i2));
-            case PropertyType.DECIMAL:
-                return compare(p1.getValue(Type.DECIMAL, i1), p2.getValue(Type.DECIMAL, i2));
-            case PropertyType.DATE:
-                return compareAsDate(p1.getValue(Type.STRING, i1), p2.getValue(Type.STRING,
i2));
-            default:
-                return compare(p1.getValue(Type.STRING, i1), p2.getValue(Type.STRING, i2));
-        }
-    }
-
-    private static <T extends Comparable<T>> int compare(T p1, T p2) {
-        return p1.compareTo(p2);
-    }
-
-    private static int compareAsDate(String p1, String p2) {
-        Calendar c1 = Conversions.convert(p1).toCalendar();
-        Calendar c2 = Conversions.convert(p1).toCalendar();
-        return c1 != null && c2 != null
-                ? c1.compareTo(c2)
-                : p1.compareTo(p2);
-    }
-
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyStateValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyStateValue.java?rev=1526699&r1=1526698&r2=1526699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyStateValue.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyStateValue.java
Thu Sep 26 21:20:05 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.jackrabbit.oak.spi.query;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Calendar;
 import java.util.Iterator;
 
@@ -25,6 +27,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 
+import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Type;
@@ -99,10 +102,11 @@ public class PropertyStateValue implemen
         case PropertyType.LONG:
             return compare(getValue(Type.LONGS), p2.getValue(Type.LONGS));
         case PropertyType.BINARY:
-            return compare(getValue(Type.BINARIES), p2.getValue(Type.BINARIES));
+            return compareBinaries(
+                    getValue(Type.BINARIES), p2.getValue(Type.BINARIES));
         case PropertyType.DATE:
-            return compareAsDate(getValue(Type.STRINGS),
-                    p2.getValue(Type.STRINGS));
+            return compareAsDate(
+                    getValue(Type.STRINGS), p2.getValue(Type.STRINGS));
         default:
             return compare(getValue(Type.STRINGS), p2.getValue(Type.STRINGS));
         }
@@ -127,6 +131,44 @@ public class PropertyStateValue implemen
         return 0;
     }
 
+    private static int compareBinaries(Iterable<Blob> p1, Iterable<Blob> p2)
{
+        Iterator<Blob> i1 = p1.iterator();
+        Iterator<Blob> i2 = p2.iterator();
+        while (i1.hasNext() || i2.hasNext()) {
+            if (!i1.hasNext()) {
+                return 1;
+            }
+            if (!i2.hasNext()) {
+                return -1;
+            }
+            try {
+                InputStream v1 = i1.next().getNewStream();
+                try {
+                    InputStream v2 = i2.next().getNewStream();
+                    try {
+                        while (true) {
+                            int b1 = v1.read();
+                            int b2 = v2.read();
+                            int compare = b1 - b2;
+                            if (compare != 0) {
+                                return compare;
+                            } else if (b1 == -1) {
+                                break;
+                            }
+                        }
+                    } finally {
+                        v2.close();
+                    }
+                } finally {
+                    v1.close();
+                }
+            } catch (IOException e) {
+                throw new RuntimeException("Failed to compare stream values", e);
+            }
+        }
+        return 0;
+    }
+
     private static int compareAsDate(Iterable<String> p1, Iterable<String> p2)
{
         Iterator<String> i1 = p1.iterator();
         Iterator<String> i2 = p2.iterator();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyValues.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyValues.java?rev=1526699&r1=1526698&r2=1526699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyValues.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyValues.java
Thu Sep 26 21:20:05 2013
@@ -18,9 +18,10 @@
  */
 package org.apache.jackrabbit.oak.spi.query;
 
+import static com.google.common.collect.Iterables.contains;
+
 import java.math.BigDecimal;
 import java.net.URI;
-import java.util.Iterator;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -184,20 +185,8 @@ public final class PropertyValues {
 
     }
 
-    private static <T extends Comparable<T>> boolean contains(Iterable<T>
p1,
-            T p2) {
-        Iterator<T> i1 = p1.iterator();
-        while (i1.hasNext()) {
-            int compare = i1.next().compareTo(p2);
-            if (compare == 0) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     // --
-    
+
     /**
      * Converts the given value to a value of the specified target type. The
      * conversion is performed according to the rules described in



Mime
View raw message