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.yahoo.parsec.clients.ParsecEqualsUtil.java

/**
 * Byte array list equals.//from   ww w  . j  a v  a  2  s . c  o m
 *
 * @param lhs lhs
 * @param rhs rhs
 *
 * @return true when two byte array list are equal by value
 */
static boolean byteArrayListEquals(final List<byte[]> lhs, final List<byte[]> rhs) {
    if (lhs != rhs) {
        if (lhs == null || rhs == null || lhs.size() != rhs.size()) {
            return false;
        }

        for (int i = 0; i < lhs.size(); i++) {
            if (!Arrays.equals(lhs.get(i), rhs.get(i))) {
                return false;
            }
        }
    }
    return true;
}

From source file:de.mpg.imeji.logic.storage.util.ImageUtils.java

/**
 * Prepare the image for the upload: <br/>
 * if it is original image upload, do nothing <br/>
 * if it is another resolution, resize it <br/>
 * if it is a tiff to be resized, transformed it to jpeg and resize it
 * //www .  j av a 2s  .c om
 * @param stream
 * @param contentCategory
 * @param format
 * @return
 * @throws IOException
 * @throws Exception
 */
public static byte[] transformImage(byte[] bytes, FileResolution resolution, String mimeType)
        throws IOException, Exception {
    // If it is orginal resolution, don't touch the file, otherwise transform (compress and/or )
    if (!FileResolution.ORIGINAL.equals(resolution)) {
        if (FileResolution.THUMBNAIL.equals(resolution) || StorageUtils.getMimeType("tif").equals(mimeType)) {
            // If it is the thumbnail, compress the images (in jpeg), if it is a tif compress even for WEb
            // resolution, since resizing not possible with tif
            byte[] compressed = compressImage(bytes, mimeType);
            if (!Arrays.equals(compressed, bytes)) {
                mimeType = StorageUtils.getMimeType("jpg");
            }
            bytes = compressed;
        }
        // Read the bytes as BufferedImage
        BufferedImage image;
        if (StorageUtils.getMimeType("jpg").equals(mimeType)) {
            image = JpegUtils.readJpeg(bytes);
        } else {
            image = ImageIO.read(new ByteArrayInputStream(bytes));
        }
        if (image == null) {
            // The image couldn't be read
            return null;
        }
        // Resize image
        if (StorageUtils.getMimeType("gif").equals(mimeType) && GifUtils.isAnimatedGif(bytes)) {
            // If it is an animated gif, resize all frame and build a new gif with this resized frames
            bytes = GifUtils.resizeAnimatedGif(bytes, resolution);
        } else {
            bytes = toBytes(scaleImage(image, resolution), mimeType);
        }
    }
    return bytes;
}

From source file:com.linkedin.pinot.common.utils.primitive.ByteArray.java

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

    ByteArray bytes = (ByteArray) o;

    return Arrays.equals(_bytes, bytes._bytes);
}

From source file:com.cloudant.sync.datastore.BasicDBBodyTest.java

@Test
public void constructor_byteArray_correctObjectShouldBeCreated() throws Exception {
    DocumentBody body = new BasicDocumentBody(jsonData);
    Assert.assertTrue(Arrays.equals(jsonData, body.asBytes()));
    Assert.assertNotNull(body.asMap());/* w ww.j a v a2 s .  co m*/

    Map<String, Object> actualMap = body.asMap();
    assertMapIsCorrect(actualMap);
}

From source file:com.baidu.oped.apm.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  w  w  w  . jav  a  2s .  com*/

    buffer.putPadBytes(test, TOTAL_LENGTH);

    byte[] result = buffer.getBuffer();
    Assert.assertEquals(result.length, TOTAL_LENGTH);
    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];
    Assert.assertTrue("check pad", Arrays.equals(Arrays.copyOfRange(padBytes, 0, TEST_SIZE),
            Arrays.copyOfRange(result, TEST_SIZE, TOTAL_LENGTH)));

}

From source file:jenkins.plugins.git.MethodUtils.java

/**
 * <p>Retrieves a method whether or not it's accessible. If no such method
 * can be found, return {@code null}.</p>
 *
 * @param cls            The class that will be subjected to the method search
 * @param methodName     The method that we wish to call
 * @param parameterTypes Argument class types
 * @return The method/*from w ww .j  av  a  2 s  .  com*/
 */
