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:com.opengamma.analytics.math.linearalgebra.SVDecompositionCommonsResultTest.java

@Test
public void testSolvers() {
    assertTrue(Arrays.equals(RESULT_1D.getData(), SVD.solve(new double[] { 0.1, 0.2 })));
    assertRealVectorEquals(RESULT_1D, SVD.solve(new DoubleMatrix1D(new double[] { 0.1, 0.2 })));
    assertRealMatrixEquals(RESULT_2D, SVD.solve(
            new DoubleMatrix2D(new double[][] { new double[] { 0.1, 0.2 }, new double[] { 0.1, 0.2 } })));
}

From source file:libepg.epg.util.datetime.DateTimeFieldConverter.java

private static Map<HMS_KEY, Integer> BcdTimeToMap(byte[] hms) throws ParseException {
    Map<HMS_KEY, Integer> ret = new HashMap<>();
    if (hms.length != 3) {
        throw new IndexOutOfBoundsException(
                "?????3????????"
                        + " ?=" + Hex.encodeHexString(hms));
    }//  ww  w . j  a  v  a2  s  .c  om

    //ARIB????????????????
    if (Arrays.equals(hms, UNDEFINED_BCD_TIME_BLOCK.getData())) {
        throw new ParseException("???????????" + " ?="
                + Hex.encodeHexString(hms), 0);
    }
    Object[] parameters = null;

    final int hour = new BCD(hms[0]).getDecimal();
    final int minute = new BCD(hms[1]).getDecimal();
    final int second = new BCD(hms[2]).getDecimal();
    CHECK: {
        final Range<Integer> HOUR_RANGE = Range.between(0, 23);

        if (!HOUR_RANGE.contains(hour)) {
            parameters = new Object[] { Hex.encodeHexString(hms), "", hour };
            break CHECK;
        }

        final Range<Integer> MINUTE_AND_SECOND_RANGE = Range.between(0, 59);

        if (!MINUTE_AND_SECOND_RANGE.contains(minute)) {
            parameters = new Object[] { Hex.encodeHexString(hms), "", minute };
            break CHECK;
        }

        if (!MINUTE_AND_SECOND_RANGE.contains(second)) {
            parameters = new Object[] { Hex.encodeHexString(hms), "", second };
            break CHECK;
        }
    }

    if (parameters != null) {
        MessageFormat msg = new MessageFormat(
                "????????????={0} ={1} ={2}");
        throw new ParseException(msg.format(parameters), 0);
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace("hour=" + hour + " minute=" + minute + " second=" + second);
    }

    ret.put(HMS_KEY.HOUR, hour);
    ret.put(HMS_KEY.MINUTE, minute);
    ret.put(HMS_KEY.SECOND, second);

    return ret;
}

From source file:com.openlattice.mail.EmailRequest.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    EmailRequest other = (EmailRequest) obj;
    if (bcc == null) {
        if (other.bcc != null)
            return false;
    } else if (!bcc.equals(other.bcc))
        return false;
    if (cc == null) {
        if (other.cc != null)
            return false;
    } else if (!cc.equals(other.cc))
        return false;
    if (from == null) {
        if (other.from != null)
            return false;
    } else if (!from.equals(other.from))
        return false;
    if (!Arrays.equals(to, other.to))
        return false;
    return true;/*from ww  w.  jav a 2 s.co m*/
}

From source file:me.lazerka.gae.jersey.oauth2.facebook.TokenVerifierFacebookSignedRequest.java

@Override
public FacebookUserPrincipal verify(String signedRequestToken) throws IOException, InvalidKeyException {
    logger.trace("Requesting endpoint to validate token");

    List<String> parts = Splitter.on('.').splitToList(signedRequestToken);

    checkArgument(parts.size() == 2, "Signed request must have two parts separated by period.");

    byte[] providedSignature = Base64Variants.MODIFIED_FOR_URL.decode(parts.get(0));
    String signedRequestJsonEncoded = parts.get(1);
    byte[] signedRequestJson = Base64Variants.MODIFIED_FOR_URL.decode(signedRequestJsonEncoded);

    SignedRequest signedRequest = jackson.readValue(signedRequestJson, SignedRequest.class);

    if (!"HMAC-SHA256".equals(signedRequest.algorithm)) {
        throw new InvalidKeyException("Unsupported signing method: " + signedRequest.algorithm);
    }//from  www.  j  a v a 2s  .  c o m

    byte[] expectedSignature = hmac.doFinal(signedRequestJsonEncoded.getBytes(UTF_8));
    if (!Arrays.equals(providedSignature, expectedSignature)) {
        throw new InvalidKeyException("Signature invalid");
    }

    // We still need to verify expiration somehow. The only way is to ask Facebook.

    // Exchange `code` for long-lived access token.
    // This serves as verification for `code` expiration too.

    AccessTokenResponse response = fetcher.fetchUserAccessToken(signedRequest.code, redirectUri);

    // Not fetching email, because maybe we won't need to, if ID is enough.

    return new FacebookUserPrincipal(signedRequest.userId, null, response, null);
}

