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.adguard.commons.web.UrlUtils.java

/**
 * Checks if specified domain name is in the list of the domainNames
 * or if it is sub-domain of any domain in the list.
 *
 * @param domainName  Domain name to check
 * @param domainNames List of domain names
 * @return true if domain (or it's top-level domain) is in the list
 *//*from  w w w  .j a v a2  s .  c o m*/
public static boolean isDomainOrSubDomain(String domainName, List<String> domainNames) {
    if (CollectionUtils.isEmpty(domainNames)) {
        return false;
    }

    for (String domainToCheck : domainNames) {
        if (domainName.equals(domainToCheck) ||
        // Optimizing end checking: http://jira.performix.ru/browse/AG-6587?focusedCommentId=23526&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-23526
                (domainName.endsWith(domainToCheck) && domainName.endsWith("." + domainToCheck))) {
            return true;
        }
    }

    return false;
}

From source file:com.epam.catgenome.manager.gene.GffManager.java

private List<GeneLowLevel> recursiveConvert(final Gene gene,
        final Map<Gene, List<ProteinSequenceEntry>> aminoAcids) {
    if (gene == null || CollectionUtils.isEmpty(gene.getItems())) {
        return Collections.emptyList();
    }/*from  www  . j  a  v  a2  s. com*/

    final List<GeneLowLevel> items = new ArrayList<>();
    for (Gene item : gene.getItems()) {
        final GeneLowLevel geneLowLevel = new GeneLowLevel(item);
        items.add(geneLowLevel);

        setProteinSequences(aminoAcids, item, geneLowLevel);

        final List<GeneLowLevel> lows = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(item.getItems())) {
            for (Gene lowItem : item.getItems()) {
                final GeneLowLevel itemLowLevel = new GeneLowLevel(lowItem);
                itemLowLevel.setItems(recursiveConvert(lowItem, aminoAcids));
                lows.add(itemLowLevel);
            }
        }

        geneLowLevel.setItems(lows);
    }

    return items;
}

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

/**
 * Groups variations from specified {@link List} of {@link VcfFile}s by specified field
 * @param files a {@link List} of {@link FeatureFile}, which indexes to search
 * @param query a query to search in index
 * @param groupBy a field to perform grouping
 * @return a {@link List} of {@link Group}s, mapping field value to number of variations, having this value
 * @throws IOException if something goes wrong with the file system
 */// ww  w  .  j a v a  2s. co m
public List<Group> groupVariations(List<VcfFile> files, Query query, String groupBy) throws IOException {
    List<Group> res = new ArrayList<>();

    if (CollectionUtils.isEmpty(files)) {
        return Collections.emptyList();
    }

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

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

        IndexSearcher searcher = new IndexSearcher(reader);
        AbstractGroupFacetCollector groupedFacetCollector = TermGroupFacetCollector
                .createTermGroupFacetCollector(FeatureIndexFields.UID.fieldName,
                        getGroupByField(files, groupBy), false, null, GROUP_INITIAL_SIZE);
        searcher.search(query, groupedFacetCollector); // Computing the grouped facet counts
        TermGroupFacetCollector.GroupedFacetResult groupedResult = groupedFacetCollector
                .mergeSegmentResults(reader.numDocs(), 1, false);
        List<AbstractGroupFacetCollector.FacetEntry> facetEntries = groupedResult.getFacetEntries(0,
                reader.numDocs());
        for (AbstractGroupFacetCollector.FacetEntry facetEntry : facetEntries) {
            res.add(new Group(facetEntry.getValue().utf8ToString(), facetEntry.getCount()));
        }
    } finally {
        for (SimpleFSDirectory index : indexes) {
            IOUtils.closeQuietly(index);
        }
    }

    return res;
}

From source file:io.cloudslang.lang.compiler.modeller.ExecutableBuilder.java

private List<Map<String, String>> getNavigationStrings(Map<String, Serializable> postStepData,
        String defaultSuccess, String defaultFailure, List<RuntimeException> errors) {
    @SuppressWarnings("unchecked")
    List<Map<String, String>> navigationStrings = (List<Map<String, String>>) postStepData.get(NAVIGATION_KEY);

    //default navigation
    if (CollectionUtils.isEmpty(navigationStrings)) {
        navigationStrings = new ArrayList<>();
        Map<String, String> successMap = new HashMap<>();
        successMap.put(SUCCESS_RESULT, defaultSuccess);
        Map<String, String> failureMap = new HashMap<>();
        failureMap.put(ScoreLangConstants.FAILURE_RESULT, defaultFailure);
        navigationStrings.add(successMap);
        navigationStrings.add(failureMap);
        return navigationStrings;
    } else {//from  w w  w  .java  2  s .  c  o m
        return navigationStrings;
    }
}

