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:ml.dmlc.xgboost4j.java.BoosterImplTest.java

@Test
public void saveLoadModelWithPath() throws XGBoostError, IOException {
    DMatrix trainMat = new DMatrix("../../demo/data/agaricus.txt.train");
    DMatrix testMat = new DMatrix("../../demo/data/agaricus.txt.test");
    IEvaluation eval = new EvalError();

    Booster booster = trainBooster(trainMat, testMat);
    // save and load
    File temp = File.createTempFile("temp", "model");
    temp.deleteOnExit();//from www .  ja v a 2 s  . c o m
    booster.saveModel(temp.getAbsolutePath());

    Booster bst2 = XGBoost.loadModel(temp.getAbsolutePath());
    assert (Arrays.equals(bst2.toByteArray(), booster.toByteArray()));
    float[][] predicts2 = bst2.predict(testMat, true, 0);
    TestCase.assertTrue(eval.eval(predicts2, testMat) < 0.1f);
}

From source file:eu.europa.esig.dss.xades.validation.XMLDocumentValidator.java

private boolean isXmlPreamble(byte[] preamble) {
    byte[] startOfPramble = ArrayUtils.subarray(preamble, 0, xmlPreamble.length);
    return Arrays.equals(startOfPramble, xmlPreamble) || Arrays.equals(startOfPramble, xmlUtf8);
}

From source file:org.apache.cxf.fediz.service.idp.kerberos.KerberosServiceRequestToken.java

/**
 * equals() is based only on the Kerberos token
 *///from   w w w.  j a  v a2s .  c  o  m
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!super.equals(obj)) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    KerberosServiceRequestToken other = (KerberosServiceRequestToken) obj;
    if (!Arrays.equals(token, other.token)) {
        return false;
    }
    return true;
}

From source file:com.google.u2f.gaedemo.storage.TokenStorageData.java

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof TokenStorageData))
        return false;
    TokenStorageData that = (TokenStorageData) obj;
    return (this.enrollmentTime == that.enrollmentTime)
            && SecurityKeyData.containSameTransports(this.transports, that.transports)
            && (this.counter == that.counter) && Arrays.equals(this.keyHandle, that.keyHandle)
            && Arrays.equals(this.publicKey, that.publicKey)
            && Arrays.equals(this.attestationCert, that.attestationCert);
}

From source file:com.couchbase.lite.BlobStoreTest.java

public void testReopen() throws Exception {
    if (!isSQLiteDB())
        return;/*from w w w .ja v  a  2s .  com*/

    byte[] item = "this is an item".getBytes("UTF8");
    BlobKey key = new BlobKey();
    Assert.assertTrue(store.storeBlob(item, key));

    BlobStore store2 = new BlobStore(manager.getContext(), store.getPath(), store.getEncryptionKey(), true);
    Assert.assertNotNull("Couldn't re-open store", store2);

    byte[] readItem = store2.blobForKey(key);
    Assert.assertTrue(Arrays.equals(readItem, item));

    readItem = store.blobForKey(key);
    Assert.assertTrue(Arrays.equals(readItem, item));
    verifyRawBlob(key, item);
}

From source file:com.facebook.infrastructure.service.ReadResponseResolver.java

