Interface CategoryTree


public interface CategoryTree
All categories in the project, represented as an in-memory tree.
  • Method Details

    • getRoots

      List<Category> getRoots()
      Root categories (the ones that have no parent).
      Returns:
      root categories
    • findById

      Optional<Category> findById(String id)
      Finds a category by id.
      Parameters:
      id - the ID of the category to search for
      Returns:
      category
    • findByExternalId

      Optional<Category> findByExternalId(String externalId)
      Finds a category by its external ID.
      Parameters:
      externalId - the external id of the category to find
      Returns:
      optional
    • findBySlug

      Optional<Category> findBySlug(Locale locale, String slug)
      Finds a category by the slug and a specific locale.
      Parameters:
      locale - the locale
      slug - the slug
      Returns:
      a category matching the criteria
    • findByKey

      Optional<Category> findByKey(String key)
      Finds a category by the key.
      Parameters:
      key - the category key
      Returns:
      a category matching the criteria
    • getAllAsFlatList

      List<Category> getAllAsFlatList()
      All categories as a flat list.
      Returns:
      all categories
    • findChildren

      List<Category> findChildren(Identifiable<Category> category)
      return the children for category. If there are no children or category is not in this CategoryTree 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

      List<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.
      Parameters:
      categoryIds - Categories for which the sibling categories should be fetched
      Returns:
      a list of sibling categories
    • getSubtree

      CategoryTree getSubtree(Collection<? extends Identifiable<Category>> parentCategories)
      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

      Category getRootAncestor(Identifiable<Category> category)
      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

      List<Category> getSubtreeRoots()
      For a subtree the categories which are at the top level.

      Unlike getRoots() this does ignore the parent reference.

      Returns:
      subtree roots
    • of

      static CategoryTree of(List<Category> allCategoriesAsFlatList)
      Creates a category tree from a flat list of categories.
      Parameters:
      allCategoriesAsFlatList - all categories as flat list.
      Returns:
      the created category tree.