List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty
public static boolean isNotEmpty(final Collection<?> coll)
From source file:org.codice.ddf.opensearch.source.OpenSearchSource.java
/** * Method to combine spatial searches into either geometry collection or a bounding box. * OpenSearch endpoints and the query framework allow for multiple spatial query parameters. This * method has been refactored out and is protected so that downstream projects may try to * implement another algorithm (e.g. best-effort) to combine searches. * * @return null if there is no search specified, or a {@linkSpatialSearch} with one search that is * the combination of all of the spatial criteria */// ww w .j a v a2 s . com @Nullable protected SpatialSearch createCombinedSpatialSearch(final Queue<PointRadius> pointRadiusSearches, final Queue<Geometry> geometrySearches, final int numMultiPointRadiusVertices, final int distanceTolerance) { Geometry geometrySearch = null; BoundingBox boundingBox = null; PointRadius pointRadius = null; SpatialSearch spatialSearch = null; Set<Geometry> combinedGeometrySearches = new HashSet<>(geometrySearches); if (CollectionUtils.isNotEmpty(pointRadiusSearches)) { if (shouldConvertToBBox) { for (PointRadius search : pointRadiusSearches) { BoundingBox bbox = BoundingBoxUtils.createBoundingBox(search); List bboxCoordinate = BoundingBoxUtils.getBoundingBoxCoordinatesList(bbox); List<List> coordinates = new ArrayList<>(); coordinates.add(bboxCoordinate); combinedGeometrySearches.add(ddf.geo.formatter.Polygon.buildPolygon(coordinates)); LOGGER.trace( "Point radius searches are converted to a (rough approximation) square using Vincenty's formula (direct)"); } } else { if (pointRadiusSearches.size() == 1) { pointRadius = pointRadiusSearches.remove(); } else { for (PointRadius search : pointRadiusSearches) { Geometry circle = GeospatialUtil.createCirclePolygon(search.getLat(), search.getLon(), search.getRadius(), numMultiPointRadiusVertices, distanceTolerance); combinedGeometrySearches.add(circle); LOGGER.trace("Point radius searches are converted to a polygon with a max of {} vertices.", numMultiPointRadiusVertices); } } } } if (CollectionUtils.isNotEmpty(combinedGeometrySearches)) { // if there is more than one geometry, create a geometry collection if (combinedGeometrySearches.size() > 1) { geometrySearch = GEOMETRY_FACTORY .createGeometryCollection(combinedGeometrySearches.toArray(new Geometry[0])); } else { geometrySearch = combinedGeometrySearches.iterator().next(); } /** * If convert to bounding box is enabled, extracts the approximate envelope. In the case of * multiple geometry, a large approximate envelope encompassing all of the geometry is * returned. Area between the geometries are also included in this spatial search. Hence widen * the search area. */ if (shouldConvertToBBox) { if (combinedGeometrySearches.size() > 1) { LOGGER.trace( "An approximate envelope encompassing all the geometry is returned. Area between the geometries are also included in this spatial search. Hence widen the search area."); } boundingBox = BoundingBoxUtils.createBoundingBox((Polygon) geometrySearch.getEnvelope()); geometrySearch = null; } } if (geometrySearch != null || boundingBox != null || pointRadius != null) { // Geo Draft 2 default always geometry instead of polygon spatialSearch = new SpatialSearch(geometrySearch, boundingBox, null, pointRadius); } return spatialSearch; }
From source file:org.craftercms.commons.crypto.impl.EncryptionTool.java
private static TextEncryptor createEncryptor(CommandLine line) throws MissingOptionException, CryptoException { List<String> missingOptions = new ArrayList<>(); String password = null;/* ww w. ja v a 2s .c o m*/ String salt = null; if (line.hasOption(PASS_OPTION)) { password = line.getOptionValue(PASS_OPTION); } else { missingOptions.add("-" + PASS_OPTION); } if (line.hasOption(SALT_OPTION)) { salt = line.getOptionValue(SALT_OPTION); } else { missingOptions.add("-" + SALT_OPTION); } if (CollectionUtils.isNotEmpty(missingOptions)) { throw new MissingOptionException(missingOptions); } return new PbkAesTextEncryptor(password, salt); }
From source file:org.craftercms.commons.jackson.JacksonUtils.java
/** * Creates a module from a set of serializers and deserializes. * * @param serializers the serializers, can be null or empty * @param deserializers the deserializers, can be null or empty * * @return a non-reusable Jackson module composed of the specified serializers and deserializers *//* w w w. java2s . c om*/ @SuppressWarnings("unchecked") public static final Module createModule(List<JsonSerializer<?>> serializers, Map<Class<?>, JsonDeserializer<?>> deserializers) { SimpleModule module = new SimpleModule(); if (CollectionUtils.isNotEmpty(serializers)) { for (JsonSerializer<?> serializer : serializers) { module.addSerializer(serializer); } } if (MapUtils.isNotEmpty(deserializers)) { for (Map.Entry<Class<?>, JsonDeserializer<?>> entry : deserializers.entrySet()) { Class<Object> type = (Class<Object>) entry.getKey(); JsonDeserializer<Object> des = (JsonDeserializer<Object>) entry.getValue(); module.addDeserializer(type, des); } } return module; }
From source file:org.craftercms.commons.mongo.JongoFactoryBean.java
@Override protected Jongo createInstance() throws Exception { DB db = mongo.getDB(dbName);/* www.j a v a2 s. co m*/ JacksonMapper.Builder builder = new JacksonMapper.Builder(); builder.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); if (CollectionUtils.isNotEmpty(serializers) || MapUtils.isNotEmpty(deserializers)) { builder.registerModule(JacksonUtils.createModule(serializers, deserializers)); } return new Jongo(db, builder.build()); }
From source file:org.craftercms.commons.security.permissions.PermissionBase.java
@Override public boolean isAllowed(String action) { return CollectionUtils.isNotEmpty(allowedActions) && (allowedActions.contains(ANY_ACTION) || allowedActions.contains(action)); }
From source file:org.craftercms.core.cache.impl.CacheImpl.java
/** * Called when a tick occurs. A tick is a logical unit of time. It basically symbolizes the time span between * calls to this method (i.e. 15 mins) by a job scheduler like Quartz. * <p/>// ww w. j a v a 2 s .com * Checks if some of the {@link CacheItem}s in the cache have expired or need to be refreshed. If the item * has expired, it is removed from the cache. If it needs to be refreshed, it is added to a list of items that * need to be refreshed that is later passed to the {@link CacheRefresher}. */ public void tick() { ticks.incrementAndGet(); if (logger.isDebugEnabled()) { logger.debug("Tick!"); } List<CacheItem> itemsToRefresh = new ArrayList<CacheItem>(); try { Collection<String> scopes = cacheStoreAdapter.getScopes(); if (CollectionUtils.isNotEmpty(scopes)) { for (String scope : scopes) { Collection<Object> keys = cacheStoreAdapter.getKeys(scope); if (CollectionUtils.isNotEmpty(keys)) { for (Object key : keys) { CacheItem item = cacheStoreAdapter.get(scope, key); if (item != null) { doChecks(item, itemsToRefresh); } else { if (logger.isDebugEnabled()) { logger.debug(item + " was removed before it could be checked for " + "expiration/refresh"); } } } } } } if (cacheRefresher != null && CollectionUtils.isNotEmpty(itemsToRefresh)) { cacheRefresher.refreshItems(itemsToRefresh, this); } } catch (Exception ex) { logger.warn("Exception while checking items for expiration/refresh", ex); } }
From source file:org.craftercms.core.cache.impl.CacheImpl.java
/** * Checks if some of the dependencies of the given {@link CacheItem} have changed, that means, they're no longer * in the cache, their timestamp is greater than the item's timestamp (which means that they were put in the * cache after the item was put) or their own dependencies have changed (recursive). If the dependencies have * changed, the item needs to be taken out of the cache. * * @return true if some of the dependencies have changed, false if none of them have changed. * @throws Exception//from w ww. jav a 2 s . c om */ protected boolean haveDependenciesChanged(CacheItem item) throws Exception { List<Object> dependencyKeys = item.getDependencyKeys(); if (CollectionUtils.isNotEmpty(dependencyKeys)) { for (Object dependencyKey : dependencyKeys) { CacheItem dependency = cacheStoreAdapter.get(item.getScope(), dependencyKey); if (dependency == null || item.getTimestamp() < dependency.getTimestamp() || haveDependenciesChanged(dependency)) { return true; } } } return false; }
From source file:org.craftercms.core.cache.impl.TopologicalCacheItemSorterImpl.java
/** * The visit(n) function of the sorting algorithm. Adds the items to the sorted list by depth-first. *//*ww w. j av a2s .c o m*/ private void visitItem(CacheItem item, Set<CacheItem> visitedItems, List<CacheItem> sortedItems, Cache cache) { // if n has not been visited yet then if (!visitedItems.contains(item)) { // mark n as visited visitedItems.add(item); // for each node m with an edge from n to m do List<Object> dependencyKeys = item.getDependencyKeys(); if (CollectionUtils.isNotEmpty(dependencyKeys)) { for (Object dependencyKey : dependencyKeys) { CacheItem dependency = getCacheItem(cache, item.getScope(), dependencyKey); if (dependency != null) { visitItem(dependency, visitedItems, sortedItems, cache); } } } // add n to L sortedItems.add(item); } }
From source file:org.craftercms.core.cache.impl.TopologicalCacheItemSorterImpl.java
/** * Returns true if {@code possibleDependency} is a direct or indirect dependency of {@code item}. *//*from ww w. ja va 2s. co m*/ private boolean isDependency(CacheItem item, CacheItem possibleDependency, Cache cache) { List<Object> dependencyKeys = item.getDependencyKeys(); if (CollectionUtils.isNotEmpty(dependencyKeys)) { for (Object dependencyKey : dependencyKeys) { if (dependencyKey.equals(possibleDependency.getKey())) { return true; } else { CacheItem dependency = getCacheItem(cache, item.getScope(), dependencyKey); if (dependency != null && isDependency(dependency, possibleDependency, cache)) { return true; } } } } return false; }
From source file:org.craftercms.core.processors.impl.ItemProcessorPipeline.java
/** * Processes the given {@link Item}, by calling a pipeline of processors. The output of each processor's * {@link ItemProcessor#process(org.craftercms.core.service.Context, org.craftercms.core.service.CachingOptions, * Item)} call is passed as input to the next processor. * * @return the result of the final processor in the pipeline. * @throws ItemProcessingException if one of the processors in the pipeline couldn't process the item *///from w ww .j a v a2s . co m @Override public Item process(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException { if (CollectionUtils.isNotEmpty(processors)) { for (ItemProcessor processor : processors) { item = processor.process(context, cachingOptions, item); } } return item; }