static Method getMethodImpl(final Class<?> cls, final String methodName, final Class<?>... parameterTypes) {
    Validate.notNull(cls, "Null class not allowed.");
    Validate.notEmpty(methodName, "Null or blank methodName not allowed.");

    // fast path, check if directly declared on the class itself
    for (final Method method : cls.getDeclaredMethods()) {
        if (methodName.equals(method.getName()) && Arrays.equals(parameterTypes, method.getParameterTypes())) {
            return method;
        }
    }
    if (!cls.isInterface()) {
        // ok, now check if directly implemented on a superclass
        // Java 8: note that super-interface implementations trump default methods
        for (Class<?> klass = cls.getSuperclass(); klass != null; klass = klass.getSuperclass()) {
            for (final Method method : klass.getDeclaredMethods()) {
                if (methodName.equals(method.getName())
                        && Arrays.equals(parameterTypes, method.getParameterTypes())) {
                    return method;
                }
            }
        }
    }
    // ok, now we are looking for an interface method... the most specific one
    // in the event that we have two unrelated interfaces both declaring a method of the same name
    // we will give up and say we could not find the method (the logic here is that we are primarily
    // checking for overrides, in the event of a Java 8 default method, that default only
    // applies if there is no conflict from an unrelated interface... thus if there are
    // default methods and they are unrelated then they don't exist... if there are multiple unrelated
    // abstract methods... well they won't count as a non-abstract implementation
    Method res = null;
    for (final Class<?> klass : (List<Class<?>>) ClassUtils.getAllInterfaces(cls)) {
        for (final Method method : klass.getDeclaredMethods()) {
            if (methodName.equals(method.getName())
                    && Arrays.equals(parameterTypes, method.getParameterTypes())) {
                if (res == null) {
                    res = method;
                } else {
                    Class<?> c = res.getDeclaringClass();
                    if (c == klass) {
                        // match, ignore
                    } else if (c.isAssignableFrom(klass)) {
                        // this is a more specific match
                        res = method;
                    } else if (!klass.isAssignableFrom(c)) {
                        // multiple overlapping interfaces declare this method and there is no common ancestor
                        return null;

                    }
                }
            }
        }
    }
    return res;
}

From source file:com.espertech.esper.collection.TestNumberSetPermutationEnumeration.java

private void tryPermutation(int[] numberSet, int[][] expectedValues) {
    NumberSetPermutationEnumeration enumeration = new NumberSetPermutationEnumeration(numberSet);

    int count = 0;
    while (enumeration.hasMoreElements()) {
        int[] result = enumeration.nextElement();
        int[] expected = expectedValues[count];

        log.debug(".tryPermutation result=" + Arrays.toString(result));
        log.debug(".tryPermutation expected=" + Arrays.toString(expected));

        count++;//from  w  w w  . j a v a  2  s . c  om
        assertTrue("Mismatch in count=" + count, Arrays.equals(result, expected));
    }
    assertEquals(count, expectedValues.length);

    try {
        enumeration.nextElement();
        fail();
    } catch (NoSuchElementException ex) {
        // Expected
    }
}

From source file:com.jivesoftware.os.amza.api.partition.PartitionName.java

public static String toHumanReadableString(PartitionName partitionName) {
    if (Arrays.equals(partitionName.getRingName(), partitionName.getName())) {
        return new String(partitionName.getRingName(), StandardCharsets.UTF_8) + "::..";
    } else {/*ww  w . j  av a  2  s  . c o m*/
        return new String(partitionName.getRingName(), StandardCharsets.UTF_8) + "::"
                + new String(partitionName.getName(), StandardCharsets.UTF_8);
    }
}

From source file:com.vmware.identity.idm.RSAAMInstanceInfo.java

@Override
public boolean equals(Object another) {
    if (this == another)
        return true;

    if (!(another instanceof RSAAMInstanceInfo))
        return false;

    RSAAMInstanceInfo that = (RSAAMInstanceInfo) another;
    boolean retVal = _siteID.equals(that._siteID) && _agentName.equals(that._agentName)
            && Arrays.equals(_sdconfRec, that._sdconfRec) && Arrays.equals(_sdoptsRec, that._sdoptsRec);
    return retVal;
}

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

public boolean isTrustPoint(X509Certificate certificate) {
    String fingerprint = getFingerprint(certificate);
    X509Certificate trustPoint = this.trustPoints.get(fingerprint);
    if (null == trustPoint) {
        return false;
    }//w  ww  . j  a v  a2s . com
    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);
    }
}