From source file:com.evolveum.midpoint.schema.GetOperationOptions.java

public static Collection<SelectorOptions<GetOperationOptions>> fromRestOptions(List<String> options,
        List<String> include, List<String> exclude, DefinitionProcessingOption definitionProcessing) {
    if (CollectionUtils.isEmpty(options) && CollectionUtils.isEmpty(include)
            && CollectionUtils.isEmpty(exclude)) {
        if (definitionProcessing != null) {
            return SelectorOptions
                    .createCollection(GetOperationOptions.createDefinitionProcessing(definitionProcessing));
        }// w w  w. j  a  v a  2s . c om
        return null;
    }
    Collection<SelectorOptions<GetOperationOptions>> rv = new ArrayList<>();
    GetOperationOptions rootOptions = fromRestOptions(options, definitionProcessing);
    if (rootOptions != null) {
        rv.add(SelectorOptions.create(rootOptions));
    }
    for (ItemPath includePath : ItemPath.fromStringList(include)) {
        rv.add(SelectorOptions.create(includePath, GetOperationOptions.createRetrieve()));
    }
    for (ItemPath excludePath : ItemPath.fromStringList(exclude)) {
        rv.add(SelectorOptions.create(excludePath, GetOperationOptions.createDontRetrieve()));
    }
    // Do NOT set executionPhase here!
    return rv;
}

From source file:cgeo.geocaching.connector.gc.GCParser.java

public static SearchResult searchByNextPage(final SearchResult search, boolean showCaptcha,
        RecaptchaReceiver recaptchaReceiver) {
    if (search == null) {
        return null;
    }//ww w.j  a  v a  2s  . c  o  m
    final String[] viewstates = search.getViewstates();

    final String url = search.getUrl();

    if (StringUtils.isBlank(url)) {
        Log.e("GCParser.searchByNextPage: No url found");
        return search;
    }

    if (GCLogin.isEmpty(viewstates)) {
        Log.e("GCParser.searchByNextPage: No viewstate given");
        return search;
    }

    // As in the original code, remove the query string
    final String uri = Uri.parse(url).buildUpon().query(null).build().toString();

    final Parameters params = new Parameters("__EVENTTARGET", "ctl00$ContentBody$pgrBottom$ctl08",
            "__EVENTARGUMENT", "");
    GCLogin.putViewstates(params, viewstates);

    final String page = GCLogin.getInstance().postRequestLogged(uri, params);
    if (!GCLogin.getInstance().getLoginStatus(page)) {
        Log.e("GCParser.postLogTrackable: Can not log in geocaching");
        return search;
    }

    if (StringUtils.isBlank(page)) {
        Log.e("GCParser.searchByNextPage: No data from server");
        return search;
    }

    final SearchResult searchResult = parseSearch(url, page, showCaptcha, recaptchaReceiver);
    if (searchResult == null || CollectionUtils.isEmpty(searchResult.getGeocodes())) {
        Log.w("GCParser.searchByNextPage: No cache parsed");
        return search;
    }

    // search results don't need to be filtered so load GCVote ratings here
    GCVote.loadRatings(
            new ArrayList<Geocache>(searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB)));

    // save to application
    search.setError(searchResult.getError());
    search.setViewstates(searchResult.viewstates);
    for (final String geocode : searchResult.getGeocodes()) {
        search.addGeocode(geocode);
    }
    return search;
}

From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java

private static Object simplifyValue(Collection<?> valuesList) {
    if (CollectionUtils.isEmpty(valuesList)) {
        return null;
    }//from ww w.java2 s .  c o m

    return valuesList.size() == 1 ? valuesList.iterator().next() : valuesList.toArray();
}

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

/**
 * Returns a {@code List} of chromosome IDs from specified files, where variations exist and satisfy a
 * specified query// w  w w .j  a  v a2 s . c o m
 *
 * @param files a list of {@link FeatureFile}s to search chromosomes
 * @param query     a query to filter variations
 * @return a {@code List} of chromosome IDs
 * @throws IOException
 */
