package org.ethereum.db;

import com.google.common.primitives.UnsignedBytes;

import java.util.Arrays;
import java.util.Comparator;

/**
 * www.ethereumJ.com
 *
 * @author: Roman Mandeleil
 * Created on: 11/06/2014 15:02
 */

public class ByteArrayWrapper implements Comparable{

    private final byte[] data;

    public ByteArrayWrapper(byte[] data)
    {
        if (data == null)
        {
            throw new NullPointerException();
        }
        this.data = data;
    }

    @Override
    public boolean equals(Object other)
    {
        if (!(other instanceof ByteArrayWrapper))
        {
            return false;
        }
        return Arrays.equals(data, ((ByteArrayWrapper)other).data);
    }

    @Override
    public int hashCode()
    {
        return Arrays.hashCode(data);
    }


    public byte[] getData() {
        return data;
    }

    @Override
    public int compareTo(Object second) {

        Comparator<byte[]> comparator = UnsignedBytes.lexicographicalComparator();

        return comparator.compare(this.data, ((ByteArrayWrapper)second).getData());
    }
}

@@ -23,60 +23,8 @@
 b;%0A%0A
-import com.google.common.primitives.UnsignedBytes;%0A%0A
 impo
@@ -48,35 +48,53 @@
 ys;%0A
+%0A
 import 
-java.util.
+org.ethereum.util.FastByte
 Compar
-ator
+isons
 ;%0A%0A/
@@ -119,16 +119,17 @@
 J.com%0A *
+ 
 %0A * @aut
@@ -148,19 +148,16 @@
 andeleil
-%0A *
  Created
@@ -182,17 +182,16 @@
 :02%0A */%0A
-%0A
 public c
@@ -233,23 +233,39 @@
 mparable
-%7B%0A%0A    
+%3CByteArrayWrapper%3E %7B%0A%0A%09
 private 
@@ -284,20 +284,17 @@
  data;%0A%0A
-    
+%09
 public B
@@ -321,31 +321,21 @@
 %5B%5D data)
-%0A    %7B%0A        
+ %7B%0A%09%09
 if (data
@@ -343,39 +343,22 @@
 == null)
-%0A        %7B%0A            
+ %7B%0A%09%09%09
 throw ne
@@ -387,69 +387,37 @@
 ();%0A
-        %7D%0A        this.data = data;%0A    %7D%0A%0A    @Override%0A    
+%09%09%7D%0A%09%09this.data = data;%0A%09%7D%0A%0A%09
 publ
@@ -447,31 +447,21 @@
 t other)
-%0A    %7B%0A        
+ %7B%0A%09%09
 if (!(ot
@@ -497,89 +497,52 @@
 er))
-%0A        %7B%0A            return false;%0A        %7D%0A        return Arrays.equals(data,
+ %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09byte%5B%5D otherData =
  ((B
@@ -561,33 +561,141 @@
 per)
+ 
 other).
-d
+getD
 ata
+(
 );%0A
-    %7D%0A%0A    
+%09%09return FastByteComparisons.compareTo(%0A%09%09%09%09data, 0, data.length, %0A%09%09%09%09otherData, 0, otherData.length) == 0;%0A%09%7D%0A%0A%09
 @Ove
@@ -692,36 +692,33 @@
 %0A%09%7D%0A%0A%09@Override%0A
-    
+%09
 public int hashC
@@ -726,23 +726,13 @@
 de()
-%0A    %7B%0A        
+ %7B%0A%09%09
 retu
@@ -761,78 +761,13 @@
 a);%0A
-    %7D%0A%0A%0A    public byte%5B%5D getData() %7B%0A        return data;%0A    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Ove
@@ -772,20 +772,17 @@
 verride%0A
-    
+%09
 public i
@@ -798,198 +798,186 @@
 eTo(
-Object second) %7B%0A%0A        Comparator%3Cbyte%5B%5D%3E comparator = UnsignedBytes.lexicographicalComparator();%0A%0A        return comparator.compare(this.data, ((ByteArrayWrapper)second).getData());%0A    
+ByteArrayWrapper o) %7B%0A%09%09return FastByteComparisons.compareTo(%0A%09%09%09%09data, 0, data.length, %0A%09%09%09%09o.getData(), 0, o.getData().length);%0A%09%7D%0A%09%0A%09public byte%5B%5D getData() %7B%0A%09%09return data;%0A%09
 %7D%0A%7D%0A

Replace equals and compareTo with FastByteComparison