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

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

Introduction

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

Prototype

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

Source Link

Document

Null-safe check if the specified collection is not empty.

Usage

From source file:nc.noumea.mairie.appock.entity.AdresseTest.java

@Test
public void construitListeMessageErreur() {
    Adresse adresse = new Adresse();
    adresse.setVille(null);/* ww w  .  j av  a2  s  .  c o m*/

    Assert.assertTrue(CollectionUtils.isNotEmpty(adresse.construitListeMessageErreur()));
}

From source file:co.rsk.remasc.Remasc.java

/**
 * Implements the actual Remasc distribution logic
 *//*from  ww  w .  j av  a  2s . c  o  m*/
void processMinersFees() {
    if (!(executionTx instanceof RemascTransaction)) {
        //Detect
        // 1) tx to remasc that is not the latest tx in a block
        // 2) invocation to remasc from another contract (ie call opcode)
        throw new RemascInvalidInvocationException("Invoked Remasc outside last tx of the block");
    }
    this.addNewSiblings();

    long blockNbr = executionBlock.getNumber();

    long processingBlockNumber = blockNbr - remascConstants.getMaturity();
    if (processingBlockNumber < 1) {
        logger.debug("First block has not reached maturity yet, current block is {}", blockNbr);
        return;
    }
    BlockHeader processingBlockHeader = blockStore
            .getBlockByHashAndDepth(executionBlock.getParentHash(), remascConstants.getMaturity() - 1)
            .getHeader();
    // Adds current block fees to accumulated rewardBalance
    BigInteger processingBlockReward = BigInteger.valueOf(processingBlockHeader.getPaidFees());
    BigInteger rewardBalance = provider.getRewardBalance();
    rewardBalance = rewardBalance.add(processingBlockReward);
    provider.setRewardBalance(rewardBalance);

    if (processingBlockNumber - remascConstants.getSyntheticSpan() < 0) {
        logger.debug("First block has not reached maturity+syntheticSpan yet, current block is {}",
                executionBlock.getNumber());
        return;
    }

    // Takes from rewardBalance this block's height reward.
    BigInteger fullBlockReward = rewardBalance.divide(BigInteger.valueOf(remascConstants.getSyntheticSpan()));
    rewardBalance = rewardBalance.subtract(fullBlockReward);
    provider.setRewardBalance(rewardBalance);

    // Pay RSK labs cut
    BigInteger payToRskLabs = fullBlockReward.divide(BigInteger.valueOf(remascConstants.getRskLabsDivisor()));
    transfer(remascConstants.getRskLabsAddress(), payToRskLabs);
    fullBlockReward = fullBlockReward.subtract(payToRskLabs);

    List<Sibling> siblings = provider.getSiblings().get(processingBlockNumber);

    if (CollectionUtils.isNotEmpty(siblings)) {
        // Block has siblings, reward distribution is more complex
        boolean previousBrokenSelectionRule = provider.getBrokenSelectionRule();
        this.payWithSiblings(processingBlockHeader, fullBlockReward, siblings, previousBrokenSelectionRule);
        boolean brokenSelectionRule = this.isBrokenSelectionRule(processingBlockHeader, siblings);
        provider.setBrokenSelectionRule(brokenSelectionRule);
    } else {
        if (provider.getBrokenSelectionRule()) {
            // broken selection rule, apply punishment, ie burn part of the reward.
            BigInteger punishment = fullBlockReward
                    .divide(BigInteger.valueOf(remascConstants.getPunishmentDivisor()));
            fullBlockReward = fullBlockReward.subtract(punishment);
            provider.setBurnedBalance(provider.getBurnedBalance().add(punishment));
        }
        transfer(processingBlockHeader.getCoinbase(), fullBlockReward);
        provider.setBrokenSelectionRule(Boolean.FALSE);
    }

    this.removeUsedSiblings(processingBlockHeader);
}

From source file:com.movies.entities.Movie.java

public List<Actor> getActorsList() {
    if (CollectionUtils.isEmpty(actorsList) && CollectionUtils.isNotEmpty(actors)) {
        actorsList = new ArrayList<>(actors);
    }/*from  w  ww  .j av a2 s . c  o m*/
    return actorsList;
}

From source file:com.oncore.calorders.rest.service.extension.PartyFacadeRESTExtension.java

/**
 * Finds an employee by user id and password
 *
 * @param userId a valid userid//from  w w  w  .  j a  v a2s.co  m
 * @param password a valid password
 * @return an Employee record if found
 * @throws com.oncore.calorders.core.exceptions.DataAccessException
 */
