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.aurel.track.report.dashboard.StatusOverTimeGraph.java

/**
 * Computes the hierarchical data for status changes
 *
 * @return/*from   ww w. j a  v  a 2 s  .  c  om*/
 */
public static SortedMap<Integer, SortedMap<Integer, Map<Integer, Integer>>> calculateTotalInStatus(
        int[] workItemIDs, Date dateFrom, Date dateTo, List<Integer> statusIDs, int selectedTimeInterval,
        Locale locale) {
    SortedMap<Integer, SortedMap<Integer, Map<Integer, Integer>>> yearToPeriodToStatusIDToStatusNumbersMap = new TreeMap<Integer, SortedMap<Integer, Map<Integer, Integer>>>();

    if (statusIDs != null && statusIDs.isEmpty()) {
        LOGGER.warn("No status specified");
        return yearToPeriodToStatusIDToStatusNumbersMap;
    }
    Set<Integer> statusIDsSet = GeneralUtils.createIntegerSetFromIntegerList(statusIDs);
    if (workItemIDs == null || workItemIDs.length == 0) {
        // LOGGER.warn("No issues satisfy the filtering condition (read right revoked, project/release deleted?)");
        return yearToPeriodToStatusIDToStatusNumbersMap;
    }

    Map<Integer, Integer> statusForWorkItems = new HashMap<Integer, Integer>();
    List<HistorySelectValues> historySelectValuesBefore = null;
    if (dateFrom != null) {
        //get all status changes till the beginning of the reporting period
        //include all statuses (not just the selected ones)
        //because we are interested only in the status at the end of each period
        historySelectValuesBefore = HistoryTransactionBL.getByWorkItemsFieldNewValuesDates(workItemIDs,
                SystemFields.INTEGER_STATE, null, null, dateFrom);
    }
    //get all status changes for the reporting period
    //include all statuses (not just the selected ones)
    //because we are interested only in the status at the end of each period
    List<HistorySelectValues> historySelectValuesReportingPeriod = HistoryTransactionBL
            .getByWorkItemsFieldNewValuesDates(workItemIDs, SystemFields.INTEGER_STATE, null, dateFrom, dateTo);
    SortedMap<Integer, SortedMap<Integer, List<HistorySelectValues>>> periodStatusChangesReportingPeriod = getStatusChangesMap(
            historySelectValuesReportingPeriod, selectedTimeInterval, true/*, statusIDs*/);

    Integer year = null;
    Integer period = null;
    Iterator yearIterator;

    //calculate the values for the beginning of the first reporting period
    if (historySelectValuesBefore != null) {
        //get the first year and period
        if (dateFrom != null) {
            //explicit dateFrom specified by user
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dateFrom);
            year = Integer.valueOf(calendar.get(Calendar.YEAR));
            int calendarInterval = getCalendarInterval(selectedTimeInterval);
            period = Integer.valueOf(calendar.get(calendarInterval));
        } else {
            //no explicit dateFrom specified by the user, get the first found entry in the history
            yearIterator = periodStatusChangesReportingPeriod.keySet().iterator();
            if (yearIterator.hasNext()) {
                year = (Integer) yearIterator.next();
                SortedMap<Integer, List<HistorySelectValues>> intervalToStatusChangeBeans = periodStatusChangesReportingPeriod
                        .get(year);
                Iterator<Integer> periodIterator = intervalToStatusChangeBeans.keySet().iterator();
                period = periodIterator.next();
            }
        }

        if (year == null || period == null) {
            //nothing found
            return yearToPeriodToStatusIDToStatusNumbersMap;
        }

        Iterator<HistorySelectValues> iterator = historySelectValuesBefore.iterator();
        while (iterator.hasNext()) {
            //count the workItems in status till the beginning of the reporting period
            HistorySelectValues historySelectValues = iterator.next();
            Integer workItemID = historySelectValues.getWorkItemID();
            Integer statusID = historySelectValues.getNewValue();
            if (statusForWorkItems.get(workItemID) == null) {
                //take into account only the last stateChange for the workItem
                statusForWorkItems.put(workItemID, statusID);
                if (statusIDsSet.contains(statusID)) {
                    //count only if selected status
                    setCount(yearToPeriodToStatusIDToStatusNumbersMap, year, period, statusID, 1);
                }
            }
        }
    }
    yearIterator = periodStatusChangesReportingPeriod.keySet().iterator();
    while (yearIterator.hasNext()) {
        year = (Integer) yearIterator.next();
        SortedMap intervalToStatusChangeBeans = periodStatusChangesReportingPeriod.get(year);
        Iterator<Integer> periodIterator = intervalToStatusChangeBeans.keySet().iterator();
        while (periodIterator.hasNext()) {
            period = periodIterator.next();
            List statusChangeBeansForInterval = (List) intervalToStatusChangeBeans.get(period);
            if (statusChangeBeansForInterval != null) {
                Iterator statusChangeBeansIterator = statusChangeBeansForInterval.iterator();
                while (statusChangeBeansIterator.hasNext()) {
                    HistorySelectValues historySelectValues = (HistorySelectValues) statusChangeBeansIterator
                            .next();
                    Integer workItemID = historySelectValues.getWorkItemID();
                    Integer nextStatusID = historySelectValues.getNewValue();
                    Integer previousStatus = statusForWorkItems.get(workItemID);
                    if (previousStatus == null) {
                        //probably the item was created in the actual period
                        statusForWorkItems.put(workItemID, nextStatusID);
                        if (statusIDsSet.contains(nextStatusID)) {
                            setCount(yearToPeriodToStatusIDToStatusNumbersMap, year, period, nextStatusID, 1);
                        }
                    } else {
                        if (!previousStatus.equals(nextStatusID)) {
                            statusForWorkItems.put(workItemID, nextStatusID);
                            //add as new status
                            if (statusIDsSet.contains(nextStatusID)) {
                                setCount(yearToPeriodToStatusIDToStatusNumbersMap, year, period, nextStatusID,
                                        1);
                            }
                            //decrement the count for the previous status
                            if (statusIDsSet.contains(previousStatus)) {
                                setCount(yearToPeriodToStatusIDToStatusNumbersMap, year, period, previousStatus,
                                        -1);
                            }
                        }
                    }
                }
            }
        }
    }
    addZerosForEmptyIntervals(dateFrom, dateTo, selectedTimeInterval, yearToPeriodToStatusIDToStatusNumbersMap,
            statusIDs);
    //addTimeSeries(timeSeriesCollection, yearToPeriodToStatusIDToStatusNumbersMap, statusMap, selectedTimeInterval, true);
    return yearToPeriodToStatusIDToStatusNumbersMap;
}

