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.strata.math.impl.linearalgebra.LUDecompositionCommonsResultTest.java

public void testGetPivot() {
    int[] expectedRaw = new int[] { 0, 1, 2, 3 };
    assertTrue(Arrays.equals(result.getPivot(), expectedRaw));
}

From source file:com.opengamma.analytics.financial.model.finitedifference.PDEFullResults1D.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }//w  w w  .  ja  v  a2 s .c om
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final PDEFullResults1D other = (PDEFullResults1D) obj;
    if (!Arrays.equals(_f, other._f)) {
        return false;
    }
    if (_grid == null) {
        if (other._grid != null) {
            return false;
        }
    } else if (!_grid.equals(other._grid)) {
        return false;
    }
    return true;
}

From source file:com.ichi2.libanki.test.ModelsTestCase.java

@MediumTest
public void test_fields() {
    Collection d = Shared.getEmptyDeck(getInstrumentation().getContext());
    Note fct = d.newNote();/*from  w ww.  j av a 2  s  .c o  m*/
    fct.setitem("Front", "1");
    fct.setitem("Back", "2");
    d.addNote(fct);
    JSONObject m = d.getModels().current();
    // make sure renaming a field updates the templates
    try {
        d.getModels().renameField(m, m.getJSONArray("flds").getJSONObject(0), "NewFront");
        assertTrue(m.getJSONArray("tmpls").getJSONObject(0).getString("qfmt").contains("{{NewFront}}"));
        String h = d.getModels().scmhash(m);
        // add a field
        JSONObject f = d.getModels().newField(m.toString());
        f.put("name", "foo");
        d.getModels().addField(m, f);
        assertTrue(Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(),
                new String[] { "1", "2", "" }));
        assertTrue(!d.getModels().scmhash(m).equals(h));
        // rename it
        d.getModels().renameField(m, f, "bar");
        assertTrue(d.getNote(d.getModels().nids(m).get(0)).getitem("bar").equals(""));
        // delete back
        d.getModels().remField(m, m.getJSONArray("flds").getJSONObject(1));
        assertTrue(
                Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(), new String[] { "1", "" }));
        // move 0 -> 1
        d.getModels().moveField(m, m.getJSONArray("flds").getJSONObject(0), 1);
        assertTrue(
                Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(), new String[] { "", "1" }));
        // move 1 -> 0
        d.getModels().moveField(m, m.getJSONArray("flds").getJSONObject(1), 0);
        assertTrue(
                Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(), new String[] { "1", "" }));
        // add another and put in middle
        f = d.getModels().newField(m.toString());
        f.put("name", "baz");
        d.getModels().addField(m, f);
        fct = d.getNote(d.getModels().nids(m).get(0));
        fct.setitem("baz", "2");
        fct.flush();
        assertTrue(Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(),
                new String[] { "1", "", "2" }));
        // move 2 -> 1
        d.getModels().moveField(m, m.getJSONArray("flds").getJSONObject(2), 1);
        assertTrue(Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(),
                new String[] { "1", "2", "" }));
        // move 0 -> 2
        d.getModels().moveField(m, m.getJSONArray("flds").getJSONObject(0), 2);
        assertTrue(Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(),
                new String[] { "2", "", "1" }));
        // move 0 -> 1
        d.getModels().moveField(m, m.getJSONArray("flds").getJSONObject(0), 1);
        assertTrue(Arrays.equals(d.getNote(d.getModels().nids(m).get(0)).getFields(),
                new String[] { "", "2", "1" }));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:kr.debop4j.core.tools.StringTool.java

/**
 * Is multi byte string.//from  ww  w.  ja  v  a 2s .co m
 *
 * @param bytes the bytes
 * @return the boolean
 */
public static boolean isMultiByteString(final byte[] bytes) {
    if (bytes == null || bytes.length < MULTI_BYTES_PREFIX.length)
        return false;

    return Arrays.equals(MULTI_BYTES_PREFIX, Arrays.copyOf(bytes, MULTI_BYTES_PREFIX.length));
}

