Example usage for org.apache.commons.collections4 CollectionUtils isEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is empty.

Usage

From source file:nc.noumea.mairie.appock.viewmodel.EditCatalogueViewModel.java

@Override
@Command/*from   w  w w .  j a v a 2 s .c om*/
@NotifyChange("entity")
public void update() {
    List<Catalogue> listeCatalogueWithSameLibelle = catalogueRepository.findAllByLibelle(entity.getLibelle());
    if (!CollectionUtils.isEmpty(listeCatalogueWithSameLibelle)) {
        Catalogue catalogue = listeCatalogueWithSameLibelle.get(0);
        if (!AppockUtil.sameIdAndNotNull(catalogue.getId(), entity.getId())) {
            showErrorPopup("Le libell " + entity.getLibelle() + " est dj utilis");
            return;
        }
    }
    super.update();
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractComponent.java

@Override
public void removeStyleName(String styleName) {
    if (StringUtils.isEmpty(styleName) || CollectionUtils.isEmpty(styles) || !styles.contains(styleName))
        return;/* w  w w  .  j a  v  a 2  s.co  m*/

    List<String> passedStyles = new ArrayList<>();

    StringTokenizer tokenizer = new StringTokenizer(styleName, " ");
    while (tokenizer.hasMoreTokens()) {
        passedStyles.add(tokenizer.nextToken());
    }

    String appliedStyleName = styles.get(styles.size() - 1);
    if (passedStyles.contains(appliedStyleName)) {
        DesktopTheme appTheme = App.getInstance().getTheme();
        if (appTheme != null)
            appTheme.applyStyle(this, null);
    }

    styles.removeAll(passedStyles);
}

From source file:com.romeikat.datamessie.core.statistics.app.shared.LocalStatisticsManager.java

private StatisticsSparseTable getBaseStatistics(final SharedSessionContract ssc,
        final Collection<Long> sourceIds, final LocalDate from, final LocalDate to) {
    final StatisticsSparseTable statistics = new StatisticsSparseTable();

    if (CollectionUtils.isEmpty(sourceIds) || from == null || to == null) {
        return statistics;
    }//from w w  w. j  a v  a  2  s  .  c  om

    final List<LocalDate> publishedDates = DateUtil.getLocalDatesBetween(from, to);
    for (final LocalDate publishedDate : publishedDates) {
        final StatisticsSparseTable statisticsForPublishedDate = statisticsDao.getStatistics(ssc, sourceIds,
                publishedDate);
        statistics.putValues(statisticsForPublishedDate);
    }
    return statistics;
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.WsConfigParserHandler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    super.endElement(uri, localName, qName);

    try {/*from  ww w  .j av  a 2 s .co  m*/
        if (SCENARIO_ELMT.equals(qName)) {
            if (currScenario.isEmpty()) {
                throw new SAXException(StreamsResources.getStringFormatted(
                        StreamsResources.RESOURCE_BUNDLE_NAME, "WsConfigParserHandler.element.must.have.one",
                        SCENARIO_ELMT, STEP_ELMT, getLocationInfo()));
            }

            ((AbstractWsStream) currStream).addScenario(currScenario);
            currScenario = null;
        } else if (STREAM_ELMT.equals(qName)) {
            if (currStream instanceof AbstractWsStream) {
                if (CollectionUtils.isEmpty(((AbstractWsStream) currStream).getScenarios())) {
                    throw new SAXException(
                            StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                                    "WsConfigParserHandler.element.must.have.one", STREAM_ELMT, SCENARIO_ELMT,
                                    getLocationInfo()));
                }
            }
        } else if (STEP_ELMT.equals(qName)) {
            if (StringUtils.isEmpty(currStep.getRequest()) && StringUtils.isEmpty(currStep.getUrlStr())) {
                throw new SAXParseException(
                        StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                                "ConfigParserHandler.must.contain", STEP_ELMT, URL_ATTR, REQ_ELMT),
                        currParseLocation);
            }

            currScenario.addStep(currStep);
            currStep = null;
        } else if (REQ_ELMT.equals(qName)) {
            if (elementData != null) {
                currStep.setRequest(getElementData());
                elementData = null;
            }
        }
    } catch (SAXException exc) {
        throw exc;
    } catch (Exception e) {
        throw new SAXException(e.getLocalizedMessage() + getLocationInfo(), e);
    }
}

From source file:com.epam.catgenome.manager.protein.ProteinSequenceReconstructionManager.java

/**
 * Load nucleotide sequence for reference CDS.
 *
 * @param chromosome  chromosome//from  w  ww  . j a v a 2 s  . c  o  m
 * @param referenceId reference id
 * @param cdsList     list of cds
 * @return list of nucleotide sequences
 * @throws IOException if errors occurred during working with files
 */
