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

private static boolean areRecordsEqual(NdefRecord record, NdefRecord otherRecord) {
    return Arrays.equals(record.toByteArray(), otherRecord.toByteArray());
}

From source file:Main.java

public static boolean declaredEquals(Class<?> clazz) {
    for (Method declaredMethod : clazz.getDeclaredMethods()) {
        if (EQUALS_METHOD.equals(declaredMethod.getName())
                && Arrays.equals(declaredMethod.getParameterTypes(), EQUALS_PARAMETERS)) {
            return true;
        }/*  ww  w. j  a v  a 2s.  c  o m*/
    }
    return false;
}

From source file:Main.java

/**
 * Check whether two {@link SparseArray} equal.
 *///from w  ww  .  j  a  va 2  s.c o  m
static boolean equals(SparseArray<byte[]> array, SparseArray<byte[]> otherArray) {
    if (array == otherArray) {
        return true;
    }
    if (array == null || otherArray == null) {
        return false;
    }
    if (array.size() != otherArray.size()) {
        return false;
    }

    // Keys are guaranteed in ascending order when indices are in ascending order.
    for (int i = 0; i < array.size(); ++i) {
        if (array.keyAt(i) != otherArray.keyAt(i) || !Arrays.equals(array.valueAt(i), otherArray.valueAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * Determines whether the contents of two arrays are equal, after a section from one array is
 * removed./* w  w  w .jav  a 2 s.  c o m*/
 *
 * Used to determine whether text has been replaced, or added to/deleted from.
 *
 * @param arrOne First array
 * @param arrTwo Second array
 * @param omissionStart Start index of section to remove from the longer or arrOne and arrTwo.
 * @param omissionEnd End index of section to remove.
 * @return True if both arrOne and arrTwo are equal after section specified in omissionStart
 * and omissionEnd is removed from the longer of the two.
 */
public static boolean isArrayEqualWithOmission(char[] arrOne, char[] arrTwo, int omissionStart,
        int omissionEnd) {

    final boolean isArrOneLonger = (arrOne.length > arrTwo.length);

    final char[] arrOneCopy = (isArrOneLonger)
            ? omitCharArrayEntriesAtIndexes(arrOne.clone(), omissionStart, omissionEnd)
            : arrOne.clone();

    final char[] arrTwoCopy = (!isArrOneLonger)
            ? omitCharArrayEntriesAtIndexes(arrTwo.clone(), omissionStart, omissionEnd)
            : arrTwo.clone();

    return Arrays.equals(arrOneCopy, arrTwoCopy);

}

From source file:Main.java

/**
 * Check whether two {@link SparseArray} equal.
 *///from   www .  j a va 2 s.  c  o  m
public static boolean equals(SparseArray<byte[]> array, SparseArray<byte[]> otherArray) {
    if (array == otherArray) {
        return true;
    }
    if (array == null || otherArray == null) {
        return false;
    }
    if (array.size() != otherArray.size()) {
        return false;
    }

    // Keys are guaranteed in ascending order when indices are in ascending order.
    for (int i = 0; i < array.size(); ++i) {
        if (array.keyAt(i) != otherArray.keyAt(i) || !Arrays.equals(array.valueAt(i), otherArray.valueAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.palantir.atlasdb.keyvalue.rocksdb.impl.RocksDbKeyValueServices.java

static boolean keyExists(RocksIterator iter, byte[] key) {
    iter.seek(key);
    return iter.isValid() && Arrays.equals(key, iter.key());
}

From source file:Main.java

/**
 * Compares two streams/*from w w  w  . jav  a2 s  .  c o  m*/
 * 
 * @param inputStream1
 * @param inputStream2
 * @return true, if streams are the same
 * @throws IOException
 */
protected static boolean compareTwoStreams(InputStream inputStream1, InputStream inputStream2)
        throws IOException {
    boolean error = false;
    try {
        byte[] buffer1 = new byte[1024];
        byte[] buffer2 = new byte[1024];
        try {
            int numRead1 = 0;
            int numRead2 = 0;
            while (true) {
                numRead1 = inputStream1.read(buffer1);
                numRead2 = inputStream2.read(buffer2);
                if (numRead1 > -1) {
                    if (numRead2 != numRead1)
                        return false;
                    if (!Arrays.equals(buffer1, buffer2))
                        return false;
                } else {
                    return numRead2 < 0;
                }
            }
        } finally {
            inputStream1.close();
        }
    } catch (IOException e) {
        error = true;
        throw e;
    } catch (RuntimeException e) {
        error = true;
        throw e;
    } finally {
        try {
            inputStream2.close();
        } catch (IOException e) {
            if (!error)
                throw e;
        }
    }
}

From source file:Main.java

/**
 * Attempt to find a {@link Method} on the supplied class with the supplied name
 * and parameter types. Searches all superclasses up to <code>Object</code>.
 * <p>Returns <code>null</code> if no {@link Method} can be found.
 *
 * @param clazz      the class to introspect
 * @param name       the name of the method
 * @param paramTypes the parameter types of the method
 *                   (may be <code>null</code> to indicate any signature)
 * @return the Method object, or <code>null</code> if none found
 *///  w ww  . jav  a 2s .  c  om
public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
    Class<?> searchType = clazz;
    while (searchType != null) {
        Method[] methods = (searchType.isInterface() ? searchType.getMethods()
                : searchType.getDeclaredMethods());
        for (Method method : methods) {
            if (name.equals(method.getName())
                    && (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) {
                return method;
            }
        }
        searchType = searchType.getSuperclass();
    }
    return null;
}

From source file:com.mirth.connect.server.util.Pre22PasswordChecker.java

/**
 * The pre-2.2 password has been migrated to the following
 * format:/*w w  w. j a v  a2  s.co  m*/
 * 
 * SALT_ + 8-bit salt + base64(sha(salt + password))
 * 
 * To compare:
 * 
 * 1. Strip the known pre-2.2 prefix
 * 2. Get the first 8-bits and Base64 decode it, this the salt
 * 3. Get the remaining bits and Base64 decode it, this is the hash
 * 4. Pass it into the pre-2.2 password checker algorithm
 * 
 * @param plainPassword The plain text password to check against the hash
 * @param encodedPassword The hashed password
 * @return true if the password matches the hash using the pre-2.2 algorithm, false otherwise
 */
public static boolean checkPassword(String plainPassword, String encodedPassword) throws Exception {
    String saltHash = StringUtils.substringAfter(encodedPassword, SALT_PREFIX);
    String encodedSalt = StringUtils.substring(saltHash, 0, SALT_LENGTH);
    byte[] decodedSalt = Base64.decodeBase64(encodedSalt);
    byte[] decodedHash = Base64.decodeBase64(StringUtils.substring(saltHash, encodedSalt.length()));

    if (Arrays.equals(decodedHash, DigestUtils.sha(ArrayUtils.addAll(decodedSalt, plainPassword.getBytes())))) {
        return true;
    }

    return false;
}

From source file:io.bigio.MessageUtils.java

public static void testMessageEquality(RepMessage m1, RepMessage m2) {
    assertTrue(m1.isBooleanValue() == m2.isBooleanValue());
    assertTrue(m1.getByteValue() == m2.getByteValue());
    assertTrue(m1.getShortValue() == m2.getShortValue());
    assertTrue(m1.getIntValue() == m1.getIntValue());
    assertTrue(m1.getFloatValue() == m2.getFloatValue());
    assertTrue(m1.getLongValue() == m2.getLongValue());
    assertTrue(m1.getDoubleValue() == m2.getDoubleValue());
    assertTrue(m1.getStringValue().equals(m2.getStringValue()));
    assertTrue(m1.getEcefValue().equals(m2.getEcefValue()));
    assertEquals(m1.getEnumValue(), m2.getEnumValue());

    assertTrue(Arrays.equals(m1.getBooleanArray(), m2.getBooleanArray()));
    assertTrue(Arrays.equals(m1.getShortArray(), m2.getShortArray()));
    assertTrue(Arrays.equals(m1.getIntArray(), m2.getIntArray()));
    assertTrue(Arrays.equals(m1.getFloatArray(), m2.getFloatArray()));
    assertTrue(Arrays.equals(m1.getLongArray(), m2.getLongArray()));
    assertTrue(Arrays.equals(m1.getDoubleArray(), m2.getDoubleArray()));
    assertTrue(Arrays.equals(m1.getStringArray(), m2.getStringArray()));

    assertTrue(CollectionUtils.isEqualCollection(m1.getBooleanList(), m2.getBooleanList()));
    assertTrue(CollectionUtils.isEqualCollection(m1.getByteList(), m2.getByteList()));
    assertTrue(CollectionUtils.isEqualCollection(m1.getShortList(), m2.getShortList()));
    assertTrue(CollectionUtils.isEqualCollection(m1.getIntList(), m2.getIntList()));
    assertTrue(CollectionUtils.isEqualCollection(m1.getFloatList(), m2.getFloatList()));
    assertTrue(CollectionUtils.isEqualCollection(m1.getLongList(), m2.getLongList()));
    assertTrue(CollectionUtils.isEqualCollection(m1.getDoubleList(), m2.getDoubleList()));
    assertTrue(CollectionUtils.isEqualCollection(m1.getStringList(), m2.getStringList()));

    assertTrue(m1.getEcefList().size() == m2.getEcefList().size());
    for (int i = 0; i < m1.getEcefList().size(); ++i) {
        assertTrue(m1.getEcefList().get(i).equals(m2.getEcefList().get(i)));
    }//  w ww. j a  va 2 s.c  om

    assertTrue(m1.getBoolean2DList().size() == m2.getBoolean2DList().size());
    for (int i = 0; i < m1.getBoolean2DList().size(); ++i) {
        assertTrue(m1.getBoolean2DList().get(i).size() == m2.getBoolean2DList().get(i).size());
        for (int j = 0; j < m1.getBoolean2DList().get(i).size(); ++j) {
            assertTrue(m1.getBoolean2DList().get(i).get(j) == m2.getBoolean2DList().get(i).get(j));
        }
    }

    assertTrue(m1.getByte2DList().size() == m2.getByte2DList().size());
    for (int i = 0; i < m1.getByte2DList().size(); ++i) {
        assertTrue(m1.getByte2DList().get(i).size() == m2.getByte2DList().get(i).size());
        for (int j = 0; j < m1.getByte2DList().get(i).size(); ++j) {
            assertTrue(m1.getByte2DList().get(i).get(j) == m2.getByte2DList().get(i).get(j));
        }
    }

    assertTrue(m1.getShort2DList().size() == m2.getShort2DList().size());
    for (int i = 0; i < m1.getShort2DList().size(); ++i) {
        assertTrue(m1.getShort2DList().get(i).size() == m2.getShort2DList().get(i).size());
        for (int j = 0; j < m1.getShort2DList().get(i).size(); ++j) {
            assertTrue(m1.getShort2DList().get(i).get(j).equals(m2.getShort2DList().get(i).get(j)));
        }
    }

    assertTrue(m1.getInt2DList().size() == m2.getInt2DList().size());
    for (int i = 0; i < m1.getInt2DList().size(); ++i) {
        assertTrue(m1.getInt2DList().get(i).size() == m2.getInt2DList().get(i).size());
        for (int j = 0; j < m1.getInt2DList().get(i).size(); ++j) {
            assertTrue(m1.getInt2DList().get(i).get(j).equals(m2.getInt2DList().get(i).get(j)));
        }
    }

    assertTrue(m1.getFloat2DList().size() == m2.getFloat2DList().size());
    for (int i = 0; i < m1.getFloat2DList().size(); ++i) {
        assertTrue(m1.getFloat2DList().get(i).size() == m2.getFloat2DList().get(i).size());
        for (int j = 0; j < m1.getFloat2DList().get(i).size(); ++j) {
            assertTrue(m1.getFloat2DList().get(i).get(j).equals(m2.getFloat2DList().get(i).get(j)));
        }
    }

    assertTrue(m1.getLong2DList().size() == m2.getLong2DList().size());
    for (int i = 0; i < m1.getLong2DList().size(); ++i) {
        assertTrue(m1.getLong2DList().get(i).size() == m2.getLong2DList().get(i).size());
        for (int j = 0; j < m1.getLong2DList().get(i).size(); ++j) {
            assertTrue(m1.getLong2DList().get(i).get(j).equals(m2.getLong2DList().get(i).get(j)));
        }
    }

    assertTrue(m1.getDouble2DList().size() == m2.getDouble2DList().size());
    for (int i = 0; i < m1.getDouble2DList().size(); ++i) {
        assertTrue(m1.getDouble2DList().get(i).size() == m2.getDouble2DList().get(i).size());
        for (int j = 0; j < m1.getDouble2DList().get(i).size(); ++j) {
            assertTrue(m1.getDouble2DList().get(i).get(j).equals(m2.getDouble2DList().get(i).get(j)));
        }
    }

    assertTrue(m1.getString2DList().size() == m2.getString2DList().size());
    for (int i = 0; i < m1.getString2DList().size(); ++i) {
        assertTrue(m1.getString2DList().get(i).size() == m2.getString2DList().get(i).size());
        for (int j = 0; j < m1.getString2DList().get(i).size(); ++j) {
            assertTrue(m1.getString2DList().get(i).get(j).equals(m2.getString2DList().get(i).get(j)));
        }
    }

    assertTrue(m1.getEcef2DList().size() == m2.getEcef2DList().size());
    for (int i = 0; i < m1.getEcef2DList().size(); ++i) {
        assertTrue(m1.getEcef2DList().get(i).size() == m2.getEcef2DList().get(i).size());
        for (int j = 0; j < m1.getEcef2DList().get(i).size(); ++j) {
            assertTrue(m1.getEcef2DList().get(i).get(j).equals(m2.getEcef2DList().get(i).get(j)));
        }
    }

    assertTrue(m1.getBooleanMap().keySet().size() == m2.getBooleanMap().keySet().size());
    for (String key : m1.getBooleanMap().keySet()) {
        assertTrue(m1.getBooleanMap().get(key).equals(m2.getBooleanMap().get(key)));
    }

    assertTrue(m1.getByteMap().keySet().size() == m2.getByteMap().keySet().size());
    for (String key : m1.getByteMap().keySet()) {
        assertTrue(m1.getByteMap().get(key).equals(m2.getByteMap().get(key)));
    }

    assertTrue(m1.getShortMap().keySet().size() == m2.getShortMap().keySet().size());
    for (String key : m1.getShortMap().keySet()) {
        assertTrue(m1.getShortMap().get(key).equals(m2.getShortMap().get(key)));
    }

    assertTrue(m1.getIntMap().keySet().size() == m2.getIntMap().keySet().size());
    for (String key : m1.getIntMap().keySet()) {
        assertTrue(m1.getIntMap().get(key).equals(m2.getIntMap().get(key)));
    }

    assertTrue(m1.getFloatMap().keySet().size() == m2.getFloatMap().keySet().size());
    for (String key : m1.getFloatMap().keySet()) {
        assertTrue(m1.getFloatMap().get(key).equals(m2.getFloatMap().get(key)));
    }

    assertTrue(m1.getLongMap().keySet().size() == m2.getLongMap().keySet().size());
    for (String key : m1.getLongMap().keySet()) {
        assertTrue(m1.getLongMap().get(key).equals(m2.getLongMap().get(key)));
    }

    assertTrue(m1.getDoubleMap().keySet().size() == m2.getDoubleMap().keySet().size());
    for (String key : m1.getDoubleMap().keySet()) {
        assertTrue(m1.getDoubleMap().get(key).equals(m2.getDoubleMap().get(key)));
    }

    assertTrue(m1.getStringMap().keySet().size() == m2.getStringMap().keySet().size());
    for (String key : m1.getStringMap().keySet()) {
        assertTrue(m1.getStringMap().get(key).equals(m2.getStringMap().get(key)));
    }

    assertTrue(m1.getEcefMap().keySet().size() == m2.getEcefMap().keySet().size());
    for (String key : m1.getEcefMap().keySet()) {
        assertTrue(m1.getEcefMap().get(key).equals(m2.getEcefMap().get(key)));
    }

    assertTrue(m1.getBooleanListMap().keySet().size() == m2.getBooleanListMap().keySet().size());
    for (String key : m1.getBooleanListMap().keySet()) {
        for (int i = 0; i < m1.getBooleanListMap().get(key).size(); ++i) {
            assertTrue(m1.getBooleanListMap().get(key).get(i).equals(m2.getBooleanListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getByteListMap().keySet().size() == m2.getByteListMap().keySet().size());
    for (String key : m1.getByteListMap().keySet()) {
        for (int i = 0; i < m1.getByteListMap().get(key).size(); ++i) {
            assertTrue(m1.getByteListMap().get(key).get(i).equals(m2.getByteListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getShortListMap().keySet().size() == m2.getShortListMap().keySet().size());
    for (String key : m1.getShortListMap().keySet()) {
        for (int i = 0; i < m1.getShortListMap().get(key).size(); ++i) {
            assertTrue(m1.getShortListMap().get(key).get(i).equals(m2.getShortListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getIntListMap().keySet().size() == m2.getIntListMap().keySet().size());
    for (String key : m1.getIntListMap().keySet()) {
        for (int i = 0; i < m1.getIntListMap().get(key).size(); ++i) {
            assertTrue(m1.getIntListMap().get(key).get(i).equals(m2.getIntListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getFloatListMap().keySet().size() == m2.getFloatListMap().keySet().size());
    for (String key : m1.getFloatListMap().keySet()) {
        for (int i = 0; i < m1.getFloatListMap().get(key).size(); ++i) {
            assertTrue(m1.getFloatListMap().get(key).get(i).equals(m2.getFloatListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getLongListMap().keySet().size() == m2.getLongListMap().keySet().size());
    for (String key : m1.getLongListMap().keySet()) {
        for (int i = 0; i < m1.getLongListMap().get(key).size(); ++i) {
            assertTrue(m1.getLongListMap().get(key).get(i).equals(m2.getLongListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getDoubleListMap().keySet().size() == m2.getDoubleListMap().keySet().size());
    for (String key : m1.getDoubleListMap().keySet()) {
        for (int i = 0; i < m1.getDoubleListMap().get(key).size(); ++i) {
            assertTrue(m1.getDoubleListMap().get(key).get(i).equals(m2.getDoubleListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getStringListMap().keySet().size() == m2.getStringListMap().keySet().size());
    for (String key : m1.getStringListMap().keySet()) {
        for (int i = 0; i < m1.getStringListMap().get(key).size(); ++i) {
            assertTrue(m1.getStringListMap().get(key).get(i).equals(m2.getStringListMap().get(key).get(i)));
        }
    }

    assertTrue(m1.getEcefListMap().keySet().size() == m2.getEcefListMap().keySet().size());
    for (String key : m1.getEcefListMap().keySet()) {
        for (int i = 0; i < m1.getEcefListMap().get(key).size(); ++i) {
            assertTrue(m1.getEcefListMap().get(key).get(i).equals(m2.getEcefListMap().get(key).get(i)));
        }
    }
}