From source file:com.bizintelapps.bugtracker.service.impl.ReportServiceImpl.java

@Override
public List<ProjectReportDto> getProjectReports(Integer project, Integer maxReports, String requestedBy) {
    if (maxReports == null || maxReports < 1) {
        maxReports = 3;/*from  www .  j a va2s.com*/
    }
    Users requestedUser = usersDao.findByUsername(requestedBy);
    Integer org = null;
    List<ProjectReport> list = null;
    List<ProjectReportDto> dtos = new ArrayList<ProjectReportDto>();
    if (project == null || project.equals(0)) {
        org = requestedUser.getOrganization().getId();
        list = projectReportDao.findByOrganizationForTodo(org, maxReports);
    } else {
        list = projectReportDao.findByProject(project, maxReports);
    }
    // copy for display
    for (ProjectReport pr : list) {
        dtos.add(projectReportDtoA.copyForDisplay(pr));
    }
    return dtos;
}

From source file:edu.si.services.beans.cameratrap.UnifiedCameraTrapPostValidationTest.java

/**
 * Setup and run the UnifiedCameraTrapValidatePostIngestResourceCount Route (direct:validatePostIngestResourceCount) using AdviceWith
 * for stubbing in test datastreams and values for testing the route.
 * @param resourceCount our test resource count, this is normally generated by the route during ingest
 * @param resourceRels_Ext RELS-EXT datastream, this is  normally provided by Fedora
 * @param fcrepo_objectResponse our test response query of Fedora relational db and PID, this is normally provided by the FcrepoRest endpoint that will query Fedora relational db and PID
 *///  w w  w . ja v a  2s.  c om
