Example usage for java.util Arrays equals

List of usage examples for java.util Arrays equals

Introduction

In this page you can find the example usage for java.util Arrays equals.

Prototype

public static boolean equals(Object[] a, Object[] a2) 

Source Link

Document

Returns true if the two specified arrays of Objects are equal to one another.

Usage

From source file:Main.java

public static boolean boeIsUnicode(byte[] boe) {
    if (null == boe || boe.length < 2) {
        return false;
    }//from   w w w.jav a  2 s .co  m
    return Arrays.equals(UNICODE_BOE, boe);
}

From source file:Main.java

public static <T> boolean isListIdentical(List<T> listA, List<T> listB) {
    if (listA == null || listB == null) {
        throw new IllegalArgumentException("input list should not be null");
    }/* w w  w.j a v a2 s. c o  m*/

    Object[] arrayA = listA.toArray();
    Object[] arrayB = listB.toArray();

    boolean ret = Arrays.equals(arrayA, arrayB);

    return ret;
}

From source file:Main.java

/**
 * Checks if two byte arrays are equal. Used to compare icons.
 * @return True if equal, false otherwise.
 *//*  w w  w  .ja  v a  2s. c om*/
public static boolean byteArrayEqual(byte[] byte1, byte[] byte2) {
    if (byte1 == null && byte2 != null) {
        return byte2.length == 0;
    }
    if (byte2 == null && byte1 != null) {
        return byte1.length == 0;
    }
    return Arrays.equals(byte1, byte2);
}

From source file:Main.java

/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  polygon 1 (<code>null</code> permitted).
 * @param p2  polygon 2 (<code>null</code> permitted).
 *
 * @return A boolean./*from w w w. j a  v a2  s .  c o  m*/
 */
public static boolean equal(final Polygon p1, final Polygon p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.npoints != p2.npoints) {
        return false;
    }
    if (!Arrays.equals(p1.xpoints, p2.xpoints)) {
        return false;
    }
    if (!Arrays.equals(p1.ypoints, p2.ypoints)) {
        return false;
    }
    return true;
}

From source file:Comparing.java

public static <T> boolean equal(T arg1, T arg2) {
    if (arg1 == null || arg2 == null) {
        return arg1 == arg2;
    } else if (arg1 instanceof Object[] && arg2 instanceof Object[]) {
        Object[] arr1 = (Object[]) arg1;
        Object[] arr2 = (Object[]) arg2;
        return Arrays.equals(arr1, arr2);
    } else if (arg1 instanceof String && arg2 instanceof String) {
        return equal((String) arg1, (String) arg2, true);
    } else {//from w w w . j av a  2s.  c  om
        return arg1.equals(arg2);
    }
}

From source file:Main.java

@SuppressWarnings("resource")
public static boolean isSameContent(String srcFilename, String destFilename) {

    try {//from  w  w  w .  j  a  v a  2  s.c  om

        FileInputStream src = new FileInputStream(srcFilename);
        FileInputStream dst = new FileInputStream(destFilename);

        byte[] bsrc = new byte[1024];
        byte[] bdst = new byte[1024];

        int n;
        while ((n = src.read(bsrc)) != -1) {
            int m = dst.read(bdst);

            if (m == -1)
                return false;

            if (m != n)
                return false;

            if (!Arrays.equals(bsrc, bdst))
                return false;
        }

        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static boolean compare(String[] otherIndexProps, String[] thisIndexProps) {
    if (otherIndexProps != null && thisIndexProps != null) {
        return Arrays.equals(otherIndexProps, thisIndexProps);
    }//  w  w w. ja  v  a  2 s  .  c o m
    return otherIndexProps == null && thisIndexProps == null;
}

From source file:Main.java

private static void skipStartCode(ByteBuffer prefixedSpsBuffer) {
    byte[] prefix3 = new byte[3];
    prefixedSpsBuffer.get(prefix3);/*from w w  w  . j a v  a  2s  .co m*/
    if (Arrays.equals(prefix3, AVC_START_CODE_3))
        return;

    byte[] prefix4 = Arrays.copyOf(prefix3, 4);
    prefix4[3] = prefixedSpsBuffer.get();
    if (Arrays.equals(prefix4, AVC_START_CODE_4))
        return;
    throw new IllegalStateException("AVC NAL start code does not found in csd.");
}

From source file:Comparing.java

public static <T> boolean equal(T[] arr1, T[] arr2) {
    if (arr1 == null || arr2 == null) {
        return arr1 == arr2;
    }/*from  w  w  w .  j  av a  2s  .  com*/
    return Arrays.equals(arr1, arr2);
}

From source file:Main.java

public static boolean checkPassword(char[] plaintextPassword, String passwordHash, String passwordSalt) {
    byte[] calculatedHash = null;
    byte[] savedSalt = hexStringToBytes(passwordSalt);
    byte[] savedHash = hexStringToBytes(passwordHash);

    if (savedHash.length == 0)
        return true; //if they are both empty this will fall through (first time, no set pass)

    try {//from  w  w w.java2 s.co m
        calculatedHash = generateHash(plaintextPassword, savedSalt);
    } catch (Exception e) {
        Log.d(LOG_TAG, "checkPassword", e);
        return false;
    }

    if (calculatedHash != null) {
        if (Arrays.equals(calculatedHash, savedHash))
            return true;
        else
            return false;
    }
    return false;
}