@Transactional(propagation = Propagation.REQUIRED)
public List<List<Sequence>> loadNucleotidesForReferenceCds(final Chromosome chromosome, final Long referenceId,
        final List<Gene> cdsList) throws IOException {
    if (CollectionUtils.isEmpty(cdsList)) {
        return Collections.emptyList();
    }
    double time1 = Utils.getSystemTimeMilliseconds();
    boolean isNegative = StrandSerializable.NEGATIVE.equals(cdsList.get(0).getStrand());
    List<List<Sequence>> cdsNucleotides = new ArrayList<>(cdsList.size());

    int startIndex = chromosome.getSize();
    int endIndex = 1;
    for (Gene cds : cdsList) {
        if (cds.getStartIndex() <= startIndex) {
            startIndex = cds.getStartIndex();
        }
        if (cds.getEndIndex() >= endIndex) {
            endIndex = cds.getEndIndex();
        }
    }

    String referenceString = referenceManager.getSequenceString(startIndex, endIndex, referenceId,
            chromosome.getName());

    for (Gene cds : cdsList) {
        String nucleotides = referenceString.substring(cds.getStartIndex() - startIndex,
                cds.getEndIndex() - startIndex + 1);

        if (isNegative) {
            nucleotides = ProteinSequenceUtils.reverseComplement(nucleotides);
        }

        cdsNucleotides
                .add(ProteinSequenceUtils.breakSequenceString(nucleotides, cds.getStartIndex(), isNegative));
    }

    double time2 = Utils.getSystemTimeMilliseconds();
    LOGGER.debug("Loading nucleotides for reference cds {}:{} ms", Thread.currentThread().getName(),
            time2 - time1);
    return cdsNucleotides;
}

From source file:com.haulmont.cuba.web.toolkit.ui.CubaMultiUpload.java

protected void setResultExtensions() {
    if (CollectionUtils.isEmpty(permittedExtensions) && StringUtils.isEmpty(accept)) {
        setFileTypesMask("*.*");
    } else if (CollectionUtils.isEmpty(permittedExtensions)) {
        setFileTypesMask(accept);//from   w  w  w  .ja  va  2 s.com
    } else if (StringUtils.isEmpty(accept)) {
        setFileTypesMask(StringUtils.join(permittedExtensions, ";"));
    } else {
        Set<String> acceptSet = new HashSet<>(Arrays.asList(accept.split("\\s*;\\s*")));
        List<String> fileTypeMask = new ArrayList<>();
        for (String extension : permittedExtensions) {
            if (acceptSet.contains(extension)) {
                fileTypeMask.add(extension);
            }
        }
        setFileTypesMask(StringUtils.join(fileTypeMask, ";"));
    }
}

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  2s.  com*/
 * @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.jkoolcloud.tnt4j.streams.fields.ActivityField.java

/**
 * Gets master locator for this field. If field has grouping locator defined then this locator is returned. If no
 * grouping locator defined, but there is at least one ordinary locator defined, then first ordinary locator is
 * returned.// w  w  w  .j a va 2 s.  c  o m
 *
 * @return field master locator, or {@code null} if none locators defined for this field
 */
public ActivityFieldLocator getMasterLocator() {
    return groupLocator != null ? groupLocator : CollectionUtils.isEmpty(locators) ? null : locators.get(0);
}

From source file:io.cloudslang.lang.cli.SlangCli.java

private String prettyPrintSystemProperties(Set<SystemProperty> systemProperties) {
    StringBuilder stringBuilder = new StringBuilder();
    if (CollectionUtils.isEmpty(systemProperties)) {
        stringBuilder.append("No system properties found.");
    } else {/*from   ww  w  .j ava2  s  .  co  m*/
        stringBuilder.append("Following system properties were loaded:").append(System.lineSeparator());
        for (SystemProperty systemProperty : systemProperties) {
            stringBuilder.append("\t");
            stringBuilder.append(systemProperty.getFullyQualifiedName());
            stringBuilder.append(": ");
            stringBuilder.append(systemProperty.getValue());
            stringBuilder.append(System.lineSeparator());
        }
    }
    return StringUtils.trim(stringBuilder.toString());
}

From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java

private Optional<JsonArray> toJsonObject(final List<Match> matches) {
    if (CollectionUtils.isEmpty(matches)) {
        return Optional.empty();
    }//from   w w w.  j  a  v a2 s . com

    final JsonArray jsonArray = new JsonArray();
    matches.stream().map(match -> new JsonObject().put("value", match.getValue()).put("type", match.getType()))
            .forEach(jsonArray::add);

    return Optional.of(jsonArray);
}