public void runUnifiedCameraTrapValidatePostIngestResourceCountRoute_Test(Integer resourceCount,
        String resourceRels_Ext, String fcrepo_objectResponse) throws Exception {
    //Set headers
    headers.put("SitePID", "test:00000");
    headers.put("ValidationErrors", "ValidationErrors"); //Set the header for aggregation correlation
    headers.put("ResourceCount", resourceCount); //Header that's incremented after a resource obj is ingested.

    //The RELS-EXT datastream that will be used in adviceWith to replace the getDatastreamDissemination endpoint
    // with the same exchange body that fedora would return but modified for our test
    datastream = FileUtils.readFileToString(new File(testDataDir + resourceRels_Ext));

    //add the mock:result endpoint to the end of the ValidationErrorMessageAggregationStrategy route using AdviceWith
    setupValidationErrorMessageAggregationStrategyAdviceWith();

    //Configure and use adviceWith to mock for testing purpose
    context.getRouteDefinition("UnifiedCameraTrapValidatePostIngestResourceCount").adviceWith(context,
            new AdviceWithRouteBuilder() {

                @Override
                public void configure() throws Exception {

                    //replace the getDatastreamDissemination endpoint with the same exchange body that fedora would return but modified for our test
                    weaveByToString(".*getDatastreamDissemination.*").replace().setBody(simple(datastream));

                    //set body for fedora ri search result
                    weaveByType(ToDynamicDefinition.class).replace().setBody(
                            simple(FileUtils.readFileToString(new File(testDataDir + fcrepo_objectResponse))));

                    //Send Validation complete and stop route
                    weaveAddLast().setHeader("ValidationComplete", simple("true"))
                            .to("direct:validationErrorMessageAggregationStrategy").stop();
                }
            });

    //Set mock endpoint for assertion
    mockEndpoint = getMockEndpoint("mock:result");

    // set mock expectations
    mockEndpoint.expectedMessageCount(1);
    //mockEndpoint.setMinimumExpectedMessageCount(1);

    //Send the datastream and headers to the UnifiedCameraTrapValidatePostIngestResourceCount route
    template.sendBodyAndHeaders("direct:validatePostIngestResourceCount", datastream, headers);

    //the mock:result body and header values
    Object resultBody = mockEndpoint.getExchanges().get(0).getIn().getBody();
    Integer relsExtResourceCountResult = mockEndpoint.getExchanges().get(0).getIn()
            .getHeader("RelsExtResourceCount", Integer.class);

    //Setup the Resource Count Validation expected validation error message
    if (!relsExtResourceCountResult.equals(resourceCount)) {
        StringBuilder message = new StringBuilder();
        message.append("Post Resource Count validation failed. ");
        message.append("Expected " + resourceCount + " but found " + relsExtResourceCountResult);

        expectedValidationMessage = cameraTrapValidationMessage.createValidationMessage(camelFileParent,
                message.toString(), false);
        expectedBody.add(expectedValidationMessage);
    }

    //Setup the Resource Object Not Found expected validation error message
    if (fcrepo_objectResponse.contains("not")) {
        expectedValidationMessage = cameraTrapValidationMessage.createValidationMessage(camelFileParent,
                String.valueOf(headers.get("SitePID")), "Resource Object not found from Fedora Repository",
                false);
        expectedBody.add(expectedValidationMessage);
    }

    //assertions
    if (!expectedBody.isEmpty()) {
        log.debug("expectedBody:\n" + expectedBody + "\nresultBody:\n" + resultBody);
        log.debug("expectedBody Type:\n" + expectedBody.getClass() + "\nresultBody Type:\n"
                + resultBody.getClass());

        assertEquals("mock:result Body assertEquals failed!", expectedBody, resultBody);

    } else {
        log.debug("expectedBody:\n" + datastream.trim() + "\nresultBody:\n" + resultBody);
        log.debug("expectedBody Type:\n" + datastream.getClass() + "\nresultBody Type:\n"
                + resultBody.getClass());

        assertEquals("mock:result Body assertEquals failed!", datastream.trim(), resultBody);
    }

    assertMockEndpointsSatisfied();
}

