/** * Creates a category tree from a flat list of categories. * * @param allCategoriesAsFlatListWithoutChildrenSettings all categories as flat list, {@code element.getChildren()} must result in an empty list. * @return the created category tree. */ static CategoryTree of(final List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { requireNonNull(allCategoriesAsFlatListWithoutChildrenSettings); return CategoryTreeFactory.create(allCategoriesAsFlatListWithoutChildrenSettings); } }
/** * Creates a category tree from a flat list of categories. * * @param allCategoriesAsFlatListWithoutChildrenSettings all categories as flat list, {@code element.getChildren()} must result in an empty list. * @return the created category tree. */ static CategoryTree of(final List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { requireNonNull(allCategoriesAsFlatListWithoutChildrenSettings); return CategoryTreeFactory.create(allCategoriesAsFlatListWithoutChildrenSettings); } }
/** * Creates a category tree from a flat list of categories. * * @param allCategoriesAsFlatListWithoutChildrenSettings all categories as flat list, {@code element.getChildren()} must result in an empty list. * @return the created category tree. */ static CategoryTree of(final List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { requireNonNull(allCategoriesAsFlatListWithoutChildrenSettings); return CategoryTreeFactory.create(allCategoriesAsFlatListWithoutChildrenSettings); } }
/** * 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<Category> allCategoriesAsFlatList) { requireNonNull(allCategoriesAsFlatList); return CategoryTreeFactory.of().create(allCategoriesAsFlatList); } }
/** * 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<Category> allCategoriesAsFlatList) { requireNonNull(allCategoriesAsFlatList); return CategoryTreeFactory.of().create(allCategoriesAsFlatList); } }
/** * 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<Category> allCategoriesAsFlatList) { requireNonNull(allCategoriesAsFlatList); return CategoryTreeFactory.of().create(allCategoriesAsFlatList); } }
public CategoryTree create(final List<Category> allCategoriesAsFlatList) { final List<Category> roots = findRoots(allCategoriesAsFlatList); return create(allCategoriesAsFlatList, roots, roots); }
public CategoryTree create(final List<Category> allCategoriesAsFlatList) { final List<Category> roots = findRoots(allCategoriesAsFlatList); return create(allCategoriesAsFlatList, roots, roots); }
public CategoryTree createSubtree(final CategoryTree categoryTree, final Collection<? extends Identifiable<Category>> subtreeRoots) { final List<Category> subtreeRootsCategories = subtreeRoots.stream() .map(identifiable -> getCategoryOrThrow(identifiable, categoryTree)) .collect(toList()); final List<String> subtreeRootIds = subtreeRoots.parallelStream().map(Identifiable::getId).collect(toList()); subtreeRootsCategories.forEach(subtreeRoot -> { final Optional<String> rootAncestorOptional = subtreeRoot.getAncestors() .stream() .map(x -> x.getId()) .filter(ancestorId -> subtreeRootIds.contains(ancestorId)) .findFirst(); if (rootAncestorOptional.isPresent()) { throw new IllegalArgumentException(String.format("category of ID [%s] cannot be subtree root and descendant of [%s]", subtreeRoot.getId(), rootAncestorOptional.get())); } }); final List<Category> includedCategories = new LinkedList<>(); subtreeRootsCategories.forEach(parentCategory -> { includedCategories.add(parentCategory); final List<Category> children = categoryTree.findChildren(parentCategory); includedCategories.addAll(getSubtreeAsFlatList(categoryTree, children)); }); final List<Category> roots = findRoots(includedCategories); return create(includedCategories, roots, subtreeRootsCategories); } }
public CategoryTree createSubtree(final CategoryTree categoryTree, final Collection<? extends Identifiable<Category>> subtreeRoots) { final List<Category> subtreeRootsCategories = subtreeRoots.stream() .map(identifiable -> getCategoryOrThrow(identifiable, categoryTree)) .collect(toList()); final List<String> subtreeRootIds = subtreeRoots.parallelStream().map(Identifiable::getId).collect(toList()); subtreeRootsCategories.forEach(subtreeRoot -> { final Optional<String> rootAncestorOptional = subtreeRoot.getAncestors() .stream() .map(x -> x.getId()) .filter(ancestorId -> subtreeRootIds.contains(ancestorId)) .findFirst(); if (rootAncestorOptional.isPresent()) { throw new IllegalArgumentException(String.format("category of ID [%s] cannot be subtree root and descendant of [%s]", subtreeRoot.getId(), rootAncestorOptional.get())); } }); final List<Category> includedCategories = new LinkedList<>(); subtreeRootsCategories.forEach(parentCategory -> { includedCategories.add(parentCategory); final List<Category> children = categoryTree.findChildren(parentCategory); includedCategories.addAll(getSubtreeAsFlatList(categoryTree, children)); }); final List<Category> roots = findRoots(includedCategories); return create(includedCategories, roots, subtreeRootsCategories); } }