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:edu.cmu.tetrad.util.MatrixUtils.java

/**
 * Tests two vectors for equality./*  ww w .  j a v  a2s .  c  o m*/
 *
 * @param va The first 1D matrix to check.
 * @param vb The second 1D matrix to check.
 * @return True iff the first and second matrices are equal.
 */
public static boolean equals(double[] va, double[] vb) {
    return Arrays.equals(va, vb);
}

From source file:com.github.aelstad.keccakj.fips202.KeccackDigestTestUtils.java

public void runTests(List<DigestTest> tests, AbstractKeccackMessageDigest messageDigest, int digestLength)
        throws Exception {
    for (DigestTest dt : tests) {
        messageDigest.reset();/*  w w  w .jav  a  2 s . com*/

        if ((dt.len & 7) == 0)
            messageDigest.update(dt.msg, 0, dt.len >> 3);
        else
            messageDigest.engineUpdateBits(dt.msg, 0, dt.len);

        System.out.println("Rate is now " + new String(
                Hex.encodeHex(messageDigest.getRateBits(0, Math.min(dt.len, messageDigest.getRateBits())))));
        byte[] md = messageDigest.digest();
        System.out.println("Testing length " + dt.len + ". Got " + new String(Hex.encodeHex(md)));
        Assert.assertTrue(digestLength == dt.digest.length);
        ;
        Assert.assertTrue(digestLength == md.length);
        ;
        org.junit.Assert.assertTrue(Arrays.equals(md, dt.digest));
    }

    testPerformance(messageDigest);
}

From source file:com.opengamma.analytics.financial.forex.method.PresentValueForexBlackVolatilityQuoteSensitivityDataBundle.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//  ww  w  .  j a  v  a  2  s .  c  o m
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    PresentValueForexBlackVolatilityQuoteSensitivityDataBundle other = (PresentValueForexBlackVolatilityQuoteSensitivityDataBundle) obj;
    if (!ObjectUtils.equals(_currencyPair, other._currencyPair)) {
        return false;
    }
    if (!Arrays.equals(_delta, other._delta)) {
        return false;
    }
    if (!Arrays.equals(_expiries, other._expiries)) {
        return false;
    }
    if (!Arrays.equals(_vega, other._vega)) {
        return false;
    }
    return true;
}

From source file:ly.count.android.api.CountlyStoreTests.java

public void testConnections_prefHasTwoValues() {
    final String connStr1 = "blah1";
    final String connStr2 = "blah2";
    store.addConnection(connStr1);/*from www.ja  v  a  2s  . co m*/
    store.addConnection(connStr2);
    assertTrue(Arrays.equals(new String[] { connStr1, connStr2 }, store.connections()));
}

From source file:com.github.tojo.session.cookies.SignatureStrategyDefaultImpl.java

@Override
public byte[] validate(byte[] signedSessionData) throws SignatureException {
    assertNotNullAndEmpty(signedSessionData);
    assertMinLength(signedSessionData, SIGNATURE_LENGTH);

    byte[] signature = ArrayUtils.subarray(signedSessionData, 0, SIGNATURE_LENGTH);
    byte[] sessionData = ArrayUtils.subarray(signedSessionData, SIGNATURE_LENGTH, signedSessionData.length);

    byte[] newSignature = ArrayUtils.subarray(sign(sessionData), 0, SIGNATURE_LENGTH);
    if (!Arrays.equals(newSignature, signature)) {
        throw new SignatureException("Invalid signature!");
    }//w w  w .j  ava 2  s. c  om
    return sessionData;
}

From source file:edu.tamu.tcat.crypto.bouncycastle.PBKDF2Impl.java

@Override
protected boolean checkHash(byte[] password, String saltStr, String outputStr, DigestType digest, int rounds) {
    if (!Base64.isBase64(saltStr) || !Base64.isBase64(outputStr))
        return false;

    byte[] salt = Base64.decodeBase64(saltStr);
    byte[] output = Base64.decodeBase64(outputStr);

    int outputSize = DigestTypeMap.getDigest(digest).getDigestSize();
    if (output.length != outputSize)
        return false;

    PBKDF2Impl pbkdf2 = new PBKDF2Impl(digest);
    byte[] candidate = pbkdf2.deriveKey(password, salt, rounds, outputSize);
    return Arrays.equals(candidate, output);
}