From source file:edu.berkeley.compbio.ncbitaxonomy.NcbiTaxonomyServiceEngineImpl.java

@Nullable
public Integer findTaxidByName(@NotNull String speciesNameA) throws NoSuchNodeException {
    //sometimes the taxid is already in the string
    try {//  www  .ja  v  a  2s .c  o m
        return Integer.parseInt(speciesNameA);
    } catch (NumberFormatException e) {
        // no problem, look for it by name then
    }

    Integer taxIdA = taxIdByName.get(speciesNameA);

    if (taxIdA == null) {
        try {
            taxIdA = ncbiTaxonomyNameDao.findByName(speciesNameA).getTaxon().getId();
        } //if (taxIdA == null)
        catch (NoSuchNodeException e) {
            taxIdA = HASNOTAXID;
        }
        taxIdByName.put(speciesNameA, taxIdA);
    }

    if (taxIdA.equals(HASNOTAXID)) {
        throw new NoSuchNodeException("No taxId found for name: " + speciesNameA);
    }

    return taxIdA;
}

From source file:net.neurowork.cenatic.centraldir.workers.xml.CapacidadXmlImporter.java

private Capacidad importCapacidad(String xmlString, Integer capacityId)
        throws ParserConfigurationException, SAXException, IOException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);
    Capacidad ret = null;/*from   w  ww.ja  v  a  2s.c o m*/
    NodeList nodeLst = doc.getElementsByTagName("capacity");

    for (int s = 0; s < nodeLst.getLength(); s++) {
        Node fstNode = nodeLst.item(s);
        if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
            Element elPDU = (Element) fstNode;
            String code = XmlParserUtil.getAttribute(elPDU, XML_CODE);
            String category = XmlParserUtil.getAttribute(elPDU, "category");
            NodeList fstNm = elPDU.getChildNodes();
            String capacidadName = null;

            if (fstNm.getLength() > 0) {
                capacidadName = ((Node) fstNm.item(0)).getNodeValue();

                Integer capId = AbstractXmlImporter.getId(code);
                Capacidad capacidad = null;
                try {
                    List<Capacidad> capacidades = organizacionService.findCapacidadByName(capacidadName);

                    if (capacidades != null && capacidades.size() > 0) {
                        capacidad = capacidades.get(0);
                    } else {
                        capacidad = new Capacidad();
                        capacidad.setName(capacidadName);
                        if (StringUtils.hasLength(category))
                            capacidad.setCategoria(category);
                        organizacionService.saveCapacidad(capacidad);
                    }

                    if (capId != null && capId.equals(capacityId)) {
                        ret = capacidad;
                    }
                } catch (ServiceException e) {
                    logger.error(e.getMessage());
                }
            }
        }
    }

    if (ret != null) {
        if (logger.isTraceEnabled())
            logger.trace("Se devuelve la Capacidad: " + ret);
        return ret;
    }
    if (logger.isTraceEnabled())
        logger.trace("No se ha encontrado la Capacidad con Id: " + capacityId);
    return null;
}

From source file:edu.berkeley.compbio.ncbitaxonomy.NcbiTaxonomyServiceEngineImpl.java

@Nullable
public Integer findParentTaxidByName(String speciesNameA) throws NoSuchNodeException {
    //sometimes the taxid is already in the string
    try {//w w  w  .java  2  s.  co  m
        return Integer.parseInt(speciesNameA);
    } catch (NumberFormatException e) {
        // no problem, look for it by name then
    }

    Integer taxIdA = taxIdByName.get(speciesNameA);

    if (taxIdA == null) {
        try {
            taxIdA = ncbiTaxonomyNameDao.findByName(speciesNameA).getTaxon().getParent().getId();
        } //if (taxIdA == null)
        catch (NoSuchNodeException e) {
            taxIdA = HASNOTAXID;
        }
        taxIdByName.put(speciesNameA, taxIdA);
    }

    if (taxIdA.equals(HASNOTAXID)) {
        throw new NoSuchNodeException("No taxId found for name: " + speciesNameA);
    }

    return taxIdA;
}

