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:com.oncore.calorders.rest.service.extension.OrderHistoryFacadeRESTExtension.java

/**
 * Fetch all orders grouped by quarter for the last 4 years. For this
 * iteration the orders are pulled for the last four years (including the
 * current year), which are 2017,16,15,14
 *
 * @param departmentId//from w w w.  j a  va  2  s.  co  m
 * @return a structure of order totals grouped by quarter
 *
 * @throws com.oncore.calorders.core.exceptions.DataAccessException
 */
@GET
@Path("fetchOrdersByQuarter/{departmentId}")
@Produces({ MediaType.APPLICATION_JSON })
public OrdersByQuarterSeriesData fetchOrdersByQuarter(@PathParam("departmentId") Integer departmentId)
        throws DataAccessException {

    List<OrderHistory> orderHistoryList = null;
    OrdersByQuarterSeriesData ordersByQuarterSeriesData = new OrdersByQuarterSeriesData();
    OrdersByQuarterData ordersByQuarterData = null;
    OrderItemData orderItemData = null;
    Calendar cal = Calendar.getInstance();
    Department department = null;

    ordersByQuarterData = new OrdersByQuarterData();
    ordersByQuarterData.setName("Jan");
    ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData);

    ordersByQuarterData = new OrdersByQuarterData();
    ordersByQuarterData.setName("Apr");
    ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData);

    ordersByQuarterData = new OrdersByQuarterData();
    ordersByQuarterData.setName("Jul");
    ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData);

    ordersByQuarterData = new OrdersByQuarterData();
    ordersByQuarterData.setName("Oct");
    ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData);

    try {

        Logger.debug(LOG, "Hey testing logging, the fetchOrdersByQuarter is being called!");

        department = getEntityManager().createNamedQuery("Department.findByDepUid", Department.class)
                .setParameter("depUid", departmentId).getSingleResult();

        orderHistoryList = getEntityManager().createQuery(
                "SELECT o FROM OrderHistory o WHERE o.depUidFk = :departmentId AND o.createTs > '2014:01:01 15:06:39.673' ORDER BY o.createTs ASC",
                OrderHistory.class).setParameter("departmentId", department).getResultList();

        String month = null;
        Integer year = null;

        if (CollectionUtils.isNotEmpty(orderHistoryList)) {

            for (OrderHistory order : orderHistoryList) {
                cal.setTime(order.getCreateTs());

                month = this.getQuarterMonth(cal.get(Calendar.MONTH));
                year = cal.get(Calendar.YEAR);

                if (year.equals(2015)) {
                    year = 2015;
                }

                boolean found = false;

                for (OrdersByQuarterData quarter : ordersByQuarterSeriesData.getOrdersByQuarterDataList()) {
                    if (month.equalsIgnoreCase(quarter.getName())) {

                        found = false;

                        if (CollectionUtils.isEmpty(quarter.getItems())) {
                            OrderItemData item = new OrderItemData();
                            item.setYear(year);
                            item.setY(1);
                            item.setLabel(1);
                            quarter.getItems().add(item);
                        } else {
                            for (OrderItemData item : quarter.getItems()) {
                                if (year.equals(item.getYear())) {
                                    item.setY(item.getY() + 1);
                                    item.setLabel(item.getY());
                                    found = true;
                                    break;
                                }

                            }

                            if (!found) {
                                OrderItemData item = new OrderItemData();
                                item.setYear(year);
                                item.setY(1);
                                item.setLabel(1);
                                quarter.getItems().add(item);
                                break;
                            }

                        }

                    }
                }

            }

        }

    } catch (Exception ex) {
        Logger.error(LOG, FormatHelper.getStackTrace(ex));
        throw new DataAccessException(ex, ErrorCode.DATAACCESSERROR);
    }

    return ordersByQuarterSeriesData;

}

From source file:com.act.biointerpretation.desalting.ReactionDesalter.java