From source file:eu.europa.esig.dss.RemoteDocument.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*from   w w w.j  a va 2s .  co m*/
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    RemoteDocument other = (RemoteDocument) obj;
    if (absolutePath == null) {
        if (other.absolutePath != null) {
            return false;
        }
    } else if (!absolutePath.equals(other.absolutePath)) {
        return false;
    }
    if (!Arrays.equals(bytes, other.bytes)) {
        return false;
    }
    if (mimeType == null) {
        if (other.mimeType != null) {
            return false;
        }
    } else if (!mimeType.equals(other.mimeType)) {
        return false;
    }
    if (name == null) {
        if (other.name != null) {
            return false;
        }
    } else if (!name.equals(other.name)) {
        return false;
    }
    return true;
}

From source file:Main.java

public static boolean equals(Object target, Object o) {
    if (target == o)
        return true;
    if (target == null || o == null)
        return false;
    if (!target.getClass().equals(o.getClass()))
        return false;

    Class<?> current = target.getClass();
    do {/* www  .j a va 2  s  .  c o  m*/
        for (Field f : current.getDeclaredFields()) {
            if (Modifier.isStatic(f.getModifiers()) || Modifier.isTransient(f.getModifiers())
                    || f.isSynthetic()) {
                continue;
            }

            Object self;
            Object other;
            try {
                f.setAccessible(true);
                self = f.get(target);
                other = f.get(o);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException(e);
            }
            if (self == null) {
                if (other != null)
                    return false;
            } else if (self.getClass().isArray()) {
                if (self.getClass().equals(boolean[].class)) {
                    if (!Arrays.equals((boolean[]) self, (boolean[]) other))
                        return false;
                } else if (self.getClass().equals(char[].class)) {
                    if (!Arrays.equals((char[]) self, (char[]) other))
                        return false;
                } else if (self.getClass().equals(byte[].class)) {
                    if (!Arrays.equals((byte[]) self, (byte[]) other))
                        return false;
                } else if (self.getClass().equals(short[].class)) {
                    if (!Arrays.equals((short[]) self, (short[]) other))
                        return false;
                } else if (self.getClass().equals(int[].class)) {
                    if (!Arrays.equals((int[]) self, (int[]) other))
                        return false;
                } else if (self.getClass().equals(long[].class)) {
                    if (!Arrays.equals((long[]) self, (long[]) other))
                        return false;
                } else if (self.getClass().equals(float[].class)) {
                    if (!Arrays.equals((float[]) self, (float[]) other))
                        return false;
                } else if (self.getClass().equals(double[].class)) {
                    if (!Arrays.equals((double[]) self, (double[]) other))
                        return false;
                } else {
                    if (!Arrays.equals((Object[]) self, (Object[]) other))
                        return false;
                }
            } else if (!self.equals(other)) {
                return false;
            }
        }
        current = current.getSuperclass();
    } while (!Object.class.equals(current));

    return true;
}

From source file:com.bitctrl.net.MAC.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    } else if (obj instanceof MAC) {
        final MAC o = (MAC) obj;
        return Arrays.equals(address, o.address);
    }/*from   w  w w. java2  s .c  o  m*/

    return false;
}

From source file:com.nokia.dempsy.messagetransport.tcp.TcpSender.java

private DataOutputStream getDataOutputStream() throws MessageTransportException, IOException {
    if (dataOutputStream == null) // socket must also be null.
    {/*from w w w  .  j  av a  2 s  .  c om*/
        socket = makeSocket(destination);

        // There is a really odd circumstance (at least on Linux) where a connection 
        //  to a port in the dynamic range, while there is no listener on that port,
        //  from the same system/network interface, can result in a local port selection
        //  that's the same as the port that the connection attempt is to. In this case,
        //  for some reason the Socket instantiation (and connection) succeeds without
        //  a listener. We need to force a failure if this is the case.
        if (isLocalAddress == IsLocalAddress.Unknown) {
            if (socket.isBound()) {
                InetAddress localSocketAddress = socket.getLocalAddress();
                isLocalAddress = (Arrays.equals(localSocketAddress.getAddress(),
                        destination.inetAddress.getAddress())) ? IsLocalAddress.Yes : IsLocalAddress.No;
            }
        }

        if (isLocalAddress == IsLocalAddress.Yes) {
            if (socket.getLocalPort() == destination.port)
                throw new IOException("Connection to self same port!!!");
        }

        dataOutputStream = new DataOutputStream(socket.getOutputStream());
    }

    return dataOutputStream;
}