From source file:io.brooklyn.ambari.server.AmbariServerImpl.java

@Override
public void addAlertNotification(String name, String description, Boolean global, String notificationType,
        List<String> alertStates, List<String> ambariDispatchRecipients, String mailSmtpHost,
        Integer mailSmtpPort, String mailSmtpFrom, Boolean mailSmtpAuth) {

    mailSmtpHost = mailSmtpHost.equals("default")
            ? (String) ((Map) getConfig(AmbariCluster.AMBARI_ALERT_NOTIFICATIONS).get("default_properties"))
                    .get("mail.smtp.host")
            : mailSmtpHost;//from  www.j a  v a2  s.com
    mailSmtpPort = mailSmtpPort.equals("587")
            ? (Integer) ((Map) getConfig(AmbariCluster.AMBARI_ALERT_NOTIFICATIONS).get("default_properties"))
                    .get("mail.smtp.port")
            : mailSmtpPort;
    mailSmtpFrom = mailSmtpFrom.equals("default")
            ? (String) ((Map) getConfig(AmbariCluster.AMBARI_ALERT_NOTIFICATIONS).get("default_properties"))
                    .get("mail.smtp.from")
            : mailSmtpFrom;

    Map<String, Object> ambariAlertNotifications = ImmutableMap.<String, Object>builder().put("name", name)
            .put("description", description).put("global", global).put("notification_type", notificationType)
            .put("alert_states", alertStates)
            .put("properties",
                    ImmutableMap.of("ambari.dispatch.recipients", ambariDispatchRecipients, "mail.smtp.host",
                            mailSmtpHost, "mail.smtp.port", mailSmtpPort, "mail.smtp.from", mailSmtpFrom,
                            "mail.smtp.auth", mailSmtpAuth))
            .build();

    createAlertNotification(ambariAlertNotifications);
}

From source file:dylemator.DylematorUI.java

private Dilemma getResults(String type, Integer index) {
    for (Dilemma d : selectedDilemmas) {
        if (type.equals(d.getType()) && index.equals(d.getIndex())) {
            return d;
        }/* w  ww.  j a va  2s  . c  o m*/
    }
    return new Dilemma("", 0);
}

From source file:com.nagarro.core.v1.controller.CartController.java

protected OrderEntryData getCartEntryForNumber(final long number) {
    final List<OrderEntryData> entries = cartFacade.getSessionCart().getEntries();
    if (entries != null && !entries.isEmpty()) {
        final Integer requestedEntryNumber = Integer.valueOf((int) number);
        for (final OrderEntryData entry : entries) {
            if (entry != null && requestedEntryNumber.equals(entry.getEntryNumber())) {
                return entry;
            }// w w  w.j a v  a2  s  . co  m
        }
    }
    return null;
}

From source file:net.mariottini.swing.JFontChooser.java

private void updateSample() {
    String familyName = (String) fontList.getSelectedValue();
    if (familyName == null) {
        return;/*w  w w .ja  v  a  2 s.  c  o m*/
    }

    Integer size = null;
    try {
        size = new Integer(sizeText.getText());
    } catch (Exception nfe) {
        size = (Integer) sizeList.getSelectedValue();
    }

    int style = STYLE_VALUES[styleList.getSelectedIndex()];

    if (!familyName.equals(oldFamily) || !size.equals(oldSize) || style != oldStyle) {
        if (sampleText == null && !familyName.equals(oldFamily)) {
            sampleLabel.setText(familyName);
        }

        if (!familyName.equals(oldFamily)) {
            notifyPropertyChange(FONT_NAME_CHANGED_PROPERTY, oldFamily, familyName);
        }
        if (!size.equals(oldSize)) {
            notifyPropertyChange(FONT_SIZE_CHANGED_PROPERTY, oldSize, size);
        }
        if (style != oldStyle) {
            notifyPropertyChange(FONT_STYLE_CHANGED_PROPERTY, new Integer(oldStyle), new Integer(style));
        }

        sampleLabel.setFont(new Font(familyName, style, size.intValue()));

        oldFamily = familyName;
        oldSize = size;
        oldStyle = style;
    }
}