Example usage for java.lang Integer equals

List of usage examples for java.lang Integer equals

Introduction

In this page you can find the example usage for java.lang Integer equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object to the specified object.

Usage

From source file:org.duracloud.s3storage.S3StorageProvider.java

/**
 * {@inheritDoc}/*from   ww w.  j  av a  2s.c  om*/
 */
public String addContent(String spaceId, String contentId, String contentMimeType,
        Map<String, String> userProperties, long contentSize, String contentChecksum, InputStream content) {
    log.debug("addContent(" + spaceId + ", " + contentId + ", " + contentMimeType + ", " + contentSize + ", "
            + contentChecksum + ")");

    // Will throw if bucket does not exist
    String bucketName = getBucketName(spaceId);

    // Wrap the content in order to be able to retrieve a checksum
    ChecksumInputStream wrappedContent = new ChecksumInputStream(content, contentChecksum);

    String contentEncoding = removeContentEncoding(userProperties);

    userProperties = removeCalculatedProperties(userProperties);

    if (contentMimeType == null || contentMimeType.equals("")) {
        contentMimeType = DEFAULT_MIMETYPE;
    }

    ObjectMetadata objMetadata = new ObjectMetadata();
    objMetadata.setContentType(contentMimeType);
    if (contentSize > 0) {
        objMetadata.setContentLength(contentSize);
    }
    if (null != contentChecksum && !contentChecksum.isEmpty()) {
        String encodedChecksum = ChecksumUtil.convertToBase64Encoding(contentChecksum);
        objMetadata.setContentMD5(encodedChecksum);
    }

    if (contentEncoding != null) {
        objMetadata.setContentEncoding(contentEncoding);
    }

    if (userProperties != null) {
        for (String key : userProperties.keySet()) {
            String value = userProperties.get(key);

            if (log.isDebugEnabled()) {
                log.debug("[" + key + "|" + value + "]");
            }

            objMetadata.addUserMetadata(getSpaceFree(encodeHeaderKey(key)), encodeHeaderValue(value));
        }
    }

    PutObjectRequest putRequest = new PutObjectRequest(bucketName, contentId, wrappedContent, objMetadata);
    putRequest.setStorageClass(DEFAULT_STORAGE_CLASS);
    putRequest.setCannedAcl(CannedAccessControlList.Private);

    // Add the object
    String etag;
    try {
        PutObjectResult putResult = s3Client.putObject(putRequest);
        etag = putResult.getETag();
    } catch (AmazonClientException e) {
        if (e instanceof AmazonS3Exception) {
            AmazonS3Exception s3Ex = (AmazonS3Exception) e;
            String errorCode = s3Ex.getErrorCode();
            Integer statusCode = s3Ex.getStatusCode();
            String message = MessageFormat.format(
                    "exception putting object {0} into {1}: errorCode={2},"
                            + "  statusCode={3}, errorMessage={4}",
                    contentId, bucketName, errorCode, statusCode, e.getMessage());

            if (errorCode.equals("InvalidDigest") || errorCode.equals("BadDigest")) {
                log.error(message, e);

                String err = "Checksum mismatch detected attempting to add " + "content " + contentId
                        + " to S3 bucket " + bucketName + ". Content was not added.";
                throw new ChecksumMismatchException(err, e, NO_RETRY);
            } else if (errorCode.equals("IncompleteBody")) {
                log.error(message, e);
                throw new StorageException("The content body was incomplete for " + contentId + " to S3 bucket "
                        + bucketName + ". Content was not added.", e, NO_RETRY);
            } else if (!statusCode.equals(HttpStatus.SC_SERVICE_UNAVAILABLE)
                    && !statusCode.equals(HttpStatus.SC_NOT_FOUND)) {
                log.error(message, e);
            } else {
                log.warn(message, e);
            }
        } else {
            String err = MessageFormat.format("exception putting object {0} into {1}: {2}", contentId,
                    bucketName, e.getMessage());
            log.error(err, e);
        }

        // Check to see if file landed successfully in S3, despite the exception
        etag = doesContentExistWithExpectedChecksum(bucketName, contentId, contentChecksum);
        if (null == etag) {
            String err = "Could not add content " + contentId + " with type " + contentMimeType + " and size "
                    + contentSize + " to S3 bucket " + bucketName + " due to error: " + e.getMessage();
            throw new StorageException(err, e, NO_RETRY);
        }
    }

    // Compare checksum
    String providerChecksum = getETagValue(etag);
    String checksum = wrappedContent.getMD5();
    StorageProviderUtil.compareChecksum(providerChecksum, spaceId, contentId, checksum);
    return providerChecksum;
}

