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:com.haulmont.cuba.gui.data.impl.GroupDelegate.java

public List<Entity> getChildItems(GroupInfo groupId) {
    if (groupItems == null) {
        return Collections.emptyList();
    }//from  w  ww. j a  v a2s.c om

    if (containsGroup(groupId)) {
        List<Entity> entities = new ArrayList<>();

        // if current group contains other groups
        if (hasChildren(groupId)) {
            List<GroupInfo> children = getChildren(groupId);
            for (GroupInfo childGroup : children) {
                entities.addAll(getChildItems(childGroup));
            }
        }

        // if current group contains only items
        List<K> idsList = groupItems.get(groupId);
        if (CollectionUtils.isNotEmpty(idsList)) {
            entities.addAll(idsList.stream().map(id -> datasource.getItem(id)).collect(Collectors.toList()));
        }

        return entities;
    }
    return Collections.emptyList();
}

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

private HashMap<Gene, List<Gene>> makeMrnaToVarCdsMap(Map<Gene, List<Gene>> mrnaToCdsMap, Set<Gene> allCds,
        Map<Gene, List<List<Sequence>>> cdsToNucleotidesMap) {
    HashMap<Gene, List<Gene>> mrnaToVarCdsMap = new HashMap<>();
    List<Gene> cdsListNoDuplicates = removeCdsDuplicates(allCds, cdsToNucleotidesMap);

    for (Map.Entry<Gene, List<Gene>> mrnaCdsEntry : mrnaToCdsMap.entrySet()) {
        List<Gene> variationCdsList = new ArrayList<>();
        for (Gene cds : cdsListNoDuplicates) {
            List<Gene> cdsList = mrnaCdsEntry.getValue();
            List<Gene> collect = cdsList.stream().filter(c -> c.getStartIndex().equals(cds.getStartIndex())
                    && c.getEndIndex().equals(cds.getEndIndex())).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(collect)) {
                variationCdsList.add(cds);
            }//from  w  w w  .j  a v a2  s  .com
        }
        mrnaToVarCdsMap.put(mrnaCdsEntry.getKey(), variationCdsList);
    }

    return mrnaToVarCdsMap;
}

From source file:com.evolveum.midpoint.web.page.admin.reports.dto.AuditEventRecordProvider.java

private boolean valueRefTargetIsNotEmpty(Object valueRefTargetNamesParam) {
    if (valueRefTargetNamesParam instanceof String) {
        return StringUtils.isNotBlank((String) valueRefTargetNamesParam);
    } else if (valueRefTargetNamesParam instanceof Collection) {
        return CollectionUtils.isNotEmpty((Collection) valueRefTargetNamesParam);
    } else {/*from   ww w.j ava  2  s . com*/
        return valueRefTargetNamesParam != null;
    }
}

From source file:com.mirth.connect.client.core.Client.java

/**
 * Allows registration of extension providers after the client is initialized.
 *///from   w  w  w.  j  a va  2s . co  m
public void registerApiProviders(Set<String> packageNames, Set<String> classes) {
    if (CollectionUtils.isNotEmpty(packageNames)) {
        for (String packageName : packageNames) {
            try {
                for (Class<?> clazz : new Reflections(packageName)
                        .getTypesAnnotatedWith(javax.ws.rs.ext.Provider.class)) {
                    client.register(clazz);
                }
                for (Class<?> clazz : new Reflections(packageName).getTypesAnnotatedWith(Path.class)) {
                    client.register(clazz);
                }
            } catch (Throwable t) {
                logger.error("Error registering API provider package: " + packageName);
            }
        }
    }

    if (CollectionUtils.isNotEmpty(classes)) {
        for (String clazz : classes) {
            try {
                client.register(Class.forName(clazz));
            } catch (Throwable t) {
                logger.error("Error registering API provider class: " + clazz);
            }
        }
    }
}

From source file:co.rsk.net.discovery.PeerExplorer.java

