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:org.codice.ddf.catalog.ui.forms.filter.TransformVisitor.java

@Override
public void visitDistanceBufferType(VisitableElement<List<Object>> visitable) {
    traceName(visitable);//from w  ww. ja va 2s  .com
    List<Object> values = visitable.getValue();
    if (CollectionUtils.isEmpty(values)) {
        LOGGER.debug("No values found on distance buffer type");
        return;
    }

    builder.beginBinarySpatialType("DWITHIN");
    visitable.getValue().stream().map(VisitableElement.class::cast).forEachOrdered(v -> v.accept(this));
    builder.endTerminalType();
}

From source file:org.codice.ddf.catalog.ui.query.cql.CqlRequest.java

public QueryRequest createQueryRequest(String localSource, FilterBuilder filterBuilder) {
    List<SortBy> sortBys = sorts.stream()
            .filter(s -> StringUtils.isNotEmpty(s.getAttribute()) && StringUtils.isNotEmpty(s.getDirection()))
            .map(s -> parseSort(s.getAttribute(), s.getDirection())).collect(Collectors.toList());
    if (sortBys.isEmpty()) {
        sortBys.add(new SortByImpl(Result.TEMPORAL, DEFAULT_SORT_ORDER));
    }/*from w  w w.  ja  va2s  .c o m*/
    Query query = new QueryImpl(createFilter(filterBuilder), start, count, sortBys.get(0), true, timeout);

    QueryRequest queryRequest;
    if (!CollectionUtils.isEmpty(srcs)) {
        parseSrcs(localSource);
        queryRequest = new QueryRequestImpl(query, srcs);
        queryRequest.getProperties().put(MODE, UPDATE);
    } else {
        String source = parseSrc(localSource);
        if (CACHE_SOURCE.equals(source)) {
            queryRequest = new QueryRequestImpl(query, true);
            queryRequest.getProperties().put(MODE, CACHE_SOURCE);
        } else {
            queryRequest = new QueryRequestImpl(query, Collections.singleton(source));
            queryRequest.getProperties().put(MODE, UPDATE);
        }
    }

    queryRequest = facetQueryRequest(queryRequest);

    if (excludeUnnecessaryAttributes) {
        queryRequest.getProperties().put("excludeAttributes", Sets.newHashSet(Metacard.METADATA, "lux"));
    }

    if (sortBys.size() > 1) {
        queryRequest.getProperties().put(ADDITIONAL_SORT_BYS,
                sortBys.subList(1, sortBys.size()).toArray(new SortBy[0]));
    }

    queryRequest.getProperties().put("requestId", id);

    if (StringUtils.isNotEmpty(batchId)) {
        queryRequest.getProperties().put("batchId", batchId);
    }

    if (StringUtils.isNotEmpty(queryType)) {
        queryRequest.getProperties().put("queryType", queryType);
    }

    if (spellcheck != null) {
        queryRequest.getProperties().put("spellcheck", spellcheck);
    }

    if (phonetics != null) {
        queryRequest.getProperties().put("phonetics", phonetics);
    }

    return queryRequest;
}

From source file:org.codice.ddf.catalog.ui.query.cql.CqlRequest.java

public String getSourceResponseString() {
    if (!CollectionUtils.isEmpty(srcs)) {
        return String.join(", ", srcs);
    } else {//from   w w  w . j a  va2  s .c  o m
        return src;
    }
}

From source file:org.codice.ddf.catalog.ui.util.EndpointUtil.java

private Filter buildAttributeFilter(String attributeName, Collection<String> attributeValues,
        boolean isExactMatch) {
    if (CollectionUtils.isEmpty(attributeValues)) {
        return null;
    }//w  w w .  ja  va2s  .co m

    List<Filter> filters = new ArrayList<>();
    for (String value : attributeValues) {
        if (isExactMatch) {
            filters.add(filterBuilder.attribute(attributeName).is().equalTo().text(value));
        } else {
            filters.add(filterBuilder.attribute(attributeName).is().like().text(value));
        }
    }

    if (filters.size() == 1) {
        return filters.get(0);
    } else {
        return filterBuilder.anyOf(filters);
    }
}

From source file:org.codice.ddf.opensearch.endpoint.query.OpenSearchQuery.java