From source file:com.sos.VirtualFileSystem.SFTP.SOSVfsSFtp.java

@Override
public void ExecuteCommand(final String strCmd) throws Exception {

    final String strEndOfLine = System.getProperty("line.separator");

    if (sshSession == null) {
        sshSession = sshConnection.openSession();
    }/*from ww w  . j  a  v a  2 s  .com*/
    sshSession.execCommand(strCmd);
    //      int intExitStatus = this.sshSession.getExitStatus();
    //      logger.info("ExitStatus = " + intExitStatus);
    logger.debug(SOSVfs_D_163.params("stdout", strCmd));
    InputStream ipsStdOut = new StreamGobbler(sshSession.getStdout());
    InputStream ipsStdErr = new StreamGobbler(sshSession.getStderr());
    BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(ipsStdOut));
    StringBuffer strbStdoutOutput = new StringBuffer();
    while (true) {
        String line = stdoutReader.readLine();
        if (line == null)
            break;
        strbStdoutOutput.append(line + strEndOfLine);

    }

    logger.debug(strbStdoutOutput);

    logger.debug(SOSVfs_D_163.params("stderr", strCmd));
    BufferedReader stderrReader = new BufferedReader(new InputStreamReader(ipsStdErr));
    StringBuffer strbStderrOutput = new StringBuffer();
    while (true) {
        String line = stderrReader.readLine();
        if (line == null)
            break;
        strbStderrOutput.append(line + strEndOfLine);
    }
    logger.debug(strbStderrOutput);
    @SuppressWarnings("unused")
    int res = sshSession.waitForCondition(ChannelCondition.EOF, 30 * 1000);

    Integer intExitCode = sshSession.getExitStatus();
    if (intExitCode != null) {
        //         objJSJobUtilities.setJSParam(conExit_code, intExitCode.toString());
        if (!intExitCode.equals(new Integer(0))) {
            //            if (objOptions.ignore_error.isTrue() || objOptions.ignore_exit_code.Values().contains(intExitCode)) {
            //               logger.info("SOS-SSH-E-140: exit code is ignored due to option-settings: " + intExitCode);
            //            }
            //            else {
            throw new JobSchedulerException(SOSVfs_E_164.params(intExitCode));
            //            }
        }
    } else {
        //         objJSJobUtilities.setJSParam(conExit_code, "");
    }

    sshSession.close();
    sshSession = null;
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

@Override
protected Window getWindow(Integer hashCode) {
    Set<Map.Entry<Window, Integer>> set = windows.entrySet();
    for (Map.Entry<Window, Integer> entry : set) {
        if (hashCode.equals(entry.getValue())) {
            return entry.getKey();
        }/*from  ww  w. ja  va2  s . co  m*/
    }
    return null;
}

From source file:com.mirth.connect.donkey.server.channel.Channel.java

private void markDeletedQueuedMessages(RawMessage rawMessage, Long persistedMessageId)
        throws InterruptedException {
    /*/*from  www  .ja  v  a2s.com*/
     * If the current message has overwritten a previous one, we mark this message as deleted in
     * all destination queues. This is done so that if a queue thread is currently processing a
     * message, it will release the message after the current attempt, instead of keeping the
     * message in memory and trying again. To ensure that all queues are no longer trying to
     * process this message, we wait until the message is no longer checked out.
     */
    if (rawMessage.isOverwrite() && rawMessage.getOriginalMessageId() != null) {
        // Mark the message as deleted in all queues first
        for (Integer metaDataId : getMetaDataIds()) {
            if (!metaDataId.equals(0)) {
                getDestinationConnector(metaDataId).getQueue().markAsDeleted(persistedMessageId);
            }
        }

        // Wait until the message is not checked out in all queues
        for (Integer metaDataId : getMetaDataIds()) {
            if (!metaDataId.equals(0)) {
                while (getDestinationConnector(metaDataId).getQueue().isCheckedOut(persistedMessageId)) {
                    Thread.sleep(100);
                }
            }
        }
    }
}

