Class StoreElementFilter
java.lang.Object
de.espirit.firstspirit.access.store.StoreElementFilter
- All Implemented Interfaces:
Filter<StoreElement>
,Filter.TypedFilter<StoreElement>
,Serializable
- Since:
- 4.0.17
- See Also:
- Example:
- Usage example:
import de.espirit.firstspirit.access.store.*; import de.espirit.common.util.Listable; import de.espirit.firstspirit.access.UserService; import de.espirit.firstspirit.access.project.Project; import de.espirit.firstspirit.access.store.Store.Type; import de.espirit.firstspirit.access.store.pagestore.Page; import de.espirit.firstspirit.access.store.pagestore.PageFolder; import de.espirit.firstspirit.access.store.pagestore.PageStoreRoot; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * Example how to use StoreElementFilter. * * @since 4.2.410 */ public class StoreElementFilterExample { /** * Example how to use a StoreElementFilter which filters PageFolders and Pages within the {@link PageStoreRoot PageStore} of the given {@link Project} using an iterator.<br/> * * <b>Important:</b> In case of usage in a Beanshell script the usage of an iterator is mandatory, because Beanshell doesn't support java "for each" syntax. * For usage in java code the "for each" syntax is recommended -> see {@link #getFilteredChildren_ForEach(de.espirit.firstspirit.access.project.Project)} for details. * * @return the filtered storelements * @see #getFilteredChildren_ForEach(de.espirit.firstspirit.access.project.Project) * @since 4.2.410 */ public Map<String, IDProvider> getFilteredChildren_Iterator(final Project project) { final UserService userService = project.getUserService(); final Store currentPageStore = userService.getStore(Type.PAGESTORE, false); final StoreElementFilter filter = StoreElementFilter.on(PageFolder.class, Page.class); // get filtered children recursive final Listable<StoreElement> filteredListable = currentPageStore.getChildren(filter, true); final Map<String, IDProvider> result = new HashMap<String, IDProvider>(); final Iterator<StoreElement> filteredIterator = filteredListable.iterator(); while (filteredIterator.hasNext()) { // we filtered on Page and PageFolder, therefore we can cast to IdProvider without risk final IDProvider idProvider = (IDProvider) filteredIterator.next(); if (idProvider.hasUid()) { result.put(idProvider.getUid(), idProvider); } } return result; } /** * Example how to use a StoreElementFilter which filters PageFolders and Pages within the {@link PageStoreRoot PageStore} of the given {@link Project} using "for each" syntax.<br/> * * <b>Important:</b> In a Beanshell script the "for each" is not supported, therefore an iterator should be used -> see {@link #getFilteredChildren_Iterator(de.espirit.firstspirit.access.project.Project)} for details. * * @return the filtered storelements * @see #getFilteredChildren_Iterator(de.espirit.firstspirit.access.project.Project) * @since 4.2.410 */ public Map<String, IDProvider> getFilteredChildren_ForEach(final Project project) { final UserService userService = project.getUserService(); final Store currentPageStore = userService.getStore(Type.PAGESTORE, false); final StoreElementFilter filter = StoreElementFilter.on(PageFolder.class, Page.class); // get filtered children recursive final Listable<StoreElement> filteredListable = currentPageStore.getChildren(filter, true); final Map<String, IDProvider> result = new HashMap<String, IDProvider>(); for (final StoreElement storeElement : filteredListable) { // we filtered on Page and PageFolder, therefore we can cast to IdProvider without risk final IDProvider idProvider = (IDProvider) storeElement; if (idProvider.hasUid()) { result.put(idProvider.getUid(), idProvider); } } return result; } }
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.espirit.common.util.Filter
Filter.AndFilter<T>, Filter.CombinedFilter<T>, Filter.EqualFilter<T>, Filter.ImpliesFilter<T>, Filter.NotFilter<T>, Filter.OrFilter<T>, Filter.TypedFilter<T>, Filter.Util
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic StoreElementFilter
create
(Filter<StoreElement> filter) static <T extends StoreElement>
StoreElementFilterstatic <T extends StoreElement>
StoreElementFiltercreate
(Class<T> type, Filter<StoreElement> filter) static <T> Filter.TypedFilter<T>
createIncludeFilter
(@NotNull Class<T> type, Class<? extends T>... includes) Creates and returns a class based type filter with an additional include filtering of the specified sub classes.@Nullable StoreElement
Filter the given element and return either an object of this classes type T or null, if the element does not match the filter as defined byFilter.accept(Object)
.@NotNull Class<StoreElement>
getType()
Get the filter type.static StoreElementFilter
on
(Class<? extends StoreElement>... types)
-
Field Details
-
ACCEPT_ALL
- Since:
- 4.0.26
-
-
Constructor Details
-
StoreElementFilter
public StoreElementFilter()- Since:
- 4.0.17
-
StoreElementFilter
- Since:
- 4.0.26
-
-
Method Details
-
filter
Filter the given element and return either an object of this classes type T or null, if the element does not match the filter as defined byFilter.accept(Object)
.- Specified by:
filter
in interfaceFilter.TypedFilter<StoreElement>
- Parameters:
element
- The element to be filtered.- Returns:
- The correctly typed element or null.
- Since:
- 4.0.17
-
getType
Get the filter type.- Specified by:
getType
in interfaceFilter.TypedFilter<StoreElement>
- Returns:
- The filter type.
- Since:
- 4.0.17
-
create
- Since:
- 4.0.26
-
create
public static <T extends StoreElement> StoreElementFilter create(Class<T> type, Filter<StoreElement> filter) - Since:
- 4.0.26
-
create
- Since:
- 4.0.26
-
on
- Since:
- 4.0.40
-
createIncludeFilter
public static <T> Filter.TypedFilter<T> createIncludeFilter(@NotNull @NotNull Class<T> type, Class<? extends T>... includes) Creates and returns a class based type filter with an additional include filtering of the specified sub classes.- Type Parameters:
T
- Type of the filter.- Parameters:
type
- The type to check basically for.includes
- A list of included classes that should not be filtered.- Returns:
- The created type filter.
- Since:
- 5.0.3
-