Java Array Compare arrayCompare(final T[] a, final T[] b)

Here you can find the source of arrayCompare(final T[] a, final T[] b)

Description

array Compare

License

Open Source License

Declaration

public static final <T extends Object & Comparable<? super T>> int arrayCompare(final T[] a, final T[] b) 

Method Source Code

//package com.java2s;
// This package is part of the Spiralcraft project and is licensed under

public class Main {
    public static final <T extends Object & Comparable<? super T>> int arrayCompare(final T[] a, final T[] b) {
        // Supress unchecked generics- we're in meta-land here

        if (a == b) {
            return 0;
        }/*from   w ww  .j av a  2  s .  com*/
        if (a == null && b != null) {
            return -1;
        }
        if (b == null && a != null) {
            return 1;
        }

        for (int i = 0; i < a.length; i++) {
            if (i == b.length) {
                return 1;
            }

            if (a[i] != b[i]) {
                if (a[i] == null && b[i] != null) {
                    return -1;
                }
                if (b[i] == null && a[i] != null) {
                    return 1;
                }
                int result = a[i].compareTo(b[i]);
                if (result != 0) {
                    return result;
                }
            }
        }
        if (b.length > a.length) {
            return -1;
        }
        return 0;
    }
}

Related

  1. areEquals(byte[] g1, byte[] g2)
  2. arrayCompare(byte src[], short srcOff, byte dest[], short destOff, short length)
  3. arrayCompare(byte[] a, byte[] a2)
  4. arrayCompare(byte[] a1, byte[] a2)
  5. arrayCompare(byte[] b1, byte[] b2)
  6. arrayCompare(int[] arr1, int[] arr2)
  7. arrayCompareLex(byte[] a, byte[] b)
  8. arrayContentsEq(Object[] a1, Object[] a2)
  9. createStainMask(float[] redOD, float[] greenOD, float[] blueOD, double stainThreshold, boolean excludeGray, boolean excludeUncommonColors, boolean[] mask)