// Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//   
//   /**
//    * An empty {@code byte} array.
//    */
//   public static final byte[] EMPTY = new byte[0];
// 
//   private Bytes() {}
//   
//   /**
//    * Compares the given {@code byte} values.
//    * 
//    * @see Comparable
//    * @see Comparator
//    */
//   public static int compare(byte b1, byte b2) {
//     if (b1 < b2) {
//       return -1;
//     } else if (b2 < b1) {
//       return 1;
//     }
//     return 0;
//   }
//   
//   /**
//    * Compares the given {@code byte}s as unsigned values.
//    * 
//    * @see Comparable
//    * @see Comparator
//    */
//   public static int compareUnsigned(int b1, int b2) {
//     return (b1 & 0xFF) - (b2 & 0xFF);
//   }
// }


import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Bytes;
/*
 * Copyright 2010-2012 Roger Kapsi
 *
 *   Licensed 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.ardverk.utils;



/**
 * A {@link Comparator} for byte-arrays.
 */
public class ByteArrayComparator implements Comparator<byte[]>, Serializable {

  private static final long serialVersionUID = 6625000716332463624L;

  public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
  
  @Override
  public int compare(byte[] o1, byte[] o2) {
    if (o1.length != o2.length) {
      return o1.length - o2.length;
    }
    
    for (int i = 0; i < o1.length; i++) {
// Path: src/main/java/org/ardverk/lang/Bytes.java
// public class Bytes {
//   
//   /**
//    * An empty {@code byte} array.
//    */
//   public static final byte[] EMPTY = new byte[0];
// 
//   private Bytes() {}
//   
//   /**
//    * Compares the given {@code byte} values.
//    * 
//    * @see Comparable
//    * @see Comparator
//    */
//   public static int compare(byte b1, byte b2) {
//     if (b1 < b2) {
//       return -1;
//     } else if (b2 < b1) {
//       return 1;
//     }
//     return 0;
//   }
//   
//   /**
//    * Compares the given {@code byte}s as unsigned values.
//    * 
//    * @see Comparable
//    * @see Comparator
//    */
//   public static int compareUnsigned(int b1, int b2) {
//     return (b1 & 0xFF) - (b2 & 0xFF);
//   }
// }


// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
import java.io.Serializable;
import java.util.Comparator;
import org.ardverk.lang.Bytes;

/*
 * Copyright 2010-2012 Roger Kapsi
 *
 *   Licensed 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.ardverk.utils;



/**
 * A {@link Comparator} for byte-arrays.
 */
public class ByteArrayComparator implements Comparator<byte[]>, Serializable {

  private static final long serialVersionUID = 6625000716332463624L;

  public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
  
  @Override
  public int compare(byte[] o1, byte[] o2) {
    if (o1.length != o2.length) {
      return o1.length - o2.length;
    }
    
    for (int i = 0; i < o1.length; i++) {
      int diff = Bytes.compareUnsigned(o1[i], o2[i]);