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.enonic.cms.core.portal.instruction.CreateResourceUrlInstruction.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*www  .j  a  v a2s. com*/
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    CreateResourceUrlInstruction that = (CreateResourceUrlInstruction) o;

    if (!Arrays.equals(params, that.params)) {
        return false;
    }
    if (resolvedPath != null ? !resolvedPath.equals(that.resolvedPath) : that.resolvedPath != null) {
        return false;
    }

    return true;
}

From source file:org.cloudfoundry.identity.uaa.scim.PasswordChangeRequest.java

public void setSchemas(String[] schemas) {
    Assert.isTrue(Arrays.equals(ScimUser.SCHEMAS, schemas),
            "Only schema '" + ScimUser.SCHEMAS[0] + "' is currently supported");
}

From source file:Main.java

@SuppressLint("NewApi")
public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) {
    List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange();
    Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges));
    if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) {
        int[] suitableFPSRange = null;
        for (int[] fpsRange : supportedPreviewFpsRanges) {
            int thisMin = fpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX];
            int thisMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX];
            if (thisMin >= minFPS * 1000 && thisMax <= maxFPS * 1000) {
                suitableFPSRange = fpsRange;
                break;
            }/*  w  w w . j a v  a  2s  . c o m*/
        }
        if (suitableFPSRange == null) {
            Log.i(TAG, "No suitable FPS range?");
        } else {
            int[] currentFpsRange = new int[2];
            parameters.getPreviewFpsRange(currentFpsRange);
            if (Arrays.equals(currentFpsRange, suitableFPSRange)) {
                Log.i(TAG, "FPS range already set to " + Arrays.toString(suitableFPSRange));
            } else {
                Log.i(TAG, "Setting FPS range to " + Arrays.toString(suitableFPSRange));
                parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
                        suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
            }
        }
    }
}

From source file:additionalpipes.inventory.components.PropertyIntArray.java

@Override
public boolean equalsValue(Object obj) {
    if (obj instanceof List) {
        return Ints.asList(value).equals(obj);
    }/*from w  w  w .j  a v a 2  s.co m*/
    return obj instanceof int[] && Arrays.equals(value, (int[]) obj);
}

From source file:ru.mystamps.web.validation.jsr303.ImageFileValidator.java

private static boolean isJpeg(byte[] bytes) {
    // TODO: also check that last 2 bytes are FF D9 (use RandomAccessFile)

    for (byte[] signature : JPEG_SIGNATURES) {
        if (Arrays.equals(bytes, signature)) {
            return true;
        }/*from w  ww.j a v a2 s .com*/
    }

    return false;
}

From source file:com.gs.plistconv.matchers.RsBodyMatcher.java

@Override
protected boolean matchesSafely(Response item) {
    try {/*from  w  w w.j  a v a2  s.c o m*/
        return Arrays.equals(IOUtils.toByteArray(item.body()), expectedBody);
    } catch (IOException e) {
        return false;
    }
}

From source file:ObjectUtils.java

/**
 * Determine if the given objects are equal, returning <code>true</code>
 * if both are <code>null</code> or <code>false</code> if only one is
 * <code>null</code>./*from   w w w.j  av a  2  s .com*/
 * <p>Compares arrays with <code>Arrays.equals</code>, performing an equality
 * check based on the array elements rather than the array reference.
 * @param o1 first Object to compare
 * @param o2 second Object to compare
 * @return whether the given objects are equal
 * @see java.util.Arrays#equals
 */
public static boolean nullSafeEquals(Object o1, Object o2) {
    if (o1 == o2) {
        return true;
    }
    if (o1 == null || o2 == null) {
        return false;
    }
    if (o1.equals(o2)) {
        return true;
    }
    if (o1 instanceof Object[] && o2 instanceof Object[]) {
        return Arrays.equals((Object[]) o1, (Object[]) o2);
    }
    if (o1 instanceof boolean[] && o2 instanceof boolean[]) {
        return Arrays.equals((boolean[]) o1, (boolean[]) o2);
    }
    if (o1 instanceof byte[] && o2 instanceof byte[]) {
        return Arrays.equals((byte[]) o1, (byte[]) o2);
    }
    if (o1 instanceof char[] && o2 instanceof char[]) {
        return Arrays.equals((char[]) o1, (char[]) o2);
    }
    if (o1 instanceof double[] && o2 instanceof double[]) {
        return Arrays.equals((double[]) o1, (double[]) o2);
    }
    if (o1 instanceof float[] && o2 instanceof float[]) {
        return Arrays.equals((float[]) o1, (float[]) o2);
    }
    if (o1 instanceof int[] && o2 instanceof int[]) {
        return Arrays.equals((int[]) o1, (int[]) o2);
    }
    if (o1 instanceof long[] && o2 instanceof long[]) {
        return Arrays.equals((long[]) o1, (long[]) o2);
    }
    if (o1 instanceof short[] && o2 instanceof short[]) {
        return Arrays.equals((short[]) o1, (short[]) o2);
    }
    return false;
}

From source file:com.hypersocket.auth.PasswordEncryptionService.java

public boolean authenticate(char[] attemptedPassword, byte[] encryptedPassword, byte[] salt,
        PasswordEncryptionType type) 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, type);

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

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) {
    List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange();
    Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges));
    if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) {
        int[] suitableFPSRange = null;
        for (int[] fpsRange : supportedPreviewFpsRanges) {
            int thisMin = fpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX];
            int thisMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX];
            if (thisMin >= minFPS * 1000 && thisMax <= maxFPS * 1000) {
                suitableFPSRange = fpsRange;
                break;
            }//w w w  .j  a  v a2 s.co m
        }
        if (suitableFPSRange == null) {
            Log.i(TAG, "No suitable FPS range?");
        } else {
            int[] currentFpsRange = new int[2];
            parameters.getPreviewFpsRange(currentFpsRange);
            if (Arrays.equals(currentFpsRange, suitableFPSRange)) {
                Log.i(TAG, "FPS range already set to " + Arrays.toString(suitableFPSRange));
            } else {
                Log.i(TAG, "Setting FPS range to " + Arrays.toString(suitableFPSRange));
                parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
                        suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
            }
        }
    }
}

From source file:Main.java

/**
 * Compare two input stream//www .  j  a  va  2  s  . c o m
 * 
 * @param input1 the first stream
 * @param input2 the second stream
 * @return true if the streams contain the same content, or false otherwise
 * @throws IOException
 * @throws IllegalArgumentException if the stream is null
 */
public static boolean isSame(InputStream input1, InputStream input2) throws IOException {
    boolean error = false;
    try {
        byte[] buffer1 = new byte[1024];
        byte[] buffer2 = new byte[1024];
        try {
            int numRead1 = 0;
            int numRead2 = 0;
            while (true) {
                numRead1 = input1.read(buffer1);
                numRead2 = input2.read(buffer2);
                if (numRead1 > -1) {
                    if (numRead2 != numRead1)
                        return false;
                    // Otherwise same number of bytes read
                    if (!Arrays.equals(buffer1, buffer2))
                        return false;
                    // Otherwise same bytes read, so continue ...
                } else {
                    // Nothing more in stream 1 ...
                    return numRead2 < 0;
                }
            }
        } finally {
            input1.close();
        }
    } catch (IOException e) {
        error = true; // this error should be thrown, even if there is an error closing stream 2
        throw e;
    } catch (RuntimeException e) {
        error = true; // this error should be thrown, even if there is an error closing stream 2
        throw e;
    } finally {
        try {
            input2.close();
        } catch (IOException e) {
            if (!error)
                throw e;
        }
    }
}