/*
Copyright (c) 2013, Colorado State University
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are
disclaimed. In no event shall the copyright holder or contributors be liable for
any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused and on
any theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.
*/

package galileo.dataset.feature;

public class ByteArray implements Comparable<ByteArray> {

    private byte[] array;

    public ByteArray(byte[] bytes) {
        this.array = bytes;
    }

    public byte[] getBytes() {
        return array;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }

        ByteArray that = (ByteArray) obj;
        return (compareTo(that) == 0);
    }

    @Override
    public int compareTo(ByteArray otherBytes) {
        int size1 = this.array.length;
        int size2 = otherBytes.array.length;

        for (int i = 0; i < size1 && i < size2; ++i) {
            int thisValue = this.array[i] & 0xFF;
            int thatValue = otherBytes.array[i] & 0xFF;

            if (thisValue != thatValue) {
                return thisValue - thatValue;
            }
        }

        /* The arrays have been the same thus far.  If they are a different
         * length then do the comparison based on that, otherwise the following
         * will return 0 (arrays are the same).  */
        return this.array.length - otherBytes.array.length;
    }
}

@@ -1346,16 +1346,42 @@
 ature;%0A%0A
+import java.util.Arrays;%0A%0A
 public c
@@ -1582,32 +1582,216 @@
 n array;%0A    %7D%0A%0A
+    @Override%0A    public int hashCode() %7B%0A        final int prime = 31;%0A        int result = 1;%0A        result = prime * result + Arrays.hashCode(array);%0A        return result;%0A    %7D%0A%0A
     @Override%0A  
@@ -1882,33 +1882,32 @@
 true;%0A        %7D%0A
-%0A
         if (obj 
@@ -1945,33 +1945,32 @@
 alse;%0A        %7D%0A
-%0A
         if (getC
@@ -2025,33 +2025,32 @@
 alse;%0A        %7D%0A
-%0A
         ByteArra
@@ -2051,20 +2051,21 @@
 teArray 
+o
 th
-at
+er
  = (Byte
@@ -2088,37 +2088,105 @@
     
-return (compareTo(that) == 0)
+if (!Arrays.equals(array, other.array)) %7B%0A            return false;%0A        %7D%0A        return true
 ;%0A  

Change equals() behavior, add hashCode()