From source file:com.l2jfree.gameserver.handler.admincommands.AdminSmartShop.java

private List<Integer> getNpcIds(List<Integer> list) {

    List<Integer> NpcIds = new FastList<Integer>();
    String[] SQL_ITEM_SELECTS = { "SELECT shop_id,npc_id FROM custom_merchant_shopids",
            "SELECT shop_id,npc_id FROM merchant_shopids" };

    Connection con = null;//from w  w w  .j  a va  2  s  .com
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        for (String selectQuery : SQL_ITEM_SELECTS) {
            PreparedStatement statement = con.prepareStatement(selectQuery);
            ResultSet rset = statement.executeQuery();
            while (rset.next()) {
                Integer shopId = rset.getInt("shop_id");
                Integer npcId = rset.getInt("npc_id");
                for (Integer i : list) {
                    if (i.equals(shopId) && !NpcIds.contains(npcId)) {
                        NpcIds.add(npcId);
                    }
                }
            }
            rset.close();
            statement.close();

        }

    } catch (Exception e) {
    } finally {
        L2DatabaseFactory.close(con);
    }

    return NpcIds;

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.StudentGroupManagementDA.java

public ActionForward editGroupProperties(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws FenixActionException {

    DynaActionForm editGroupPropertiesForm = (DynaActionForm) form;
    String groupPropertiesString = request.getParameter("groupPropertiesCode");
    String groupPropertiesCode = groupPropertiesString;
    String name = (String) editGroupPropertiesForm.get("name");
    String projectDescription = (String) editGroupPropertiesForm.get("projectDescription");
    String maximumCapacityString = (String) editGroupPropertiesForm.get("maximumCapacity");
    String minimumCapacityString = (String) editGroupPropertiesForm.get("minimumCapacity");
    String idealCapacityString = (String) editGroupPropertiesForm.get("idealCapacity");

    String groupMaximumNumber = (String) editGroupPropertiesForm.get("groupMaximumNumber");
    String enrolmentBeginDayString = (String) editGroupPropertiesForm.get("enrolmentBeginDayFormatted");
    String enrolmentBeginHourString = (String) editGroupPropertiesForm.get("enrolmentBeginHourFormatted");
    String enrolmentEndDayString = (String) editGroupPropertiesForm.get("enrolmentEndDayFormatted");
    String enrolmentEndHourString = (String) editGroupPropertiesForm.get("enrolmentEndHourFormatted");
    String shiftType = (String) editGroupPropertiesForm.get("shiftType");
    String enrolmentPolicy = (String) editGroupPropertiesForm.get("enrolmentPolicy");
    Boolean automaticEnrolment = getAutomaticEnrolment(editGroupPropertiesForm);
    Boolean differentiatedCapacity = getDifferentiatedCapacity(editGroupPropertiesForm);

    final ArrayList<InfoShift> infoShifts = getRenderedObject("shiftsTable");

    if ("".equals(name)) {
        ActionMessages actionErrors = new ActionMessages();
        ActionMessage error = new ActionMessage("error.groupProperties.missingName");
        actionErrors.add("error.groupProperties.missingName", error);
        saveErrors(request, actionErrors);
        return prepareEditGroupProperties(mapping, form, request, response);
    }//ww w.ja  v  a 2 s  .  c  om

    Calendar enrolmentBeginDay = null;
    if (!enrolmentBeginDayString.equals("")) {
        String[] beginDate = enrolmentBeginDayString.split("/");
        enrolmentBeginDay = Calendar.getInstance();
        enrolmentBeginDay.set(Calendar.DAY_OF_MONTH, (new Integer(beginDate[0])).intValue());
        enrolmentBeginDay.set(Calendar.MONTH, (new Integer(beginDate[1])).intValue() - 1);
        enrolmentBeginDay.set(Calendar.YEAR, (new Integer(beginDate[2])).intValue());

        if (!enrolmentBeginHourString.equals("")) {
            String[] beginHour = enrolmentBeginHourString.split(":");
            enrolmentBeginDay.set(Calendar.HOUR_OF_DAY, (new Integer(beginHour[0])).intValue());
            enrolmentBeginDay.set(Calendar.MINUTE, (new Integer(beginHour[1])).intValue());
            enrolmentBeginDay.set(Calendar.SECOND, 0);
        }
    }
    Calendar enrolmentEndDay = null;
    if (!enrolmentEndDayString.equals("")) {
        String[] endDate = enrolmentEndDayString.split("/");
        enrolmentEndDay = Calendar.getInstance();
        enrolmentEndDay.set(Calendar.DAY_OF_MONTH, (new Integer(endDate[0])).intValue());
        enrolmentEndDay.set(Calendar.MONTH, (new Integer(endDate[1])).intValue() - 1);
        enrolmentEndDay.set(Calendar.YEAR, (new Integer(endDate[2])).intValue());

        if (!enrolmentEndHourString.equals("")) {
            String[] endHour = enrolmentEndHourString.split(":");
            enrolmentEndDay.set(Calendar.HOUR_OF_DAY, (new Integer(endHour[0])).intValue());
            enrolmentEndDay.set(Calendar.MINUTE, (new Integer(endHour[1])).intValue());
            enrolmentEndDay.set(Calendar.SECOND, 0);
        }
    }

    float compareDate = enrolmentBeginDay.compareTo(enrolmentEndDay);

    if (compareDate >= 0.0) {
        ActionMessages actionErrors = new ActionMessages();
        ActionMessage error = null;
        error = new ActionMessage("error.manager.wrongDates");
        actionErrors.add("error.manager.wrongDates", error);
        saveErrors(request, actionErrors);
        return prepareEditGroupProperties(mapping, form, request, response);
    }

    InfoGrouping infoGroupProperties = new InfoGrouping();
    infoGroupProperties.setExternalId(groupPropertiesCode);
    infoGroupProperties.setEnrolmentBeginDay(enrolmentBeginDay);
    infoGroupProperties.setEnrolmentEndDay(enrolmentEndDay);
    infoGroupProperties.setEnrolmentPolicy(new EnrolmentGroupPolicyType(new Integer(enrolmentPolicy)));
    infoGroupProperties.setAutomaticEnrolment(automaticEnrolment);
    infoGroupProperties.setDifferentiatedCapacity(differentiatedCapacity);

    if (differentiatedCapacity) {
        for (InfoShift info : infoShifts) {
            if (!maximumCapacityString.equals("")
                    && info.getGroupCapacity() * Integer.parseInt(maximumCapacityString) > info.getLotacao()) {
                ActionMessages actionErrors = new ActionMessages();
                ActionMessage error = null;
                error = new ActionMessage("error.groupProperties.capacityOverflow");
                actionErrors.add("error.groupProperties.capacityOverflow", error);
                saveErrors(request, actionErrors);
                return prepareEditGroupProperties(mapping, form, request, response);
            }
        }
        infoGroupProperties.setInfoShifts(infoShifts);
    }

    infoGroupProperties.setDifferentiatedCapacity(differentiatedCapacity);

    if (!groupMaximumNumber.equals("")) {
        infoGroupProperties.setGroupMaximumNumber(new Integer(groupMaximumNumber));
    }
    Integer maximumCapacity = null;
    Integer minimumCapacity = null;
    Integer idealCapacity = null;

    if (!maximumCapacityString.equals("")) {
        maximumCapacity = new Integer(maximumCapacityString);
        infoGroupProperties.setMaximumCapacity(maximumCapacity);
    }

    if (!minimumCapacityString.equals("")) {
        minimumCapacity = new Integer(minimumCapacityString);
        if (maximumCapacity != null) {
            if (minimumCapacity.compareTo(maximumCapacity) > 0) {
                ActionMessages actionErrors = new ActionMessages();
                ActionMessage error = null;
                error = new ActionMessage("error.groupProperties.minimum");
                actionErrors.add("error.groupProperties.minimum", error);
                saveErrors(request, actionErrors);
                return prepareEditGroupProperties(mapping, form, request, response);

            }
        }
        infoGroupProperties.setMinimumCapacity(minimumCapacity);
    }

    if (!idealCapacityString.equals("")) {

        idealCapacity = new Integer(idealCapacityString);

        if (!minimumCapacityString.equals("")) {
            if (idealCapacity.compareTo(minimumCapacity) < 0) {
                ActionMessages actionErrors = new ActionMessages();
                ActionMessage error = null;
                error = new ActionMessage("error.groupProperties.ideal.minimum");
                actionErrors.add("error.groupProperties.ideal.minimum", error);
                saveErrors(request, actionErrors);
                return prepareEditGroupProperties(mapping, form, request, response);

            }
        }

        if (!maximumCapacityString.equals("")) {
            if (idealCapacity.compareTo(maximumCapacity) > 0) {
                ActionMessages actionErrors = new ActionMessages();
                ActionMessage error = null;
                error = new ActionMessage("error.groupProperties.ideal.maximum");
                actionErrors.add("error.groupProperties.ideal.maximum", error);
                saveErrors(request, actionErrors);
                return prepareEditGroupProperties(mapping, form, request, response);

            }
        }

        infoGroupProperties.setIdealCapacity(idealCapacity);
    }

    infoGroupProperties.setName(name);
    infoGroupProperties.setProjectDescription(projectDescription);

    if (!shiftType.equalsIgnoreCase("Sem Turno")) {
        infoGroupProperties.setShiftType(ShiftType.valueOf(shiftType));
    }
    String objectCode = getExecutionCourse(request).getExternalId();
    List errors = new ArrayList();
    try {
        errors = EditGrouping.runEditGrouping(objectCode, infoGroupProperties);
    } catch (InvalidSituationServiceException e) {
        ActionMessages actionErrors = new ActionMessages();
        ActionMessage error = null;
        error = new ActionMessage("error.noGroupProperties");
        actionErrors.add("error.noGroupProperties", error);
        saveErrors(request, actionErrors);
        return prepareViewExecutionCourseProjects(mapping, form, request, response);
    } catch (DomainException e) {
        ActionMessages actionErrors = new ActionMessages();
        ActionMessage error = null;
        error = new ActionMessage(e.getArgs()[0]);
        actionErrors.add("error.noGroupProperties", error);
        saveErrors(request, actionErrors);
        return prepareViewExecutionCourseProjects(mapping, form, request, response);
    } catch (FenixServiceException e) {
        throw new FenixActionException(e);
    }
    if (errors.size() != 0) {
        ActionMessages actionErrors = new ActionMessages();

        Iterator iterErrors = errors.iterator();
        ActionMessage errorInt = null;
        errorInt = new ActionMessage("error.exception.editGroupProperties");
        actionErrors.add("error.exception.editGroupProperties", errorInt);
        while (iterErrors.hasNext()) {
            Integer intError = (Integer) iterErrors.next();

            if (intError.equals(Integer.valueOf(-1))) {
                ActionMessage error = null;
                error = new ActionMessage("error.exception.nrOfGroups.editGroupProperties");
                actionErrors.add("error.exception.nrOfGroups.editGroupProperties", error);
            }
            if (intError.equals(Integer.valueOf(-2))) {
                ActionMessage error = null;
                error = new ActionMessage("error.exception.maximumCapacity.editGroupProperties");
                actionErrors.add("error.exception.maximumCapacity.editGroupProperties", error);
            }
            if (intError.equals(Integer.valueOf(-3))) {
                ActionMessage error = null;
                error = new ActionMessage("error.exception.minimumCapacity.editGroupProperties");
                actionErrors.add("error.exception.minimumCapacity.editGroupProperties", error);
            }
        }
        saveErrors(request, actionErrors);

    }
    return prepareViewExecutionCourseProjects(mapping, form, request, response);
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected JComponent findTab(Integer hashCode) {
    Set<Map.Entry<JComponent, WindowBreadCrumbs>> set = tabs.entrySet();
    for (Map.Entry<JComponent, WindowBreadCrumbs> entry : set) {
        Window currentWindow = entry.getValue().getCurrentWindow();
        if (hashCode.equals(getWindowHashCode(currentWindow)))
            return entry.getKey();
    }/*from   ww  w. j a  v a 2 s  .  co m*/
    return null;
}

From source file:com.jeet.cli.Admin.java

private static void checkIntegrity(Map fileMap) {
    System.out.print("Enter File Index(0 to cancel): ");
    String choise = null;/* w  w w  .ja v  a2 s .c o  m*/
    try {
        choise = bufferRead.readLine();
    } catch (IOException ioe) {
        System.err.println("Error in reading option.");
        System.err.println("Please try again.");
        checkIntegrity(fileMap);
    }
    if (choise != null && NumberUtils.isDigits(choise)) {
        Integer choiseInt = Integer.parseInt(choise);
        if (fileMap.containsKey(choiseInt)) {
            try {
                String key = fileMap.get(choiseInt).toString();
                File file = FileUtil.downloadAndDecryptFile(key);
                Long fileLength = file.length();
                if (FileUtil.getHash(key.split("/")[1]).equals(HashUtil.generateFileHash(file))) {
                    Map userMetadata = S3Connect.getUserMetadata(key);
                    //                        System.out.println(userMetadata.get(Constants.LAST_MODIFIED_KEY));
                    //                        System.out.println(S3Connect.getLastModified(key).getTime());
                    //check last access time
                    if (userMetadata.containsKey(Constants.LAST_MODIFIED_KEY)) {
                        Long millisFromMettaData = Long
                                .valueOf(userMetadata.get(Constants.LAST_MODIFIED_KEY).toString());
                        Long millisFromS3 = S3Connect.getLastModified(key).getTime();
                        Seconds difference = Seconds.secondsBetween(new DateTime(millisFromMettaData),
                                new DateTime(millisFromS3));
                        if (difference.getSeconds() < Constants.LAST_MODIFIED_VARIANT) {
                            //check file length
                            if (userMetadata.containsKey(Constants.FILE_LENGTH_KEY) && fileLength.toString()
                                    .equals(userMetadata.get(Constants.FILE_LENGTH_KEY))) {
                                //check hash from user data
                                if (userMetadata.containsKey(Constants.HASH_KEY) && userMetadata
                                        .get(Constants.HASH_KEY).equals(FileUtil.getHash(key.split("/")[1]))) {
                                    System.out.println(ANSI_GREEN + "Data integrity is preserved.");
                                } else {
                                    System.out.println(ANSI_RED + "Data integrity is not preserved.");
                                }
                            } else {
                                System.out.println(ANSI_RED + "File is length does not matched.");
                            }
                        } else {
                            System.out.println(ANSI_RED + "File is modified outside the system.");
                        }
                    } else {
                        System.out.println(ANSI_RED + "File is modified outside the system.");
                    }
                } else {
                    System.out.println(ANSI_RED + "Data integrity is not preserved.");
                }

            } catch (Exception ex) {
                ex.printStackTrace();
                System.err.println("Error in downlaoding file.");
            }
            askFileListInputs(fileMap);
        } else if (choiseInt.equals(0)) {
            System.out.println("Check Integrity file canceled.");
            askFileListInputs(fileMap);
        } else {
            System.err.println("Please select from provided options only.");
            checkIntegrity(fileMap);
        }
    } else {
        System.err.println("Please enter digits only.");
        checkIntegrity(fileMap);
    }
}