Interface CategoryTree
public interface CategoryTree
All categories in the project, represented as an in-memory tree.
-
Method Summary
Modifier and TypeMethodDescriptionfindByExternalId
(String externalId) Finds a category by its external ID.Finds a category by id.Finds a category by the key.findBySlug
(Locale locale, String slug) Finds a category by the slug and a specific locale.findChildren
(Identifiable<Category> category) return the children for category.findSiblings
(Collection<? extends Identifiable<Category>> categoryIds) Gets a list containing all categories that share a parent with at least one of the given categories.All categories as a flat list.getRootAncestor
(Identifiable<Category> category) For a given category searches the ancestor that is in root level.getRoots()
Root categories (the ones that have no parent).getSubtree
(Collection<? extends Identifiable<Category>> parentCategories) Gets the subtree of the given parent categories.For a subtree the categories which are at the top level.static CategoryTree
Creates a category tree from a flat list of categories.
-
Method Details
-
getRoots
Root categories (the ones that have no parent).- Returns:
- root categories
-
findById
Finds a category by id.- Parameters:
id
- the ID of the category to search for- Returns:
- category
-
findByExternalId
Finds a category by its external ID.- Parameters:
externalId
- the external id of the category to find- Returns:
- optional
-
findBySlug
Finds a category by the slug and a specific locale.- Parameters:
locale
- the localeslug
- the slug- Returns:
- a category matching the criteria
-
findByKey
Finds a category by the key.- Parameters:
key
- the category key- Returns:
- a category matching the criteria
-
getAllAsFlatList
All categories as a flat list.- Returns:
- all categories
-
findChildren
return the children for category. If there are no children or category is not in thisCategoryTree
then the list is empty.- Parameters:
category
- the category which should be the parent category to the result list- Returns:
- list of children or empty list
-
findSiblings
Gets a list containing all categories that share a parent with at least one of the given categories.- Parameters:
categoryIds
- Categories for which the sibling categories should be fetched- Returns:
- a list of sibling categories
-
getSubtree
Gets the subtree of the given parent categories.- Parameters:
parentCategories
- the list of parent categories to use as a starting point- Returns:
- the subtree with the subcategories including the parent categories
-
getRootAncestor
For a given category searches the ancestor that is in root level.- Parameters:
category
- the category which to find the root ancestor- Returns:
- the root ancestor of the category or the same category in case it is a root itself
-
getSubtreeRoots
For a subtree the categories which are at the top level.Unlike
getRoots()
this does ignore the parent reference.- Returns:
- subtree roots
-
of
Creates a category tree from a flat list of categories.- Parameters:
allCategoriesAsFlatList
- all categories as flat list.- Returns:
- the created category tree.
-