From source file:com.google.dart.server.generated.types.ExtractMethodFeedback.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof ExtractMethodFeedback) {
        ExtractMethodFeedback other = (ExtractMethodFeedback) obj;
        return other.offset == offset && other.length == length
                && ObjectUtilities.equals(other.returnType, returnType)
                && ObjectUtilities.equals(other.names, names) && other.canCreateGetter == canCreateGetter
                && ObjectUtilities.equals(other.parameters, parameters) && Arrays.equals(other.offsets, offsets)
                && Arrays.equals(other.lengths, lengths);
    }//  ww  w . j  a  v a2 s .  c o m
    return false;
}

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

/**
 * Compares <code>this</code> object with input object to establish if are
 * the same object./*from  w  w  w .j  ava 2  s. c o m*/
 *
 * @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;
    }

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

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

    return true;
}

From source file:io.druid.query.search.FragmentSearchQuerySpec.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//from   w  ww . ja v a  2 s.c om
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    FragmentSearchQuerySpec that = (FragmentSearchQuerySpec) o;

    if (caseSensitive ^ that.caseSensitive) {
        return false;
    }

    if (values == null && that.values == null) {
        return true;
    }

    return values != null && Arrays.equals(target, that.target);
}

From source file:ch.cyberduck.core.aquaticprime.DictionaryLicense.java

protected void verify(final NSDictionary dictionary, final String publicKey) throws InvalidLicenseException {
    if (null == dictionary) {
        throw new InvalidLicenseException();
    }//from w  ww  . j av  a2  s.c  om
    final NSData signature = (NSData) dictionary.objectForKey("Signature");
    if (null == signature) {
        log.warn(String.format("Missing key 'Signature' in dictionary %s", dictionary));
        throw new InvalidLicenseException();
    }
    // Append all values
    StringBuilder values = new StringBuilder();
    final ArrayList<String> keys = new ArrayList<>(dictionary.keySet());
    // Sort lexicographically by key
    Collections.sort(keys, new NaturalOrderComparator());
    for (String key : keys) {
        if ("Signature".equals(key)) {
            continue;
        }
        values.append(dictionary.objectForKey(key).toString());
    }
    byte[] signaturebytes = signature.bytes();
    byte[] plainbytes = values.toString().getBytes(Charset.forName("UTF-8"));
    try {
        final BigInteger modulus = new BigInteger(StringUtils.removeStart(publicKey, "0x"), 16);
        final BigInteger exponent = new BigInteger(Base64.decodeBase64("Aw=="));
        final KeySpec spec = new RSAPublicKeySpec(modulus, exponent);

        final PublicKey rsa = KeyFactory.getInstance("RSA").generatePublic(spec);
        final Cipher rsaCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
        rsaCipher.init(Cipher.DECRYPT_MODE, rsa);
        final MessageDigest sha1Digest = MessageDigest.getInstance("SHA1");
        if (!Arrays.equals(rsaCipher.doFinal(signaturebytes), sha1Digest.digest(plainbytes))) {
            throw new InvalidLicenseException();
        }
    } catch (NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException | InvalidKeyException
            | InvalidKeySpecException | NoSuchAlgorithmException e) {
        log.warn(String.format("Signature verification failure for key %s", file));
        throw new InvalidLicenseException();
    }
    if (log.isInfoEnabled()) {
        log.info(String.format("Valid key in %s", file));
    }
}

From source file:net.ontopia.persistence.query.jdo.JDOField.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj instanceof JDOField) {
        JDOField other = (JDOField) obj;
        if (root.equals(other.root))
            if (Arrays.equals(path, other.path))
                return true;
    }//from   ww  w.j a  va 2 s .  c o m
    return false;
}

From source file:com.tc.object.ApplicatorDNAEncodingTest.java

public void testNonPrimitiveArrays() throws Exception {
    final TCByteBufferOutputStream output = new TCByteBufferOutputStream();

    final Object[] array = new Object[] { new ObjectID(12), new Integer(34), new Double(Math.PI),
            ObjectID.NULL_ID, new Long(Long.MIN_VALUE + 34), "timmy" };

    final DNAEncoding encoding = getApplicatorEncoding();
    encoding.encodeArray(array, output);

    final TCByteBufferInputStream input = new TCByteBufferInputStream(output.toArray());

    assertTrue(Arrays.equals(array, (Object[]) encoding.decode(input)));

    assertEquals(0, input.available());//  w  w  w  .j  ava2  s.c om
}