private void removeConnections(List<PeerDiscoveryRequest> expiredRequests) {
    if (CollectionUtils.isNotEmpty(expiredRequests)) {
        for (PeerDiscoveryRequest req : expiredRequests) {
            Node node = req.getRelatedNode();
            if (node != null) {
                this.establishedConnections.remove(new ByteArrayWrapper(node.getId()));
                this.distanceTable.removeNode(node);
            }/*w  w  w . j  av a 2 s . c  o m*/
        }
    }
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

@Transactional(propagation = Propagation.MANDATORY)
public Chromosome loadChromosome(final Long chromosomeId) {
    final List<Chromosome> list = getNamedParameterJdbcTemplate().query(loadChromosomeByIdQuery,
            new MapSqlParameterSource(GenomeParameters.CHROMOSOME_ID.name(), chromosomeId),
            GenomeParameters.getChromosomeMapper());
    return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
}

From source file:monasca.api.infrastructure.persistence.hibernate.AlarmSqlRepoImpl.java

private String getFindAlarmsSubQuery(final String alarmDefId, final String metricName,
        final Map<String, String> metricDimensions, final AlarmState state,
        final List<AlarmSeverity> severities, final String lifecycleState, final String link,
        final DateTime stateUpdatedStart, final List<String> sortBy, final String offset, final int limit,
        final boolean enforceLimit) {
    final StringBuilder sbWhere = new StringBuilder("(select distinct a.id "
            + "from alarm as a, alarm_definition as ad " + "where ad.id = a.alarm_definition_id "
            + "  and ad.deleted_at is null " + "  and ad.tenant_id = :tenantId ");

    if (alarmDefId != null) {
        sbWhere.append(" and ad.id = :alarmDefId ");
    }// w w w.j  ava2 s  .  c  om

    if (metricName != null) {

        sbWhere.append(" and a.id in (select distinct a.id from alarm as a "
                + "inner join alarm_metric as am on am.alarm_id = a.id "
                + "inner join metric_definition_dimensions as mdd "
                + "  on mdd.id = am.metric_definition_dimensions_id "
                + "inner join (select distinct id from metric_definition "
                + "            where name = :metricName) as md " + "  on md.id = mdd.metric_definition_id ");

        buildJoinClauseFor(metricDimensions, sbWhere);

        sbWhere.append(")");

    } else if (metricDimensions != null) {

        sbWhere.append(" and a.id in (select distinct a.id from alarm as a "
                + "inner join alarm_metric as am on am.alarm_id = a.id "
                + "inner join metric_definition_dimensions as mdd "
                + "  on mdd.id = am.metric_definition_dimensions_id ");

        buildJoinClauseFor(metricDimensions, sbWhere);

        sbWhere.append(")");

    }

    if (state != null) {
        sbWhere.append(" and a.state = :state");
    }

    if (CollectionUtils.isNotEmpty(severities)) {
        if (severities.size() == 1) {
            sbWhere.append(" and ad.severity = :severity");
        } else {
            sbWhere.append(" and (");
            for (int i = 0; i < severities.size(); i++) {
                sbWhere.append("ad.severity = :severity_").append(i);
                if (i < severities.size() - 1) {
                    sbWhere.append(" or ");
                }
            }
            sbWhere.append(")");
        }
    }

    if (lifecycleState != null) {
        sbWhere.append(" and a.lifecycle_state = :lifecycleState");
    }

    if (link != null) {
        sbWhere.append(" and a.link = :link");
    }

    if (stateUpdatedStart != null) {
        sbWhere.append(" and a.state_updated_at >= :stateUpdatedStart");
    }

    if (enforceLimit && limit > 0) {
        sbWhere.append(" limit :limit");
    }
    if (offset != null) {
        sbWhere.append(" offset ");
        sbWhere.append(offset);
        sbWhere.append(' ');
    }

    sbWhere.append(")");

    return sbWhere.toString();
}

From source file:io.spotnext.maven.mojo.TransformTypesMojo.java

private List<ClassFileTransformer> getClassFileTransformers(final ClassLoader cl)
        throws MojoExecutionException {
    try {/* w w w.  ja v a 2s  .co m*/
        final List<URL> classPathUrls = getClasspath();

        if (CollectionUtils.isNotEmpty(classFileTransformers)) {
            final List<ClassFileTransformer> list = new ArrayList<>(classFileTransformers.size());

            for (final String classFileTransformer : classFileTransformers) {
                final Class<?> clazz = cl.loadClass(classFileTransformer);
                final ClassFileTransformer transformer = (ClassFileTransformer) clazz.newInstance();

                if (transformer instanceof AbstractBaseClassTransformer) {
                    final AbstractBaseClassTransformer baseClassTransformer = ((AbstractBaseClassTransformer) transformer);

                    baseClassTransformer.addClassPaths(project.getBuild().getOutputDirectory());
                    baseClassTransformer.addClassPaths(
                            classPathUrls.stream().map(u -> u.getFile()).collect(Collectors.toList()));
                }

                list.add(transformer);
            }

            return list;
        } else {
            getLog().warn("No class file transformers configured!");
            return Collections.emptyList();
        }
    } catch (final Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.epam.catgenome.manager.reference.ReferenceGenomeManager.java

/**
 * Returns {@code List} of chromosomes associated with the given reference ID and ordered by in the
 * alphabetical order./*  w w w.  j  a  v  a  2 s .com*/
 *
 * @param referenceId {@code Long} specifies ID of a reference genome which chromosomes should be loaded
 * @return {@code List}
 * @throws IllegalArgumentException will be thrown in a case, if no chromosome associated with the given
 *                                  reference ID can be found in the system
 */
@Transactional(propagation = Propagation.REQUIRED)
public List<Chromosome> loadChromosomes(final Long referenceId) {
    final List<Chromosome> chromosomes = referenceGenomeDao.loadAllChromosomesByReferenceId(referenceId);
    Assert.isTrue(CollectionUtils.isNotEmpty(chromosomes), getMessage(MessageCode.NO_SUCH_REFERENCE));
    return chromosomes;
}

From source file:io.github.swagger2markup.internal.component.PathOperationComponent.java

/**
 * Builds inline schema definitions/*from  w w  w .j a v a 2  s  . c  om*/
 *
 * @param markupDocBuilder the docbuilder do use for output
 * @param definitions      all inline definitions to display
 * @param uniquePrefix     unique prefix to prepend to inline object names to enforce unicity
 */
private void inlineDefinitions(MarkupDocBuilder markupDocBuilder, List<ObjectType> definitions,
        String uniquePrefix) {
    if (CollectionUtils.isNotEmpty(definitions)) {
        for (ObjectType definition : definitions) {
            addInlineDefinitionTitle(markupDocBuilder, definition.getName(), definition.getUniqueName());

            List<ObjectType> localDefinitions = new ArrayList<>();
            propertiesTableComponent.apply(markupDocBuilder, PropertiesTableComponent
                    .parameters(definition.getProperties(), uniquePrefix, localDefinitions));
            for (ObjectType localDefinition : localDefinitions)
                inlineDefinitions(markupDocBuilder, Collections.singletonList(localDefinition),
                        localDefinition.getUniqueName());
        }
    }

}