private Pair<List<Long>, Map<Long, Integer>> buildIdAndCoefficientMapping(Reaction oldRxn,
        ReactionComponent sOrP) {//w w w  . j a va2  s  . co m
    Long[] oldChemIds = sOrP == SUBSTRATE ? oldRxn.getSubstrates() : oldRxn.getProducts();
    List<Long> resultIds = new ArrayList<>(oldChemIds.length);
    Map<Long, Integer> newIdToCoefficientMap = new HashMap<>(oldChemIds.length);

    for (Long oldChemId : oldChemIds) {
        Integer originalRxnCoefficient = sOrP == SUBSTRATE ? oldRxn.getSubstrateCoefficient(oldChemId)
                : oldRxn.getProductCoefficient(oldChemId);

        List<Long> newChemIds = oldChemicalIdToNewChemicalIds.get(oldChemId);
        if (newChemIds == null) {
            throw new RuntimeException(String
                    .format("Found old chemical id %d that is not in the old -> new chem id map", oldChemId));
        }

        for (Long newChemId : newChemIds) {
            // Deduplicate new chemicals in the list based on whether we've assigned coefficients for them or not.
            if (newIdToCoefficientMap.containsKey(newChemId)) {
                Integer coefficientAccumulator = newIdToCoefficientMap.get(newChemId);

                // If only one coefficient is null, we have a problem.  Just write null and hope we can figure it out later.
                if ((coefficientAccumulator == null && originalRxnCoefficient != null)
                        || (coefficientAccumulator != null && originalRxnCoefficient == null)) {
                    LOGGER.error(
                            "Found null coefficient that needs to be merged with non-null coefficient. "
                                    + "New chem id: %d, old chem id: %d, coefficient value: %d, old rxn id: %d",
                            newChemId, oldChemId, originalRxnCoefficient, oldRxn.getUUID());
                    newIdToCoefficientMap.put(newChemId, null);
                } else if (coefficientAccumulator != null && originalRxnCoefficient != null) {
                    /* If neither are null, multiply the coefficient to be added by the desalting multiplier and sum that
                     * product with the existing count for this molecule. */
                    Integer desalterMultiplier = desalterMultiplerMap.get(Pair.of(oldChemId, newChemId));
                    originalRxnCoefficient *= desalterMultiplier;

                    newIdToCoefficientMap.put(newChemId, coefficientAccumulator + originalRxnCoefficient);
                } // Else both are null we don't need to do anything.

                // We don't need to add this new id to the list of substrates/products because it's already there.
            } else {
                resultIds.add(newChemId); // Add the new id to the subs/prods list.
                Integer desalterMultiplier = desalterMultiplerMap.get(Pair.of(oldChemId, newChemId));
                if (originalRxnCoefficient == null) {
                    if (!desalterMultiplier.equals(1)) {
                        LOGGER.warn("Ignoring >1 desalting multipler due to existing null coefficient.  "
                                + "New chem id: %d, old chem id: %d, coefficient value: null, multiplier: %d, old rxn id: %d",
                                newChemId, oldChemId, desalterMultiplier, oldRxn.getUUID());
                    }
                    newIdToCoefficientMap.put(newChemId, null);
                } else {
                    newIdToCoefficientMap.put(newChemId, originalRxnCoefficient * desalterMultiplier);
                }
            }
        }
    }
    return Pair.of(resultIds, newIdToCoefficientMap);
}

From source file:org.gooru.insights.api.spring.exception.InsightsExceptionResolver.java

public ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {/* ww w .  j a va2s .c  o  m*/
    ResponseParamDTO<Map<Object, Object>> responseDTO = new ResponseParamDTO<Map<Object, Object>>();
    Map<Object, Object> errorMap = new HashMap<Object, Object>();
    Integer statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    String traceId = request.getAttribute("traceId") != null ? request.getAttribute("traceId").toString()
            : DEFAULT_TRACEID;
    if (ex instanceof BadRequestException) {
        statusCode = HttpServletResponse.SC_BAD_REQUEST;
    } else if (ex instanceof AccessDeniedException) {
        statusCode = HttpServletResponse.SC_FORBIDDEN;
    } else if (ex instanceof NotFoundException) {
        statusCode = HttpServletResponse.SC_NOT_FOUND;
    } else {
        statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }

    if (statusCode.toString().startsWith(Numbers.FOUR.getNumber())) {
        InsightsLogger.debug(traceId, ex);
        errorMap.put(DEVELOPER_MESSAGE, ex.getMessage());
    } else if (statusCode.toString().startsWith(Numbers.FIVE.getNumber())) {
        InsightsLogger.error(traceId, ex);
        errorMap.put(DEVELOPER_MESSAGE, DEFAULT_ERROR);
    } else if (statusCode.equals(HttpServletResponse.SC_NO_CONTENT)) {
        InsightsLogger.error(traceId, ex);
        errorMap.put(DEVELOPER_MESSAGE, CONTENT_UNAVAILABLE);
    }
    errorMap.put(STATUS_CODE, statusCode);
    errorMap.put(MAIL_To, SUPPORT_EMAIL_ID);

    response.setStatus(statusCode);
    responseDTO.setMessage(errorMap);
    return new ModelAndView(modelAttributes.VIEW_NAME.getAttribute(),
            modelAttributes.RETURN_NAME.getAttribute(),
            new JSONSerializer().exclude(ApiConstants.EXCLUDE_CLASSES).deepSerialize(responseDTO));

}

