io.sphere.sdk.categories.CategoryTree Maven / Gradle / Ivy
package io.sphere.sdk.categories;
import io.sphere.sdk.models.Identifiable;
import java.util.*;
import static java.util.Objects.requireNonNull;
/**
* All categories in the project, represented as an in-memory tree.
*
* Consult the documentation for categories for more information.
*/
public interface CategoryTree {
/**
* Root categories (the ones that have no parent).
* @return root categories
*/
List getRoots();
/**
* Finds a category by id.
* @param id the ID of the category to search for
* @return category
*/
Optional findById(String id);
Optional findByExternalId(String externalId);
/**
* Finds a category by the slug and a specific locale.
* @param locale the locale
* @param slug the slug
* @return a category matching the criteria
*/
Optional findBySlug(Locale locale, String slug);
/**
* All categories as a flat list.
* @return all categories
*/
List getAllAsFlatList();
/**
* return the children for category. If there are no children or category is not in this {@link CategoryTree} then the list is empty.
* @param category the category which should be the parent category to the result list
* @return list of children or empty list
*/
List findChildren(final Identifiable category);
/**
* Creates a category tree from a flat list of categories.
*
* @param allCategoriesAsFlatList all categories as flat list.
* @return the created category tree.
*/
static CategoryTree of(final List allCategoriesAsFlatList) {
requireNonNull(allCategoriesAsFlatList);
return CategoryTreeFactory.of().create(allCategoriesAsFlatList);
}
}