@GET
@Path("findPartyByUserIdAndPassword/{userId}/{password}")
@Produces({ MediaType.APPLICATION_JSON })
public PartyData findPartyByUserIdAndPassword(@PathParam("userId") String userId,
        @PathParam("password") String password) throws DataAccessException {

    Party party = null;
    PartyData partyData = null;
    GroupData groupData = null;
    PrivilegeData privilegeData = null;

    try {

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

        party = getEntityManager()
                .createQuery("SELECT p FROM Party p WHERE p.ptyUserId = :userId and p.ptyPassword = :password",
                        Party.class)
                .setParameter("userId", userId).setParameter("password", DEFAULT_PASSWORD).getSingleResult();

        if (party != null) {
            partyData = new PartyData();

            partyData.setPtyFirstNm(party.getPtyFirstNm());
            partyData.setPtyHireDt(party.getPtyHireDt());
            partyData.setPtyId(party.getPtyId());
            partyData.setPtyLastNm(party.getPtyLastNm());
            partyData.setPtyMidNm(party.getPtyMidNm());
            partyData.setPtyTitle(party.getPtyTitle());
            partyData.setPtyUid(party.getPtyUid());
            partyData.setPtyUserId(party.getPtyUserId());

            for (GroupPartyAssoc assoc : party.getGroupPartyAssocCollection()) {
                partyData.setDepName(assoc.getGrpUidFk().getDepUidFk().getDepName());
                partyData.setDepUid(assoc.getGrpUidFk().getDepUidFk().getDepUid());

                if (CollectionUtils.isNotEmpty(assoc.getGrpUidFk().getDepUidFk().getAddressCollection())) {
                    Address address = assoc.getGrpUidFk().getDepUidFk().getAddressCollection().iterator()
                            .next();

                    partyData.setDepAddressLine1(address.getAdrLine1());
                    partyData.setDepAddressLine2(address.getAdrLine2());
                    partyData.setDepCity(address.getAdrCity());
                    partyData.setDepState(address.getAdrStateCd().getCode());
                    partyData.setDepZip5(address.getAdrZip5());
                    partyData.setDepZip4(address.getAdrZip4());

                }

                groupData = new GroupData();
                groupData.setGrpUid(assoc.getGrpUidFk().getGrpUid());
                groupData.setGrpTypeCd(assoc.getGrpUidFk().getGrpTypeCd().getCode());
                groupData.setGrpTypeCdDescription(assoc.getGrpUidFk().getGrpTypeCd().getShortDesc());

                for (Iterator<GroupPrivilegeAssoc> it = assoc.getGrpUidFk().getGroupPrivilegeAssocCollection()
                        .iterator(); it.hasNext();) {
                    GroupPrivilegeAssoc groupPrivAssoc = it.next();
                    Privilege privs = groupPrivAssoc.getPrvUidFk();
                    privilegeData = new PrivilegeData();
                    if (privs.getPrvReadInd() == 0) {
                        privilegeData.setCanRead(Boolean.FALSE);
                    } else {
                        privilegeData.setCanRead(Boolean.TRUE);
                    }
                    if (privs.getPrvWriteInd() == 0) {
                        privilegeData.setCanWrite(Boolean.FALSE);
                    } else {
                        privilegeData.setCanWrite(Boolean.TRUE);
                    }
                    privilegeData.setComponentIdentifier(privs.getPrvComponentId());
                    privilegeData.setPageIdentifier(privs.getPrvPageId());

                    privilegeData.setPageDescription(privs.getPrvMisc());
                    if (!groupData.getPrivilegesList().contains(privilegeData)) {
                        groupData.getPrivilegesList().add(privilegeData);
                    }
                }

                partyData.getGroupList().add(groupData);
            }
        }
    } catch (Exception ex) {
        partyData = null;

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

    if (partyData == null) {
        throw new RuntimeException("Record not found");
    }

    return partyData;
}

From source file:org.vaadin.spring.samples.mvp.ui.presenter.DSRUpdateHourlyPresenter.java

@SuppressWarnings("unchecked")
@EventBusListenerMethod/*from w w w .j ava  2s. c o  m*/
public void onFetch(Screen screen) {
    if (screen.getViewName().equals(DSRUpdateHourlyView.NAME) && screen.getAction().equals(Action.GET_DATA)) {

        // obtain control values
        Date marketDay = ((Property<Date>) screen.getControl(MarketDayPicker.class)).getValue();
        AssetOwnedDailyId id = ((Property<AssetOwnedDailyId>) screen.getControl(AnyParticipantSelector.class))
                .getValue();

        if (marketDay != null && id != null) {
            try {
                List<DSRUpdateDTO> dsrUpdateHourlies = dsrService
                        .getDSRHourly(SSTimeUtil.dateToDateTime(marketDay), id.getAssetOwner());
                new Table();
                // should only ever have one
                if (CollectionUtils.isNotEmpty(dsrUpdateHourlies)) {
                    getView().populateGrid(dsrUpdateHourlies.get(0).getRecords());
                } else {
                    getView().populateGrid(null);
                }
            } catch (Exception e) {
                String fullTrace = ExceptionUtils.getStackTrace(e);
                String trace = fullTrace;
                if (fullTrace.length() > 1000) {
                    trace = fullTrace.substring(0, 1000) + "...";
                }
                String message = "Problems populating grid";
                Notification.show(message, trace, Type.ERROR_MESSAGE);
                log.error(message, e);
            }

        } else {
            String message = "Please complete selection of market day, participant and/or DSR.";
            Notification.show("Invalid criteria", message, Type.WARNING_MESSAGE);
        }
    }
}

From source file:com.haulmont.cuba.gui.app.core.sendingmessage.browse.SendingMessageBrowser.java

public void download() {
    SendingMessage message = table.getSingleSelected();
    if (message != null) {
        List<SendingAttachment> attachments = getAttachments(message);
        if (CollectionUtils.isNotEmpty(attachments)) {
            if (attachments.size() == 1) {
                exportFile(attachments.get(0));
            } else {
                selectAttachmentDialog(message);
            }//ww  w  . j a v a2 s . c o m
        } else {
            showNotification(messages.getMessage(getClass(), "sendingMessage.noAttachments"),
                    NotificationType.HUMANIZED);
        }
    }
}

From source file:co.runrightfast.vertx.orientdb.impl.embedded.EmbeddedOrientDBService.java

private void registerDatabaseLifeCycleListeners() {
    if (CollectionUtils.isNotEmpty(config.getLifecycleListeners())) {
        config.getLifecycleListeners().forEach(l -> Orient.instance().addDbLifecycleListener(l.get()));
    }/*from   ww  w  .  j a  v  a2  s.  c  o m*/
}

From source file:com.wiiyaya.provider.main.service.impl.RoleServiceImpl.java

@Override
@Transactional(rollbackFor = BusinessException.class)
public void updateRole(RoleDto roleDto) throws BusinessException {
    Role roleDb = roleDao.findOne(roleDto.getId());
    if (roleDb == null) {
        throw new BusinessException(MainConstant.ERROR_ROLE_NOT_FOUND);
    }//from   ww w .j av  a  2s .  c om
    roleDb.setName(roleDto.getName());
    roleDb.setVersion(roleDto.getVersion());

    if (CollectionUtils.isNotEmpty(roleDto.getPrivilegeIds())) {
        for (Iterator<Privilege> itDb = roleDb.getPrivileges().iterator(); itDb.hasNext();) {
            final Privilege privilegeDb = itDb.next();
            boolean existInPage = IterableUtils.matchesAny(roleDto.getPrivilegeIds(), new Predicate<Long>() {
                @Override
                public boolean evaluate(Long object) {
                    return privilegeDb.getId().equals(object);
                }
            });
            if (!existInPage) {
                itDb.remove();
            }
        }
        roleDb.getPrivileges().addAll(privilegeDao.findAll(roleDto.getPrivilegeIds()));
    } else {
        roleDb.getPrivileges().clear();
    }
    roleDao.save(roleDb);
}

From source file:com.movies.entities.Movie.java

public List<Director> getDirectorsList() {
    if (CollectionUtils.isEmpty(directorsList) && CollectionUtils.isNotEmpty(directors)) {
        directorsList = new ArrayList<>(directors);
    }//from  w ww  .  ja va 2s .com
    return directorsList;
}

From source file:com.haulmont.cuba.core.sys.jpql.QueryTreeAnalyzer.java

@Nullable
public PathNode getFirstReturnedPathNode() {
    List<PathNode> pathNodes = getReturnedPathNodes();
    if (CollectionUtils.isNotEmpty(pathNodes)) {
        PathNode pathNode = pathNodes.get(0);
        return pathNode;
    }/*w  ww. j a  va 2 s . co  m*/

    return null;
}