From source file:edu.cornell.kfs.vnd.batch.service.impl.VendorBatchServiceImpl.java

private VendorAddress getVendorAddress(VendorDetail vDetail, Integer vendorAddressGeneratedIdentifier) {
    for (VendorAddress vAddress : vDetail.getVendorAddresses()) {
        if (vendorAddressGeneratedIdentifier.equals(vAddress.getVendorAddressGeneratedIdentifier())) {
            return vAddress;
        }//from   ww w.  ja v  a  2 s .  c om
    }
    return new VendorAddress();
}

From source file:edu.northwestern.bioinformatics.studycalendar.service.StudyService.java

public Study copy(final Study study, final Integer selectedAmendmentId) {
    if (study != null) {
        Amendment amendment = null;//from w  w  w .  ja v  a2 s .c  o  m
        Study revisedStudy = study;
        if (selectedAmendmentId == null) {
            amendment = study.getAmendment();
        } else if (study.getDevelopmentAmendment() != null
                && selectedAmendmentId.equals(study.getDevelopmentAmendment().getId())) {
            amendment = study.getDevelopmentAmendment();
            revisedStudy = deltaService.revise(study, amendment);
        }
        if (amendment == null) {
            throw new StudyCalendarValidationException(
                    "Can not find amendment for given amendment id:" + selectedAmendmentId);
        }
        String newStudyName = this.getNewStudyNameForCopyingStudy(revisedStudy.getName());
        Map<Study, Set<Population>> newStudy = revisedStudy.copy(newStudyName);
        Study copiedStudy = newStudy.keySet().iterator().next();
        Set<Population> populationSet = newStudy.values().iterator().next();
        studyDao.save(copiedStudy);
        Set<Population> populations = new TreeSet<Population>();
        for (Population population : populationSet) {
            Population copiedPopulation = new Population();
            copiedPopulation.setAbbreviation(population.getAbbreviation());
            copiedPopulation.setName(population.getName());
            copiedPopulation.setStudy(null);
            Change change = Add.create(copiedPopulation);
            if (copiedStudy.getDevelopmentAmendment() != null) {
                deltaService.updateRevisionForStudy(copiedStudy.getDevelopmentAmendment(), copiedStudy, change);
                deltaService.saveRevision(copiedStudy.getDevelopmentAmendment());
            }
            copiedPopulation = (Population) ((ChildrenChange) change).getChild();
            populations.add(copiedPopulation);

        }

        List<Epoch> epochs = new ArrayList<Epoch>();
        for (Delta delta : copiedStudy.getDevelopmentAmendment().getDeltas()) {
            if (delta.getNode() instanceof PlannedCalendar) {
                List<ChildrenChange> changes = delta.getChanges();
                for (ChildrenChange change : changes) {
                    if ((ChangeAction.ADD).equals(change.getAction())) {
                        epochs.add((Epoch) change.getChild());
                    }
                }
            }
        }

        for (Epoch epoch : epochs) {
            List<StudySegment> studySegments = epoch.getChildren();
            for (StudySegment studySegment : studySegments) {
                SortedSet<Period> periods = studySegment.getPeriods();
                for (Period period : periods) {
                    List<PlannedActivity> plannedActivities = period.getChildren();
                    for (PlannedActivity plannedActivity : plannedActivities) {
                        plannedActivity.setPopulation(Population.findMatchingPopulationByAbbreviation(
                                populations, plannedActivity.getPopulation()));
                    }
                }
            }
        }
        if (copiedStudy.getDevelopmentAmendment() != null) {
            deltaService.saveRevision(copiedStudy.getDevelopmentAmendment());
        }
        return copiedStudy;
    } else {
        throw new StudyCalendarValidationException("Can not find study");
    }
}