public List<Long> getChromosomeIdsWhereVariationsPresentFacet(List<? extends FeatureFile> files, Query query)
        throws IOException {
    if (CollectionUtils.isEmpty(files)) {
        return Collections.emptyList();
    }

    List<Long> chromosomeIds = new ArrayList<>();

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

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

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

        Facets facets = new SortedSetDocValuesFacetCounts(new DefaultSortedSetDocValuesReaderState(reader,
                FeatureIndexFields.FACET_CHR_ID.getFieldName()), facetsCollector);
        FacetResult res = facets.getTopChildren(FACET_LIMIT, FeatureIndexFields.CHR_ID.getFieldName());
        if (res == null) {
            return Collections.emptyList();
        }

        for (LabelAndValue labelAndValue : res.labelValues) {
            chromosomeIds.add(Long.parseLong(labelAndValue.label));
        }
    } finally {
        closeIndexes(indexes);
    }

    return chromosomeIds;
}

From source file:cgeo.geocaching.connector.gc.GCParser.java

/**
 * @param cacheType/*from  w  w  w.j a  v  a  2 s  .  c  om*/
 * @param listId
 * @param showCaptcha
 * @param params
 *            the parameters to add to the request URI
 * @param recaptchaReceiver
 * @return
 */
@Nullable
private static SearchResult searchByAny(final CacheType cacheType, final boolean my, final boolean showCaptcha,
        final Parameters params, RecaptchaReceiver recaptchaReceiver) {
    insertCacheType(params, cacheType);

    final String uri = "http://www.geocaching.com/seek/nearest.aspx";
    final String fullUri = uri + "?" + addFToParams(params, my, true);
    final String page = GCLogin.getInstance().getRequestLogged(uri, addFToParams(params, my, true));

    if (StringUtils.isBlank(page)) {
        Log.e("GCParser.searchByAny: No data from server");
        return null;
    }
    assert page != null;

    final SearchResult searchResult = parseSearch(fullUri, page, showCaptcha, recaptchaReceiver);
    if (searchResult == null || CollectionUtils.isEmpty(searchResult.getGeocodes())) {
        Log.e("GCParser.searchByAny: No cache parsed");
        return searchResult;
    }

    final SearchResult search = searchResult.filterSearchResults(Settings.isExcludeDisabledCaches(), false,
            cacheType);

    GCLogin.getInstance().getLoginStatus(page);

    return search;
}

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

/**
 * Processes a {@code <field-map>} element.
 *
 * @param attrs/*from w  w w  . j av  a  2 s .c  om*/
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processFieldMap(Attributes attrs) throws SAXException {
    if (currField == null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration3", FIELD_MAP_ELMT, FIELD_ELMT, FIELD_LOC_ELMT),
                currParseLocation);
    }
    // if (currFieldHasLocElmt && currLocatorData == null) {
    // throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
    // "ConfigParserHandler.element.has.both2", FIELD_ELMT, FIELD_LOC_ELMT, FIELD_MAP_ELMT,
    // getLocationInfo()));
    // }
    if (CollectionUtils.isEmpty(currField.getLocators()) && currLocatorData == null) {
        throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.element.no.binding", FIELD_MAP_ELMT, FIELD_LOC_ELMT, getLocationInfo()));
    }
    String source = null;
    String target = null;
    String type = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (SOURCE_ATTR.equals(attName)) {
            source = attValue;
        } else if (TARGET_ATTR.equals(attName)) {
            target = attValue;
        } else if (TYPE_ATTR.equals(attName)) {
            type = attValue;
        }
    }
    notNull(source, FIELD_MAP_ELMT, SOURCE_ATTR);
    notNull(target, FIELD_MAP_ELMT, TARGET_ATTR);

    if (currLocatorData != null) {
        currLocatorData.valueMapItems.add(new FieldLocatorData.ValueMapData(source, target,
                StringUtils.isEmpty(type) ? null : ActivityFieldMappingType.valueOf(type)));
    } else {
        // currFieldHasMapElmt = true;
        List<ActivityFieldLocator> locators = currField.getLocators();
        if (locators != null) {
            for (ActivityFieldLocator loc : locators) {
                loc.addValueMap(source, target,
                        StringUtils.isEmpty(type) ? null : ActivityFieldMappingType.valueOf(type));
            }
        }
    }
}