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.sk89q.craftapi.auth.ConfigurationAuthentication.java

/**
 * Verify username and password pairs using a HMAC digest.
 *
 * @param username/*from   www .  ja  v  a 2 s.  c om*/
 * @param password
 * @return
 */
public boolean verifyCredentials(Mac mac, String username, byte[] digest) {
    List credentials = config.configurationsAt("credential");
    for (Object c : credentials) {
        HierarchicalConfiguration credential = (HierarchicalConfiguration) c;
        String user = credential.getString("username");
        String pass = credential.getString("password");
        if (user != null && pass != null && user.equals(username) && implementsService(credential)) {
            byte[] testDigest = mac.doFinal(pass.getBytes());

            if (Arrays.equals(testDigest, digest)) {
                return true;
            }
        }
    }

    return false;
}

From source file:edu.oregonstate.eecs.mcplan.domains.advising.TakeCourseAction.java

@Override
public boolean equals(final Object obj) {
    if (!(obj instanceof TakeCourseAction)) {
        return false;
    }/*  w  w  w  .  jav  a  2 s  .c o  m*/
    final TakeCourseAction that = (TakeCourseAction) obj;
    return Arrays.equals(courses, that.courses);
}

From source file:com.github.rholder.esthree.command.Get.java

@Override
public Integer call() throws Exception {

    // this is the most up to date digest, it's initialized here but later holds the most up to date valid digest
    currentDigest = MessageDigest.getInstance("MD5");
    currentDigest = retryingGet();/*  w ww . j av  a 2  s .  c om*/

    if (progressListener != null) {
        progressListener.progressChanged(new ProgressEvent(ProgressEventType.TRANSFER_STARTED_EVENT));
    }

    if (!fullETag.contains("-")) {
        byte[] expected = BinaryUtils.fromHex(fullETag);
        byte[] current = currentDigest.digest();
        if (!Arrays.equals(expected, current)) {
            throw new AmazonClientException("Unable to verify integrity of data download.  "
                    + "Client calculated content hash didn't match hash calculated by Amazon S3.  "
                    + "The data may be corrupt.");
        }
    } else {
        // TODO log warning that we can't validate the MD5
        if (verbose) {
            System.err.println("\nMD5 does not exist on AWS for file, calculated value: "
                    + BinaryUtils.toHex(currentDigest.digest()));
        }
    }
    // TODO add ability to resume from previously downloaded chunks
    // TODO add rate limiter

    return 0;

}

From source file:org.dawnsci.persistence.json.function.FunctionListBean.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    FunctionListBean other = (FunctionListBean) obj;
    if (name == null) {
        if (other.name != null)
            return false;
    } else if (!name.equals(other.name))
        return false;
    if (!Arrays.equals(functions, other.functions))
        return false;
    if (type != other.type)
        return false;
    return true;//from w  w  w .  java 2  s . c  om
}

From source file:com.semicolonapps.onepassword.OnePasswordKeychain.java

private void decryptEncryptionKey(String level, String password) throws Exception {
    File keyFile = new File(baseDir, "data/default/encryptionKeys.js");
    JSONObject keys = new JSONObject(new JSONTokener(FileUtils.readFileToString(keyFile)));
    JSONArray list = (JSONArray) keys.get("list");

    for (int i = 0; i < list.length(); i++) {
        JSONObject item = (JSONObject) list.get(i);

        if (item.get("identifier").equals(keys.get(level))) {
            byte[] decryptedKey = new PBKDF2().decrypt(item.get("data").toString(), password);
            byte[] verification = new Aes().decrypt(item.get("validation").toString(), decryptedKey);

            if (Arrays.equals(decryptedKey, verification)) {
                this.decryptedKeys.put(level, decryptedKey);
            }//from  w w w. j  av  a2 s.  co m
        }
    }
}

From source file:com.jivesoftware.os.amza.api.ring.RingMember.java

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }//from www  .  j  a  v a 2s .c  om
    if (getClass() != obj.getClass()) {
        return false;
    }
    RingMember other = (RingMember) obj;
    return Arrays.equals(this.memberAsBytes, other.memberAsBytes);
}