From source file:com.globalsight.connector.blaise.BlaiseCreateJobHandler.java

private boolean isSortDesc(HttpServletRequest request, int pageIndex, int sortBy) {
    boolean isSortDesc = false;

    SessionManager sessionMgr = getSessionManager(request);
    String isSortDescStr = (String) sessionMgr.getAttribute("isSortDesc");
    if (StringUtil.isNotEmpty(isSortDescStr)) {
        isSortDesc = "true".equals(isSortDescStr) ? true : false;
    }// ww  w.  java2  s  .  com

    Integer lastSortChoice = (Integer) sessionMgr.getAttribute(SORTING);
    Integer currentSortChoice = new Integer(sortBy);
    String doSort = (String) request.getParameter(DO_SORT);
    // click column header to reverse sorting
    if (doSort != null) {
        if (lastSortChoice != null && lastSortChoice.equals(currentSortChoice)) {
            isSortDesc = !isSortDesc;
        } else {
            isSortDesc = false;
        }
    }
    // page navigation/filtering/page size change
    else {
        if (lastSortChoice == null || !lastSortChoice.equals(currentSortChoice)) {
            isSortDesc = false;
        }
    }

    sessionMgr.setAttribute("isSortDesc", String.valueOf(isSortDesc));

    return isSortDesc;
}

From source file:ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity.java

/**
 * Returns all Relations for given resourceId
 * /*from w  ww.j  a  va 2s.c o  m*/
 * @param resourceId
 * @return
 */
public List<AbstractResourceRelationEntity> getMasterRelationsForResource(Integer resourceId) {
    List<AbstractResourceRelationEntity> list = new ArrayList<AbstractResourceRelationEntity>();
    list.addAll(getConsumedMasterRelations());
    list.addAll(getProvidedMasterRelations());

    List<AbstractResourceRelationEntity> result = new ArrayList<AbstractResourceRelationEntity>();

    for (AbstractResourceRelationEntity relation : list) {
        if (resourceId.equals(relation.getSlaveResource().getId())) {
            result.add(relation);
        }
    }
    return result;
}

From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java