public Row resolve(List<Message<byte[]>> responses) throws DigestMismatchException {
    long startTime = System.currentTimeMillis();
    Row retRow = null;//  w w w.ja  va 2  s  . c  o m
    List<Row> rowList = new ArrayList<Row>();
    List<EndPoint> endPoints = new ArrayList<EndPoint>();
    String key = null;
    String table = null;
    byte[] digest = ArrayUtils.EMPTY_BYTE_ARRAY;
    boolean isDigestQuery = false;

    /*
    * Populate the list of rows from each of the messages
    * Check to see if there is a digest query. If a digest 
     * query exists then we need to compare the digest with 
     * the digest of the data that is received.
    */
    DataInputBuffer bufIn = new DataInputBuffer();
    for (Message<byte[]> response : responses) {
        byte[] body = response.getMessageBody();
        bufIn.reset(body, body.length);
        long start = System.currentTimeMillis();
        ReadResponse result = null;
        try {
            result = ReadResponse.serializer().deserialize(bufIn);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        logger_.trace("Response deserialization time : " + (System.currentTimeMillis() - start) + " ms.");
        if (!result.isDigestQuery()) {
            rowList.add(result.row());
            endPoints.add(response.getFrom());
            key = result.row().key();
            table = result.table();
        } else {
            digest = result.digest();
            isDigestQuery = true;
        }
    }
    // If there was a digest query compare it withh all teh data digests 
    // If there is a mismatch then thwrow an exception so that read repair can happen.
    if (isDigestQuery) {
        for (Row row : rowList) {
            if (!Arrays.equals(row.digest(), digest)) {
                throw new DigestMismatchException("The Digest does not match");
            }
        }
    }

    /* If the rowList is empty then we had some exception above. */
    if (rowList.size() == 0) {
        return retRow;
    }

    /* Now calculate the resolved row */
    retRow = new Row(key);
    for (int i = 0; i < rowList.size(); i++) {
        retRow.repair(rowList.get(i));
    }
    // At  this point  we have the return row .
    // Now we need to calculate the differnce 
    // so that we can schedule read repairs 

    for (int i = 0; i < rowList.size(); i++) {
        // calculate the difference , since retRow is the resolved
        // row it can be used as the super set , remember no deletes 
        // will happen with diff its only for additions so far 
        // TODO : handle deletes 
        Row diffRow = rowList.get(i).diff(retRow);
        if (diffRow == null) // no repair needs to happen
            continue;
        // create the row mutation message based on the diff and schedule a read repair 
        RowMutation rowMutation = new RowMutation(table, key);
        for (ColumnFamily cf : diffRow.getColumnFamilies()) {
            rowMutation.add(cf);
        }
        // schedule the read repair
        ReadRepairManager.instance().schedule(endPoints.get(i), rowMutation);
    }
    logger_.trace("resolve: " + (System.currentTimeMillis() - startTime) + " ms.");
    return retRow;
}

From source file:com.haulmont.chile.core.model.MetaPropertyPath.java

/**
 * Tests if this path is a nested property of the given path.
 *//*from w  ww.  j  a  v  a  2 s  .com*/
public boolean startsWith(MetaPropertyPath other) {
    if (other.getPath().length > path.length)
        return false;
    MetaProperty[] subarray = Arrays.copyOf(this.metaProperties, other.getMetaProperties().length);
    return Arrays.equals(subarray, other.metaProperties);
}

From source file:net.ontopia.persistence.query.sql.SQLColumns.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof SQLColumns) {
        SQLColumns other = (SQLColumns) obj;
        if (table.equals(other.getTable())) {
            if (Arrays.equals(cols, other.getColumns()))
                return true;
        }//ww w .  ja  v  a 2 s.co m
    }
    return false;
}

From source file:com.funambol.ctp.core.Ok.java

/**
 * Compares <code>this</code> object with input object to establish if are
 * the same object./*from www. j a v  a 2s  .  c  om*/
 *
 * @param obj the object to compare
 * @return true if the objects are equals, false otherwise
 */
public boolean deepequals(Object obj) {

    if (obj == null || (!obj.getClass().equals(this.getClass()))) {
        return false;
    }

    if (this == obj) {
        return true;
    }

    Ok cmd = (Ok) obj;
    if (this.getNonce() == null) {
        if (cmd.getNonce() != null) {
            return false;
        }
    } else {
        if (cmd.getNonce() == null) {
            return false;
        }

        if (!(Arrays.equals(this.getNonce(), cmd.getNonce()))) {
            return false;
        }
    }

    return true;
}

From source file:io.cortical.retina.core.CompareTest.java

/**
 * //from ww  w . ja  va  2s  .  c om
 * {@link Compare#compare(io.cortical.retina.model.Model, io.cortical.retina.model.Model)} method test.
 * @throws JsonProcessingException : should never be thrown.
 * @throws ApiException : should never be thrown.
 */
@Test
public void compareTest_bulk() throws JsonProcessingException, ApiException {
    List<CompareModel> compareModels = Arrays.asList(new CompareModel(TERM_1, TEXT_1),
            new CompareModel(TERM_1, TEXT_1), new CompareModel(TERM_1, TEXT_1));

    Model[][] toCompare = new Model[compareModels.size()][2];
    int i = 0;
    for (CompareModel pair : compareModels) {
        toCompare[i++] = pair.getModels();
    }

    Metric[] metrics = new Metric[] { METRIC, METRIC, METRIC };
    when(api.compareBulk(eq(Model.toJsonBulk(toCompare)), eq(NOT_NULL_RETINA))).thenReturn(metrics);
    Metric[] retVal = compare.compareBulk(compareModels);
    assertTrue(Arrays.equals(metrics, retVal));
    verify(api, times(1)).compareBulk(eq(Model.toJsonBulk(toCompare)), eq(NOT_NULL_RETINA));
}