Example usage for org.springframework.util CollectionUtils isEmpty

List of usage examples for org.springframework.util CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Map<?, ?> map) 

Source Link

Document

Return true if the supplied Map is null or empty.

Usage

From source file:com.microsoft.exchange.impl.BaseExchangeCalendarDataDao.java

private List<BaseFolderType> getFoldersByType(String upn, DistinguishedFolderIdNameType parent) {
    List<BaseFolderType> folders = new ArrayList<BaseFolderType>();
    BaseFolderType baseFolderType = getPrimaryFolder(upn, parent);
    if (null != baseFolderType) {
        folders.add(baseFolderType);/*from   w w w .j a  v a 2 s . co  m*/
    }
    List<BaseFolderType> seondaryFolders = getSeondaryFolders(upn, parent);
    if (!CollectionUtils.isEmpty(seondaryFolders)) {
        for (BaseFolderType b : seondaryFolders) {
            if (baseFolderType.getClass().equals(b.getClass())) {
                folders.add(b);
            }
        }
    }
    return folders;
}

From source file:com.azaptree.services.spring.application.config.SpringApplicationServiceConfig.java

@Override
public String toString() {
    final ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
    if (ArrayUtils.isNotEmpty(configurationClasses)) {
        final String[] names = new String[configurationClasses.length];
        for (int i = 0; i < names.length; i++) {
            names[i] = configurationClasses[i].getName();
        }//  w w  w .  j a v  a 2 s  .  c om
        sb.append("configurationClasses", Arrays.toString(names));
    }
    if (ArrayUtils.isNotEmpty(springProfiles)) {
        sb.append("springProfiles", Arrays.toString(springProfiles));
    }

    if (!CollectionUtils.isEmpty(jvmSystemProperties)) {
        final StringWriter sw = new StringWriter(256);
        try {
            jvmSystemProperties.store(sw, "JVM System Propperties");
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
        sb.append("jvmSystemProperties", sw.toString());
    }

    return sb.toString();
}

From source file:com.qpark.eip.core.failure.FailureAssert.java

/**
 * Assert that a Map has entries; that is, it must not be <code>null</code>
 * and must have at least one entry.//w  w  w .j a  v  a  2s . c o  m
 *
 * <pre class="code">
 * Assert.notEmpty(map, &quot;Map must have entries&quot;);
 * </pre>
 *
 * @param map
 *            the map to check
 * @param errorCode
 *            the error code to use if the assertion fails
 * @param data
 *            additional information to the error code.
 * @throws IllegalArgumentException
 *             if the map is <code>null</code> or has no entries
 */
public static void notEmpty(final Map<?, ?> map, final String errorCode, final Object... data) {
    if (CollectionUtils.isEmpty(map)) {
        BaseFailureHandler.throwFailureException(errorCode, data);
    }
}

From source file:org.duracloud.snapshot.service.impl.RestoreManagerImpl.java

@Override
public Restoration getBySnapshotId(String snapshotId) throws RestorationNotFoundException {
    List<Restoration> restorations = this.restoreRepo.findBySnapshotNameOrderByModifiedDesc(snapshotId);
    if (CollectionUtils.isEmpty(restorations)) {
        log.debug("Restoration returned null for snapshot id {}. Throwing exception...", snapshotId);
        throw new RestorationNotFoundException("No restorations associated with snapshot " + snapshotId);
    }//from www .j  a  v  a 2s .c o  m

    return restorations.get(0);
}

From source file:com.hybris.datahub.outbound.adapter.TmallAdapter.java

private Long getLastProcessedId(final Long lastProcessedId, final List<? extends TargetItem> items) {
    return !CollectionUtils.isEmpty(items) ? items.get(items.size() - 1).getId() : lastProcessedId;
}

From source file:com.microsoft.exchange.ExchangeRequestFactory.java

public GetUserAvailabilityRequest constructGetUserAvailabilityRequest(
        Collection<? extends MailboxData> mailboxData, FreeBusyViewOptions freeBusyView,
        SuggestionsViewOptions suggestionsView, TimeZone timeZone) {
    GetUserAvailabilityRequest request = new GetUserAvailabilityRequest();

    if (!CollectionUtils.isEmpty(mailboxData)) {
        ArrayOfMailboxData arrayOfMailboxData = new ArrayOfMailboxData();
        arrayOfMailboxData.getMailboxDatas().addAll(mailboxData);
        request.setMailboxDataArray(arrayOfMailboxData);
    }//from  w ww  .j  a  v a  2 s .c  o m
    if (null != suggestionsView) {
        request.setSuggestionsViewOptions(suggestionsView);
    }

    if (null != freeBusyView) {
        request.setFreeBusyViewOptions(freeBusyView);
    }

    if (null != timeZone) {
        request.setTimeZone(timeZone);
    }

    return request;
}

From source file:com.gst.portfolio.savings.api.SavingsAccountsApiResource.java

private SavingsAccountData populateTemplateAndAssociations(final Long accountId,
        final SavingsAccountData savingsAccount, final boolean staffInSelectedOfficeOnly,
        final String chargeStatus, final UriInfo uriInfo, final Set<String> mandatoryResponseParameters) {

    Collection<SavingsAccountTransactionData> transactions = null;
    Collection<SavingsAccountChargeData> charges = null;

    final Set<String> associationParameters = ApiParameterHelper
            .extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
    if (!associationParameters.isEmpty()) {

        if (associationParameters.contains("all")) {
            associationParameters//from   w  w  w . j av  a2s .co m
                    .addAll(Arrays.asList(SavingsApiConstants.transactions, SavingsApiConstants.charges));
        }

        if (associationParameters.contains(SavingsApiConstants.transactions)) {
            mandatoryResponseParameters.add(SavingsApiConstants.transactions);
            final Collection<SavingsAccountTransactionData> currentTransactions = this.savingsAccountReadPlatformService
                    .retrieveAllTransactions(accountId, DepositAccountType.SAVINGS_DEPOSIT);
            if (!CollectionUtils.isEmpty(currentTransactions)) {
                transactions = currentTransactions;
            }
        }

        if (associationParameters.contains(SavingsApiConstants.charges)) {
            mandatoryResponseParameters.add(SavingsApiConstants.charges);
            final Collection<SavingsAccountChargeData> currentCharges = this.savingsAccountChargeReadPlatformService
                    .retrieveSavingsAccountCharges(accountId, chargeStatus);
            if (!CollectionUtils.isEmpty(currentCharges)) {
                charges = currentCharges;
            }
        }
    }

    SavingsAccountData templateData = null;
    final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper
            .process(uriInfo.getQueryParameters());
    if (settings.isTemplate()) {
        templateData = this.savingsAccountReadPlatformService.retrieveTemplate(savingsAccount.clientId(),
                savingsAccount.groupId(), savingsAccount.productId(), staffInSelectedOfficeOnly);
    }

    return SavingsAccountData.withTemplateOptions(savingsAccount, templateData, transactions, charges);
}

From source file:pe.gob.mef.gescon.service.impl.AsignacionServiceImpl.java

@Override
public List<Consulta> getNotificationsAlertPanelByMtuser(User user) {
    List<Consulta> lista = new ArrayList<Consulta>();
    try {//from   w ww. ja  v a2 s.c  om
        Mtuser mtuser = new Mtuser();
        BeanUtils.copyProperties(mtuser, user);
        AsignacionDao asignacionDao = (AsignacionDao) ServiceFinder.findBean("AsignacionDao");
        List<HashMap> consulta = asignacionDao.getNotificationsAlertPanelByMtuser(mtuser);
        if (!CollectionUtils.isEmpty(consulta)) {
            for (HashMap map : consulta) {
                Consulta c = new Consulta();
                c.setIdconocimiento((BigDecimal) map.get("ID"));
                c.setCodigo((String) map.get("NUMERO"));
                c.setNombre((String) map.get("NOMBRE"));
                c.setSumilla((String) map.get("SUMILLA"));
                c.setFechaPublicacion((Date) map.get("FECHA"));
                c.setIdCategoria((BigDecimal) map.get("IDCATEGORIA"));
                c.setCategoria((String) map.get("CATEGORIA"));
                c.setIdTipoConocimiento((BigDecimal) map.get("IDTIPOCONOCIMIENTO"));
                c.setTipoConocimiento((String) map.get("TIPOCONOCIMIENTO"));
                c.setIdEstado((BigDecimal) map.get("IDESTADO"));
                c.setEstado((String) map.get("ESTADO"));
                c.setSemaforo((BigDecimal) map.get("SEMAFORO"));
                lista.add(c);
            }
        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
    return lista;
}

From source file:org.devgateway.ocds.web.rest.controller.AwardsWonLostController.java

@ApiOperation(value = "Counts the won, lost procurements, flags and amounts. Receives any filters, "
        + "but most important here is the supplierId and bidderId. Requires bid extension. Use bidderId instead "
        + "of supplierId.")
@RequestMapping(value = "/api/procurementsWonLost", method = { RequestMethod.POST,
        RequestMethod.GET }, produces = "application/json")
public List<ProcurementsWonLost> procurementsWonLost(
        @ModelAttribute @Valid final YearFilterPagingRequest filter) {

    Assert.notEmpty(filter.getBidderId(), "bidderId must not be empty!");
    Assert.isTrue(CollectionUtils.isEmpty(filter.getSupplierId()),
            "supplierId is not allowed here! Use bidderId to show results!");

    //supplier is the same thing as bidder for this particular query
    filter.setSupplierId(filter.getBidderId());

    Map<String, CriteriaDefinition> noSupplierCriteria = createDefaultFilterCriteriaMap(filter);
    noSupplierCriteria.remove(MongoConstants.Filters.SUPPLIER_ID);

    Aggregation agg1 = newAggregation(/*from w w  w .  ja  v a2s.c o  m*/
            match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)),
            unwind("bids.details"), unwind("bids.details.tenderers"),
            match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)),
            group(BIDS_DETAILS_TENDERERS_ID).count().as("count").sum(BIDS_DETAILS_VALUE_AMOUNT)
                    .as("totalAmount").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"),
            project("count", "totalAmount", "countFlags"));

    List<CountAmountFlags> applied = releaseAgg(agg1, CountAmountFlags.class);

    Aggregation agg2 = newAggregation(
            match(where(AWARDS_STATUS).is(Award.Status.active.toString())
                    .andOperator(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE))),
            unwind("awards"), unwind("awards.suppliers"),
            match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(
                    getYearDefaultFilterCriteria(filter.awardFiltering(), TENDER_PERIOD_START_DATE))),
            group(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID).count().as("count")
                    .sum(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).as("totalAmount")
                    .sum(FLAGS_TOTAL_FLAGGED).as("countFlags"),
            project("count", "totalAmount", "countFlags"));

    List<CountAmountFlags> won = releaseAgg(agg2, CountAmountFlags.class);

    ArrayList<ProcurementsWonLost> ret = new ArrayList<>();

    applied.forEach(a -> {
        ProcurementsWonLost r = new ProcurementsWonLost();
        r.setApplied(a);
        Optional<CountAmountFlags> optWon = won.stream().filter(w -> w.getId().equals(a.getId())).findFirst();
        if (optWon.isPresent()) {
            r.setWon(optWon.get());
            r.setLostAmount(r.getApplied().getTotalAmount().subtract(r.getWon().getTotalAmount()));
            r.setLostCount(r.getApplied().getCount() - r.getWon().getCount());
        } else {
            r.setLostAmount(r.getApplied().getTotalAmount());
            r.setLostCount(r.getLostCount());
        }
        ret.add(r);
    });

    return ret;

}