/**
 * parse excel file data to java object/*w  w  w. j  av  a 2s  . c o  m*/
 * 
 * @param workbookInputStream
 * @param sheetProcessors
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void read(InputStream workbookInputStream, ExcelReadSheetProcessor<?>... sheetProcessors) {
    Assert.isTrue(workbookInputStream != null, "workbookInputStream can't be null");
    Assert.isTrue(sheetProcessors != null && sheetProcessors.length != 0, "sheetProcessor can't be null");
    try {
        Workbook workbook = WorkbookFactory.create(workbookInputStream);
        for (ExcelReadSheetProcessor<?> sheetProcessor : sheetProcessors) {
            ExcelReadContext context = new ExcelReadContext();
            try {
                Class clazz = sheetProcessor.getTargetClass();
                Integer sheetIndex = sheetProcessor.getSheetIndex();
                String sheetName = sheetProcessor.getSheetName();
                context.setCurSheetIndex(sheetIndex);
                context.setCurSheetName(sheetName);

                Sheet sheet = null;
                if (sheetName != null) {
                    try {
                        sheet = workbook.getSheet(sheetName);
                    } catch (IllegalArgumentException e) {
                        // ignore
                    }
                    if (sheet != null && sheetIndex != null
                            && !sheetIndex.equals(workbook.getSheetIndex(sheet))) {
                        throw new IllegalArgumentException(
                                "sheetName[" + sheetName + "] and sheetIndex[" + sheetIndex + "] not match.");
                    }
                } else if (sheetIndex != null) {
                    try {
                        sheet = workbook.getSheetAt(sheetIndex);
                    } catch (IllegalArgumentException e) {
                        // ignore
                    }
                } else {
                    throw new IllegalArgumentException("sheetName or sheetIndex can't be null");
                }
                if (sheet == null) {
                    ExcelReadException e = new ExcelReadException(
                            "Sheet Not Found Exception. for sheet name:" + sheetName);
                    e.setCode(ExcelReadException.CODE_OF_SHEET_NOT_EXSIT);
                    throw e;
                }

                if (sheetIndex == null) {
                    sheetIndex = workbook.getSheetIndex(sheet);
                }
                if (sheetName == null) {
                    sheetName = sheet.getSheetName();
                }
                // do check
                Map<Integer, Map<String, ExcelReadFieldMappingAttribute>> fieldMapping = new HashMap<Integer, Map<String, ExcelReadFieldMappingAttribute>>();
                Map<String, Map<String, ExcelReadFieldMappingAttribute>> src = null;
                if (sheetProcessor.getFieldMapping() != null) {
                    src = sheetProcessor.getFieldMapping().export();
                }
                convertFieldMapping(sheet, sheetProcessor, src, fieldMapping);
                if (sheetProcessor.getTargetClass() != null && sheetProcessor.getFieldMapping() != null
                        && !Map.class.isAssignableFrom(sheetProcessor.getTargetClass())) {
                    readConfigParamVerify(sheetProcessor, fieldMapping);
                }

                // proc sheet
                context.setCurSheet(sheet);
                context.setCurSheetIndex(sheetIndex);
                context.setCurSheetName(sheet.getSheetName());
                context.setCurRow(null);
                context.setCurRowData(null);
                context.setCurRowIndex(null);
                context.setCurColIndex(null);
                context.setCurColIndex(null);
                // beforeProcess
                sheetProcessor.beforeProcess(context);

                if (sheetProcessor.getPageSize() != null) {
                    context.setDataList(new ArrayList(sheetProcessor.getPageSize()));
                } else {
                    context.setDataList(new ArrayList());
                }

                Integer pageSize = sheetProcessor.getPageSize();
                int startRow = sheetProcessor.getStartRowIndex();
                Integer rowEndIndex = sheetProcessor.getEndRowIndex();
                int actLastRow = sheet.getLastRowNum();
                if (rowEndIndex != null) {
                    if (rowEndIndex > actLastRow) {
                        rowEndIndex = actLastRow;
                    }
                } else {
                    rowEndIndex = actLastRow;
                }

                ExcelProcessControllerImpl controller = new ExcelProcessControllerImpl();
                if (pageSize != null) {
                    int total = rowEndIndex - startRow + 1;
                    int pageCount = (total + pageSize - 1) / pageSize;
                    for (int i = 0; i < pageCount; i++) {
                        int start = startRow + pageSize * i;
                        int size = pageSize;
                        if (i == pageCount - 1) {
                            size = rowEndIndex - start + 1;
                        }
                        read(controller, context, sheet, start, size, fieldMapping, clazz,
                                sheetProcessor.getRowProcessor(), sheetProcessor.isTrimSpace());
                        sheetProcessor.process(context, context.getDataList());
                        context.getDataList().clear();
                        if (controller.isDoBreak()) {
                            controller.reset();
                            break;
                        }
                    }
                } else {
                    read(controller, context, sheet, startRow, rowEndIndex - startRow + 1, fieldMapping, clazz,
                            sheetProcessor.getRowProcessor(), sheetProcessor.isTrimSpace());
                    sheetProcessor.process(context, context.getDataList());
                    context.getDataList().clear();
                }
            } catch (RuntimeException e) {
                sheetProcessor.onException(context, e);
            } finally {
                sheetProcessor.afterProcess(context);
            }
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.kuali.coeus.s2sgen.impl.generate.S2SBaseFormGenerator.java

protected String getAnswers(Integer questionSeqId, List<? extends AnswerHeaderContract> answerHeaders) {

    String answer = null;//from   w  w w .j av  a  2  s .  c om
    String childAnswer = null;
    StringBuilder stringBuilder = new StringBuilder();
    if (answerHeaders != null && !answerHeaders.isEmpty()) {
        for (AnswerHeaderContract answerHeader : answerHeaders) {
            List<? extends AnswerContract> answerDetails = answerHeader.getAnswers();
            for (AnswerContract answers : answerDetails) {
                if (questionSeqId.equals(getQuestionAnswerService().findQuestionById(answers.getQuestionId())
                        .getQuestionSeqId())) {
                    answer = answers.getAnswer();
                    if (answer != null) {
                        if (!answer.equals(NOT_ANSWERED)) {
                            stringBuilder.append(answer);
                            stringBuilder.append(",");
                        }
                    }
                    childAnswer = stringBuilder.toString();
                }
            }
        }
    }
    return childAnswer;
}