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:com.jkoolcloud.tnt4j.streams.StreamsAgent.java

private static Collection<TNTInputStream<?, ?>> initPiping(StreamsConfigLoader cfg) throws Exception {
    Collection<TNTInputStream<?, ?>> streams = new ArrayList<>(1);

    Map<String, String> props = new HashMap<>(1);
    props.put(StreamProperties.PROP_HALT_ON_PARSER, String.valueOf(haltOnUnparsed));

    PipedStream pipeStream = new PipedStream();
    pipeStream.setName("DefaultSystemPipeStream"); // NON-NLS
    pipeStream.setProperties(props.entrySet());

    Collection<ActivityParser> parsers = cfg.getParsers();
    if (CollectionUtils.isEmpty(parsers)) {
        throw new IllegalStateException(StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME,
                "StreamsAgent.no.piped.activity.parsers"));
    }// w  w w  . j  a  v a2 s.  c  om
    pipeStream.addParsers(parsers);

    streams.add(pipeStream);

    return streams;
}

From source file:com.evolveum.midpoint.prism.marshaller.PrismUnmarshaller.java

private <T> boolean isValueAllowed(T realValue, PrismPropertyDefinition<T> definition) throws SchemaException {
    if (definition == null || CollectionUtils.isEmpty(definition.getAllowedValues())) {
        return true;
    }//from  www. j a  va  2s .  c o  m
    if (realValue == null) {
        return true; // TODO: ok?
    }
    String serializedForm;
    if (realValue instanceof Enum) {
        PrimitiveXNode<String> prim = (PrimitiveXNode<String>) getBeanMarshaller().marshall(realValue);
        serializedForm = prim.getValue();
    } else {
        serializedForm = null;
    }

    return definition.getAllowedValues().stream()
            .anyMatch(displayableValue -> realValue.equals(displayableValue.getValue())
                    || serializedForm != null && serializedForm.equals(displayableValue.getValue()));
}

From source file:cop.raml.processor.RestProcessor.java

private static AnnotationMirror getAnnotationMirror(@NotNull Element element, String className) {
    List<? extends AnnotationMirror> mirrors = element.getAnnotationMirrors();

    if (CollectionUtils.isEmpty(mirrors) || StringUtils.isBlank(className))
        return null;

    for (AnnotationMirror mirror : mirrors)
        if (className.equals(mirror.getAnnotationType().toString()))
            return mirror;

    return null;//from  w w  w . ja va  2 s.c om
}

From source file:com.epam.catgenome.dao.index.FeatureIndexDao.java

/**
 * Queries a feature index of a list of files
 *
 * @param files a {@link List} of {@link FeatureFile}, which indexes to search
 * @param query a query to search in index
 * @param vcfInfoFields list of info fields to retrieve
 * @param maxResultsCount specifies a maximum number of search results to get
 * @param sort specifies sorting/*from  w  w  w . j a va  2 s  . c  o m*/
 * @return a {List} of {@code FeatureIndexEntry} objects that satisfy index query
 * @throws IOException if something is wrong in the filesystem
 */