From source file:org.opensafety.hishare.managers.implementation.http.ParcelManagerImpl.java

public Parcel getParcel(String parcelId, String parcelPassword) {
    if (parcelDao.verifyParcelAvailable(parcelId)) {
        Parcel parcel = parcelDao.getById(parcelId);
        try {// w  w w. ja  v a2s .c om
            byte[] hashedPassword = encryption.hashPassword(parcelPassword, parcel.getSalt());
            if (Arrays.equals(hashedPassword, parcel.getHashedPassword())) {
                parcel.setPassword(parcelPassword);
                return parcel;
            } else {
                return null;
            }
        } catch (CryptographyException e) {
            log.error("Password Matching Threw Exception!", e);
            return null;
        }
    }
    return null;
}

From source file:edu.oregonstate.eecs.mcplan.domains.cosmic.ShedLoadAction.java

@Override
public boolean equals(final Object obj) {
    if (!(obj instanceof ShedLoadAction)) {
        return false;
    }//from w  w w . ja v a2 s  . co  m
    final ShedLoadAction that = (ShedLoadAction) obj;
    return Arrays.equals(shunts, that.shunts) && Arrays.equals(amounts, that.amounts);
}

From source file:net.eusashead.spring.gaecache.GaeCacheKey.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    GaeCacheKey other = (GaeCacheKey) obj;
    if (!Arrays.equals(hashes, other.hashes))
        return false;
    return true;//from  w ww .ja v a  2 s . c  o m
}

From source file:convertformat.AdapterBiojavaStructureNucleosideCovalentlyBoundTest.java

@Test
public void testGenerateSequenceFromMyStructureWithProblemInStoringInSequenceDB()
        throws ParsingConfigFileException, IOException {

    AlgoParameters algoParameters = Tools.generateModifiedAlgoParametersForTestWithTestFolders();

    String fourLetterCode = "5a07";
    BiojavaReader reader = new BiojavaReader(algoParameters);
    Pair<String, Structure> pathAndmmcifStructure = null;
    try {/*from  w  ww.ja va  2 s  .  co  m*/
        pathAndmmcifStructure = reader.readFromPDBFolder(fourLetterCode, Tools.testPDBFolder,
                Tools.testChemcompFolder);
    } catch (IOException | ExceptionInIOPackage e) {
        assertTrue(false);
    }
    String hash = null;
    try {
        hash = HashTablesTools.getMD5hash(pathAndmmcifStructure.getKey());
    } catch (NoSuchAlgorithmException e) {
        assertTrue(false);
    }

    AdapterBioJavaStructure adapterBioJavaStructure = new AdapterBioJavaStructure(algoParameters);
    MyStructureIfc mystructure = null;
    try {
        mystructure = adapterBioJavaStructure.getMyStructureAndSkipHydrogens(pathAndmmcifStructure.getValue(),
                hash);
    } catch (ExceptionInMyStructurePackage | ReadingStructurefileException | ExceptionInConvertFormat e) {
        assertTrue(false);
    }

    Group mmcifGDP = pathAndmmcifStructure.getValue().getChain(0).getAtomGroup(395);
    assertTrue(mmcifGDP.getPDBName().equals("GDP"));
    GroupType type = mmcifGDP.getType();
    assertTrue(type == GroupType.NUCLEOTIDE);

    assertTrue(mystructure.getAllAminochains().length == 2);
    // Empty nucleosides chains should had been removed
    assertTrue(mystructure.getAllNucleosidechains().length == 0);

    MyMonomerIfc myStructureGDP = mystructure.getAminoChain(0).getMyMonomerByRank(395);
    assertTrue(Arrays.equals(myStructureGDP.getThreeLetterCode(), "GDP".toCharArray()));
    assertTrue(Arrays.equals(myStructureGDP.getType(), MyMonomerType.NUCLEOTIDE.getType()));
    assertTrue(myStructureGDP.isWasHetatm() == false);
}