/** * Determines the {@link Collection#size()} of the given {@link Collection}. * * @param collection {@link Collection} to evaluate. * @return the {@link Collection#size()} of the given {@link Collection}. * @see #nullSafeCollection(Collection) * @see java.util.Collection#size() */ public static int nullSafeSize(@Nullable Collection<?> collection) { return nullSafeCollection(collection).size(); }
/** * Determines the {@link Collection#size()} of the given {@link Collection}. * * @param collection {@link Collection} to evaluate. * @return the {@link Collection#size()} of the given {@link Collection}. * @see #nullSafeCollection(Collection) * @see java.util.Collection#size() */ public static int nullSafeSize(@Nullable Collection<?> collection) { return nullSafeCollection(collection).size(); }
/** * Determines whether the given {@link Collection} is {@link Collection#isEmpty() empty}. * * @param collection {@link Collection} to evaluate. * @return a boolean value indicating whether the given {@link Collection} is {@link Collection#isEmpty() empty}. * @see #nullSafeCollection(Collection) * @see java.util.Collection#isEmpty() */ public static boolean nullSafeIsEmpty(@Nullable Collection<?> collection) { return nullSafeCollection(collection).isEmpty(); }
@Override public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) { nullSafeCollection(regionConfigurers) .forEach(regionConfigurer -> regionConfigurer.configure(beanName, bean)); } };
@Override public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) { nullSafeCollection(regionConfigurers) .forEach(regionConfigurer -> regionConfigurer.configure(beanName, bean)); } };
/** * Null-safe method to determines whether the given {@link Collection} contains any elements from the given array. * * @param collection {@link Collection} to evaluate * @param elements array of elements to evaluate. * @return a boolean value indicating whether the collection contains at least 1 element from the given array. * @see java.util.Collection#contains(Object) */ public static boolean containsAny(@Nullable Collection<?> collection, @Nullable Object... elements) { return Arrays.asList(nullSafeArray(elements, Object.class)).stream() .anyMatch(element -> nullSafeCollection(collection).contains(element)); }
@Override public void configure(String beanName, IndexFactoryBean bean) { nullSafeCollection(indexConfigurers).forEach(indexConfigurer -> indexConfigurer.configure(beanName, bean)); } };
@Override public void configure(String beanName, LuceneIndexFactoryBean bean) { nullSafeCollection(indexConfigurers) .forEach(indexConfigurer -> indexConfigurer.configure(beanName, bean)); } };
/** * Null-safe method to determines whether the given {@link Collection} contains any elements from the given array. * * @param collection {@link Collection} to evaluate * @param elements array of elements to evaluate. * @return a boolean value indicating whether the collection contains at least 1 element from the given array. * @see java.util.Collection#contains(Object) */ public static boolean containsAny(@Nullable Collection<?> collection, @Nullable Object... elements) { return Arrays.asList(nullSafeArray(elements, Object.class)).stream() .anyMatch(element -> nullSafeCollection(collection).contains(element)); }
@Override public void configure(String beanName, IndexFactoryBean bean) { nullSafeCollection(indexConfigurers).forEach(indexConfigurer -> indexConfigurer.configure(beanName, bean)); } };
@Override public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) { nullSafeCollection(regionConfigurers) .forEach(regionConfigurer -> regionConfigurer.configure(beanName, bean)); } };
@GemfireFunction(id = LIST_INDEXES_FUNCTION_ID) public Set<String> listIndexes() { return Optional.ofNullable(resolveCache()) .map(cache -> cache.getQueryService()) .map(queryService -> nullSafeCollection(queryService.getIndexes()).stream().map(Index::getName).collect(Collectors.toSet())) .orElseGet(Collections::emptySet); }
Optional<Index> tryToFindExistingIndexByName(QueryService queryService, String indexName) { for (Index index : nullSafeCollection(queryService.getIndexes())) { if (index.getName().equalsIgnoreCase(indexName)) { return Optional.of(index); } } return Optional.empty(); }
@GemfireFunction(id = LIST_INDEXES_FUNCTION_ID) public Set<String> listIndexes() { return Optional.ofNullable(resolveCache()) .map(cache -> cache.getQueryService()) .map(queryService -> nullSafeCollection(queryService.getIndexes()).stream().map(Index::getName).collect(Collectors.toSet())) .orElseGet(Collections::emptySet); }
private GemFireCache registerTransactionListeners(GemFireCache cache) { nullSafeCollection(getTransactionListeners()) .forEach(transactionListener -> cache.getCacheTransactionManager().addListener(transactionListener)); return cache; }
protected boolean isNonExistingIndex(GemFireCache gemfireCache, IndexDefinition indexDefinition) { return !nullSafeCollection(gemfireCache.getQueryService().getIndexes()).stream() .anyMatch(index -> index.getName().equals(indexDefinition.getName())); } }
private GemFireCache registerTransactionListeners(GemFireCache cache) { nullSafeCollection(getTransactionListeners()) .forEach(transactionListener -> cache.getCacheTransactionManager().addListener(transactionListener)); return cache; }
Optional<Index> tryToFindExistingIndexByDefinition(QueryService queryService, String expression, String fromClause, IndexType indexType) { for (Index index : nullSafeCollection(queryService.getIndexes())) { if (index.getIndexedExpression().equalsIgnoreCase(expression) && index.getFromClause().equalsIgnoreCase(fromClause) && indexType.equals(IndexType.valueOf(index.getType()))) { return Optional.of(index); } } return Optional.empty(); }
private GemFireCache registerJndiDataSources(GemFireCache cache) { nullSafeCollection(getJndiDataSources()).forEach(jndiDataSource -> { String type = jndiDataSource.getAttributes().get("type"); JndiDataSourceType jndiDataSourceType = JndiDataSourceType.valueOfIgnoreCase(type); Assert.notNull(jndiDataSourceType, String.format("'jndi-binding' 'type' [%1$s] is invalid; 'type' must be one of %2$s", type, Arrays.toString(JndiDataSourceType.values()))); jndiDataSource.getAttributes().put("type", jndiDataSourceType.getName()); JNDIInvoker.mapDatasource(jndiDataSource.getAttributes(), jndiDataSource.getProps()); }); return cache; }
private GemFireCache registerJndiDataSources(GemFireCache cache) { nullSafeCollection(getJndiDataSources()).forEach(jndiDataSource -> { String type = jndiDataSource.getAttributes().get("type"); JndiDataSourceType jndiDataSourceType = JndiDataSourceType.valueOfIgnoreCase(type); Assert.notNull(jndiDataSourceType, String.format("'jndi-binding' 'type' [%1$s] is invalid; 'type' must be one of %2$s", type, Arrays.toString(JndiDataSourceType.values()))); jndiDataSource.getAttributes().put("type", jndiDataSourceType.getName()); JNDIInvoker.mapDatasource(jndiDataSource.getAttributes(), jndiDataSource.getProps()); }); return cache; }