public <T extends FeatureIndexEntry> IndexSearchResult<T> searchFileIndexes(List<? extends FeatureFile> files,
        Query query, List<String> vcfInfoFields, Integer maxResultsCount, Sort sort) throws IOException {
    if (CollectionUtils.isEmpty(files)) {
        return new IndexSearchResult<>(Collections.emptyList(), false, 0);
    }

    Map<Integer, FeatureIndexEntry> entryMap = new LinkedHashMap<>();

    SimpleFSDirectory[] indexes = fileManager.getIndexesForFiles(files);

    try (MultiReader reader = openMultiReader(indexes)) {
        if (reader.numDocs() == 0) {
            return new IndexSearchResult<>(Collections.emptyList(), false, 0);
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        final TopDocs docs = performSearch(searcher, query, reader, maxResultsCount, sort);

        int totalHits = docs.totalHits;
        final ScoreDoc[] hits = docs.scoreDocs;

        Map<Long, BookmarkIndexEntry> foundBookmarkEntries = new HashMap<>(); // for batch bookmarks loading
        createIndexEntries(hits, entryMap, foundBookmarkEntries, searcher, vcfInfoFields);
        setBookmarks(foundBookmarkEntries);

        return new IndexSearchResult<>(new ArrayList<T>((Collection<? extends T>) entryMap.values()),
                maxResultsCount != null && totalHits > maxResultsCount, totalHits);
    } finally {
        for (SimpleFSDirectory index : indexes) {
            IOUtils.closeQuietly(index);
        }
    }
}

From source file:io.cloudslang.lang.compiler.CompileParallelLoopFlowTest.java

private void verifyBranchPublishValuesIsEmpty(Map<String, ?> actionData) {
    @SuppressWarnings("unchecked")
    List<Output> publishValues = (List<Output>) actionData.get(ScoreLangConstants.STEP_PUBLISH_KEY);
    assertTrue(CollectionUtils.isEmpty(publishValues));
}

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

private void deleteOldSubAlarms(final Collection<String> oldSubAlarmIds, final Session session) {
    if (!CollectionUtils.isEmpty(oldSubAlarmIds)) {
        session.getNamedQuery(SubAlarmDefinitionDb.Queries.DELETE_BY_IDS)
                .setParameterList("ids", oldSubAlarmIds).executeUpdate();
    }/*www  .  j a  va2  s .c  om*/
}

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

private void deleteActions(final Session session, final String id, final AlarmState alarmState,
        final List<String> actions) {
    if (!CollectionUtils.isEmpty(actions))
        session.getNamedQuery(AlarmActionDb.Queries.DELETE_BY_ALARMDEFINITION_ID_AND_ALARMSTATE)
                .setString("id", id).setString("alarmState", alarmState.name()).executeUpdate();
}

From source file:com.epam.catgenome.dao.index.FeatureIndexDao.java

/**
 * Queries a feature index of a list of files, returning specified page of specified size.
 * If no paging parameters are passed, returns all results
 *
 * @param files a {@link List} of {@link FeatureFile}, which indexes to search
 * @param query a query to search in index
 * @param vcfInfoFields list of info fields to retrieve
 * @param page number of a page to display
 * @param pageSize number of entries per page
 * @param orderBy object, that specifies sorting
 * @return a {List} of {@code FeatureIndexEntry} objects that satisfy index query
 * @throws IOException if something is wrong in the filesystem
 *//*from   w w w. j  av a  2 s  .  c o  m*/
public <T extends FeatureIndexEntry> IndexSearchResult<T> searchFileIndexesPaging(
        List<? extends FeatureFile> files, Query query, List<String> vcfInfoFields, Integer page,
        Integer pageSize, List<VcfFilterForm.OrderBy> orderBy) throws IOException {

    if (CollectionUtils.isEmpty(files)) {
        return new IndexSearchResult<>(Collections.emptyList(), false, 0);
    }

    List<FeatureIndexEntry> entries;

    int totalHits = 0;
    SimpleFSDirectory[] indexes = fileManager.getIndexesForFiles(files);

    try (MultiReader reader = openMultiReader(indexes)) {
        if (reader.numDocs() == 0) {
            return new IndexSearchResult<>(Collections.emptyList(), false, 0);
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        GroupingSearch groupingSearch = new GroupingSearch(FeatureIndexFields.UID.fieldName);
        setSorting(orderBy, groupingSearch, files);

        TopGroups<String> topGroups = groupingSearch.search(searcher, query,
                page == null ? 0 : (page - 1) * pageSize, page == null ? reader.numDocs() : pageSize);

        final ScoreDoc[] hits = new ScoreDoc[topGroups.groups.length];
        for (int i = 0; i < topGroups.groups.length; i++) {
            hits[i] = topGroups.groups[i].scoreDocs[0];
        }

        entries = new ArrayList<>(hits.length);
        for (ScoreDoc hit : hits) {
            entries.add(createIndexEntry(hit, new HashMap<>(), searcher, vcfInfoFields));
        }
    } finally {
        for (SimpleFSDirectory index : indexes) {
            IOUtils.closeQuietly(index);
        }
    }

    return new IndexSearchResult<>((List<T>) entries, false, totalHits);
}

From source file:com.epam.catgenome.manager.vcf.reader.VcfFileReader.java

/**
 * Translates HTSJDK's ambiguous INDEL type into our INS, DEL or MIXED variation types
 *
 * @param context     {@code VariantContext}, from which variation type is being achieved.
 * @param sampleIndex {@code Integer} a sample index from VCF file. If is null, will try to guess VariationType by
 *                    first allele.//from ww w .  j a va2 s  .co  m
 * @return correct {@code VariationType}
 */
private static VariationType determineInDel(VariantContext context, Integer sampleIndex) {
    Genotype genotype = sampleIndex != null ? context.getGenotype(sampleIndex) : null;

    if (genotype == null || CollectionUtils.isEmpty(genotype.getAlleles())) {
        // No genotype information, trying to guess by first alt allele
        return context.getAlternateAlleles().get(0).length() > context.getReference().length()
                ? VariationType.INS
                : VariationType.DEL;
    } else {
        return getVariationTypeFromAlleles(context, genotype);
    }
}

From source file:com.epam.catgenome.dao.index.FeatureIndexDao.java

public int getTotalVariationsCountFacet(List<? extends FeatureFile> files, Query query) throws IOException {
    if (CollectionUtils.isEmpty(files)) {
        return 0;
    }//from  w  w  w.j  av a  2  s.co  m

    SimpleFSDirectory[] indexes = fileManager.getIndexesForFiles(files);

    try (MultiReader reader = openMultiReader(indexes)) {
        if (reader.numDocs() == 0) {
            return 0;
        }

        FacetsCollector facetsCollector = new FacetsCollector();
        IndexSearcher searcher = new IndexSearcher(reader);
        searcher.search(query, facetsCollector);

        Facets facets = new SortedSetDocValuesFacetCounts(
                new DefaultSortedSetDocValuesReaderState(reader, FeatureIndexFields.FACET_UID.fieldName),
                facetsCollector);
        FacetResult res = facets.getTopChildren(reader.numDocs(), FeatureIndexFields.F_UID.getFieldName());
        if (res == null) {
            return 0;
        }

        return res.childCount;
    } finally {
        for (SimpleFSDirectory index : indexes) {
            IOUtils.closeQuietly(index);
        }
    }
}