private Optional<Filter> getSpatialFilterOption() {
    if (CollectionUtils.isEmpty(spatialFilters)) {
        return Optional.empty();
    } else if (spatialFilters.size() == 1) {
        return Optional.ofNullable(spatialFilters.get(0));
    } else {/*from   w  w w .j  a  v  a  2s .  c om*/
        return Optional.ofNullable(FILTER_FACTORY.or(spatialFilters));
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.impl.CswActionTransformerProviderImpl.java

public void bind(CswActionTransformer cswActionTransformer) {
    if (cswActionTransformer == null) {
        return;/*from w w w . j a va 2s.  c  o  m*/
    }

    Set<String> typeNames = cswActionTransformer.getTypeNames();
    if (CollectionUtils.isEmpty(typeNames)) {
        LOGGER.warn("Unable to bind a CswActionTransformer with no typenames");
        return;
    }

    for (String typeName : typeNames) {
        transformerMap.putIfAbsent(typeName, cswActionTransformer);
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.impl.CswActionTransformerProviderImpl.java

public void unbind(CswActionTransformer cswActionTransformer) {
    if (cswActionTransformer == null) {
        return;/*  ww w  .  jav  a  2 s. c  o  m*/
    }

    Set<String> typeNames = cswActionTransformer.getTypeNames();
    if (CollectionUtils.isEmpty(typeNames)) {
        return;
    }

    for (String typeName : typeNames) {
        transformerMap.remove(typeName);
    }
}

From source file:org.craftercms.core.cache.impl.CacheImpl.java

/**
 * {@inheritDoc}//from  www  .java2s . c  om
 */
@Override
public void put(String scope, Object key, Object value, List<Object> dependencyKeys, long expireAfter,
        long refreshFrequency, CacheLoader loader, Object... loaderParams)
        throws InvalidScopeException, InternalCacheEngineException {
    if (expireAfter < 0) {
        throw new IllegalArgumentException("The expireAfter argument should be 0 or positive");
    }

    if (refreshFrequency < 0) {
        throw new IllegalArgumentException("The refreshFrequency argument should be 0 or positive");
    }

    if (value instanceof CachingAwareObject) {
        CachingAwareObject cachingAwareObj = (CachingAwareObject) value;

        if (CollectionUtils.isEmpty(dependencyKeys)) {
            dependencyKeys = cachingAwareObj.getDependencyKeys();
        }

        cachingAwareObj.setCachingTime(System.currentTimeMillis());
        cachingAwareObj.setScope(scope);
        cachingAwareObj.setKey(key);
    }

    try {
        CacheItem item = new CacheItemImpl(scope, ticks.get(), key, value, expireAfter, refreshFrequency,
                timestampGenerator.generate(), dependencyKeys, loader, loaderParams);

        cacheStoreAdapter.put(item);

        if (logger.isDebugEnabled()) {
            logger.debug("Put into cache: " + item);
        }
    } catch (InvalidScopeException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new InternalCacheEngineException(
                "Exception while putting item with key " + key + " into scope " + scope, ex);
    }
}

From source file:org.craftercms.core.processors.impl.IncludeDescriptorsProcessor.java

@SuppressWarnings("unchecked")
protected void includeDescriptors(Context context, CachingOptions cachingOptions, Item item)
        throws ItemProcessingException {
    String descriptorUrl = item.getDescriptorUrl();

    includedItemsStack.get().push(descriptorUrl);
    try {/*w ww.  ja  va2s.  co  m*/
        Document descriptorDom = item.getDescriptorDom();
        List<Element> includeElements = descriptorDom.selectNodes(includeElementXPathQuery);

        if (CollectionUtils.isEmpty(includeElements)) {
            return;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Processing includes of item @ " + descriptorUrl);
        }

        for (Element includeElement : includeElements) {
            String itemToIncludePath = includeElement.getTextTrim();

            if (StringUtils.isEmpty(itemToIncludePath)) {
                continue;
            }

            if (!isIncludeDisabled(includeElement)) {
                if (!includedItemsStack.get().contains(itemToIncludePath)) {
                    Item itemToInclude = getItemToInclude(context, cachingOptions, itemToIncludePath);
                    if (itemToInclude != null && itemToInclude.getDescriptorDom() != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Include found in " + descriptorUrl + ": " + itemToIncludePath);
                        }

                        doInclude(item, includeElement, itemToInclude);
                    } else {
                        logger.debug("No descriptor item found @ " + itemToIncludePath);
                    }
                } else {
                    logger.debug(
                            "Circular inclusion detected. Item " + itemToIncludePath + " already included");
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Ignoring include " + itemToIncludePath + ". It's currently disabled");
                }
            }
        }
    } finally {
        includedItemsStack.get().pop();
    }
}

From source file:org.craftercms.core.service.impl.ContentStoreServiceImplTest.java

private void assertRootFolderTree(Tree tree, int depth, boolean filterSpecified, boolean processorSpecified) {
    assertNotNull(tree);//from   www  . j  a  v a2  s. c o  m
    assertRootFolderItem(tree);

    if (depth == UNLIMITED_TREE_DEPTH || depth >= 1) {
        List<Item> rootFolderChildren = tree.getChildren();
        assertRootFolderChildren(rootFolderChildren, filterSpecified, processorSpecified);

        if (depth == UNLIMITED_TREE_DEPTH || depth >= 2) {
            List<Item> bundleFolderChildren = ((Tree) rootFolderChildren.get(0)).getChildren();
            assertBundleFolderChildren(bundleFolderChildren);

            if (depth == UNLIMITED_TREE_DEPTH || depth >= 3) {
                List<Item> contentFolderChildren = ((Tree) bundleFolderChildren.get(0)).getChildren();
                assertContentFolderChildren(contentFolderChildren, filterSpecified, processorSpecified);

                List<Item> contentFrFolderChildren = ((Tree) bundleFolderChildren.get(1)).getChildren();
                assertContentFrFolderChildren(contentFrFolderChildren, filterSpecified, processorSpecified);

                List<Item> contentFrEsFolderChildren = ((Tree) bundleFolderChildren.get(2)).getChildren();
                assertContentFrEsFolderChildren(contentFrEsFolderChildren, filterSpecified, processorSpecified);
            } else {
                assertTrue(CollectionUtils.isEmpty(((Tree) bundleFolderChildren.get(0)).getChildren()));
                assertTrue(CollectionUtils.isEmpty(((Tree) bundleFolderChildren.get(1)).getChildren()));
                assertTrue(CollectionUtils.isEmpty(((Tree) bundleFolderChildren.get(2)).getChildren()));
            }
        } else {
            assertTrue(CollectionUtils.isEmpty(((Tree) rootFolderChildren.get(0)).getChildren()));
        }
    } else {
        assertTrue(CollectionUtils.isEmpty(tree.getChildren()));
    }
}