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.palantir.atlasdb.keyvalue.impl.AssertLockedKeyValueService.java

@Override
public void put(String tableName, Map<Cell, byte[]> values, long timestamp) {

    if (tableName.equals(TransactionConstants.TRANSACTION_TABLE)) {
        SortedMap<LockDescriptor, LockMode> mapToAssertLockHeld = Maps.newTreeMap();
        SortedMap<LockDescriptor, LockMode> mapToAssertLockNotHeld = Maps.newTreeMap();
        for (Map.Entry<Cell, byte[]> e : values.entrySet()) {
            if (Arrays.equals(e.getValue(),
                    TransactionConstants.getValueForTimestamp(TransactionConstants.FAILED_COMMIT_TS))) {
                mapToAssertLockNotHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()),
                        LockMode.READ);//from   w w w .  j a va 2  s. c o  m
            } else {
                mapToAssertLockHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()),
                        LockMode.READ);
            }
        }

        try {
            if (!mapToAssertLockHeld.isEmpty()) {
                LockRequest request = LockRequest.builder(mapToAssertLockHeld).doNotBlock()
                        .lockAsManyAsPossible().build();
                LockRefreshToken lock = lockService.lockAnonymously(request);
                Validate.isTrue(lock == null, "these should already be held");
            }

            if (!mapToAssertLockNotHeld.isEmpty()) {
                LockRequest request = LockRequest.builder(mapToAssertLockNotHeld).doNotBlock().build();
                LockRefreshToken lock = lockService.lockAnonymously(request);
                Validate.isTrue(lock != null, "these should already be waited for");
            }
        } catch (InterruptedException e) {
            throw Throwables.throwUncheckedException(e);
        }
    }

    super.put(tableName, values, timestamp);
}

From source file:com.google.nigori.common.Revision.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Revision other = (Revision) obj;/*www  .ja v  a2s. co m*/
    if (!Arrays.equals(revision, other.revision))
        return false;
    return true;
}

From source file:org.jfree.data.function.PolynomialFunction2DTest.java

/**
 * Some tests for the constructor./*  w ww. j  ava  2 s.  c om*/
 */
@Test
public void testConstructor() {
    PolynomialFunction2D f = new PolynomialFunction2D(new double[] { 1.0, 2.0 });
    assertTrue(Arrays.equals(new double[] { 1.0, 2.0 }, f.getCoefficients()));

    boolean pass = false;
    try {
        f = new PolynomialFunction2D(null);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:my.adam.smo.EncryptionTest.java

@Test
public void symetricEncryptionShortMessage() {
    ApplicationContext clientContext = new ClassPathXmlApplicationContext("Context.xml");
    SymmetricEncryptionBox box = clientContext.getBean(SymmetricEncryptionBox.class);
    int plainTextLength = 3;

    byte[] plainText = new byte[plainTextLength];
    random.nextBytes(plainText);//from w ww  .j  ava  2s .  co m

    byte[] cryptogram = box.encrypt(plainText);
    Assert.assertFalse("plain text leaked!!!", Arrays.equals(plainText,
            Arrays.copyOfRange(cryptogram, SymmetricEncryptionBox.ivLength, cryptogram.length)));

    byte[] decrypted = box.decrypt(cryptogram);
    Assert.assertTrue("unable to decrypt", Arrays.equals(plainText, decrypted));
}

From source file:cz.lbenda.common.ByteArrayBinaryData.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (!(o instanceof ByteArrayBinaryData))
        return false;

    ByteArrayBinaryData that = (ByteArrayBinaryData) o;
    return Arrays.equals(bytes, that.bytes);
}

From source file:com.navercorp.pinpoint.common.buffer.AutomaticBufferTest.java

@Test
public void testPadBytes() throws Exception {
    int TOTAL_LENGTH = 20;
    int TEST_SIZE = 10;
    Buffer buffer = new AutomaticBuffer(10);
    byte[] test = new byte[10];

    random.nextBytes(test);/*from   ww w .j  av a  2s.  com*/

    buffer.putPadBytes(test, TOTAL_LENGTH);

    byte[] result = buffer.getBuffer();
    org.junit.Assert.assertEquals(result.length, TOTAL_LENGTH);
    org.junit.Assert.assertTrue("check data",
            Arrays.equals(Arrays.copyOfRange(test, 0, TEST_SIZE), Arrays.copyOfRange(result, 0, TEST_SIZE)));
    byte[] padBytes = new byte[TOTAL_LENGTH - TEST_SIZE];
    org.junit.Assert.assertTrue("check pad", Arrays.equals(Arrays.copyOfRange(padBytes, 0, TEST_SIZE),
            Arrays.copyOfRange(result, TEST_SIZE, TOTAL_LENGTH)));

}

From source file:be.fedict.trust.repository.MemoryCertificateRepository.java

@Override
public boolean isTrustPoint(X509Certificate certificate) {
    String fingerprint = getFingerprint(certificate);
    X509Certificate trustPoint = this.trustPoints.get(fingerprint);
    if (null == trustPoint) {
        return false;
    }//from   ww w.j  a  va  2s.  c  o m
    try {
        /*
         * We cannot used certificate.equals(trustPoint) here as the
         * certificates might be loaded by different security providers.
         */
        return Arrays.equals(certificate.getEncoded(), trustPoint.getEncoded());
    } catch (CertificateEncodingException e) {
        throw new IllegalArgumentException("certificate encoding error: " + e.getMessage(), e);
    }
}

From source file:com.registryKit.user.userManager.java

public boolean authenticate(String attemptedPassword, byte[] encryptedPassword, byte[] salt)
        throws NoSuchAlgorithmException, InvalidKeySpecException {

    // Encrypt the clear-text password using the same salt that was used to
    // encrypt the original password
    byte[] encryptedAttemptedPassword = getEncryptedPassword(attemptedPassword, salt);

    // Authentication succeeds if encrypted password that the user entered
    // is equal to the stored hash
    return Arrays.equals(encryptedPassword, encryptedAttemptedPassword);
}

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

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Digest other = (Digest) obj;// www  .j a  v  a  2 s  .  co  m
    if (algorithm != other.algorithm)
        return false;
    if (!Arrays.equals(value, other.value))
        return false;
    return true;
}

From source file:com.p6spy.engine.spy.XADataSourceTest.java

@Parameters(name = "{index}: {0}")
public static Collection<Object[]> dbs() {
    Collection<Object[]> result = new ArrayList<Object[]>();
    for (Object o : P6TestFramework.dbs()) {
        // SQLite provides no datasource implementation => skip it
        if (!Arrays.equals(new Object[] { "SQLite" }, (Object[]) o)) {
            result.add((Object[]) o);
        }//from www .  j  a  v  a  2  s  .c o  m
    }
    return result;
}