From source file:org.dawnsci.persistence.json.function.FunctionBean.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    FunctionBean other = (FunctionBean) obj;
    if (name == null) {
        if (other.name != null)
            return false;
    } else if (!name.equals(other.name))
        return false;
    if (!Arrays.equals(parameters, other.parameters))
        return false;
    if (type != other.type)
        return false;
    return true;//w  w  w  . j  av a2s .  c om
}

From source file:com.adeptj.modules.security.core.credential.UsernamePasswordCredential.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;
    UsernamePasswordCredential that = (UsernamePasswordCredential) o;
    return Objects.equals(this.username, that.username) && Arrays.equals(this.password, that.password);
}

From source file:com.cloudera.crunch.type.writable.GenericArrayWritable.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    GenericArrayWritable other = (GenericArrayWritable) obj;
    if (!Arrays.equals(values, other.values))
        return false;
    return true;/*www  .j  ava2s . com*/
}

From source file:fr.ortolang.diffusion.security.authentication.TicketHelper.java

public static Ticket decodeTicket(String ticket) {
    byte[] encryptedBytes = Base64.decodeBase64(ticket.getBytes());
    try {//from  w ww  . java 2  s .c  o m
        Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
        // Extract digest from decryptedBytes (MD5 length is 16 bytes)
        byte[] digest = Arrays.copyOfRange(decryptedBytes, decryptedBytes.length - 16, decryptedBytes.length);
        byte[] serializedMap = Arrays.copyOfRange(decryptedBytes, 0, decryptedBytes.length - 16);
        MessageDigest md = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM);
        if (!Arrays.equals(digest, md.digest(serializedMap))) {
            throw new DigestException();
        }
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serializedMap));
        return (Ticket) ois.readObject();
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | BadPaddingException
            | IllegalBlockSizeException | IOException | ClassNotFoundException | DigestException e) {
        LOGGER.log(Level.SEVERE, "Error when decoding ticket: " + e.getMessage());
    }
    return null;
}

From source file:com.meltmedia.cadmium.blackbox.test.CadmiumAssertions.java

/**
 * <p>Asserts that the local and remote files pass to this method exist and are identical.</p>
 * @param message The message that will be in the error if the local file isn't the same as the remote file.
 * @param toCheck The file to check/* ww w.  ja v a 2 s .co  m*/
 * @param username The Basic HTTP auth username.
 * @param password The Basic HTTP auth password.
 * @param remoteLocation A string containing the URL location of the remote resource to check.
 */
public static void assertResourcesEqual(String message, File toCheck, String remoteLocation, String username,
        String password) {
    FileReader reader = null;
    assertExistsLocally(message, toCheck);
    try {
        reader = new FileReader(toCheck);
        byte fileContents[] = IOUtils.toByteArray(reader);
        byte remoteContents[] = EntityUtils
                .toByteArray(assertExistsRemotely(message, remoteLocation, username, password));
        if (!Arrays.equals(fileContents, remoteContents)) {
            throw new AssertionFailedError(message);
        }
    } catch (IOException e) {
        throw new AssertionFailedError(e.getMessage() + ": " + message);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:net.darkmist.clf.UtilTest.java

public void testTailInterleavedBA() throws Exception {
    Integer[] b = new Integer[] { 1, 2, 3, 5, 7, 9 };
    Integer[] a = new Integer[] { 4, 6, 8 };
    Integer[] expected = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    Integer[] actual = new Integer[a.length + b.length];

    Util.merge(a, b, actual, comparator);
    assertTrue(Arrays.equals(actual, expected));
}