public CategoryTree create(final List<Category> allCategoriesAsFlatList, final List<Category> roots, final List<Category> subtreeRoots) { final List<Category> allAsFlatList = allCategoriesAsFlatList; final Map<LocalizedStringEntry, Category> categoriesByLocaleAndSlug = getLocalizedStringEntryCategoryMap(allCategoriesAsFlatList); final Map<String, Category> categoriesById = allCategoriesAsFlatList.stream().collect(toMap(Category::getId, Function.<Category>identity())); final Map<String, Category> categoriesByKey = allCategoriesAsFlatList.stream().filter(category -> category.getKey() != null).collect(toMap(Category::getKey, Function.<Category>identity())); final Map<String, List<Category>> childrenByParentId = getChildrenByParentIdMap(allCategoriesAsFlatList); return new CategoryTreeImpl(roots, allAsFlatList, categoriesByLocaleAndSlug, categoriesById, categoriesByKey ,childrenByParentId, subtreeRoots); }
public CategoryTree create(final List<Category> allCategoriesAsFlatList, final List<Category> roots, final List<Category> subtreeRoots) { final List<Category> allAsFlatList = allCategoriesAsFlatList; final Map<LocalizedStringEntry, Category> categoriesByLocaleAndSlug = getLocalizedStringEntryCategoryMap(allCategoriesAsFlatList); final Map<String, Category> categoriesById = allCategoriesAsFlatList.stream().collect(toMap(Category::getId, Function.<Category>identity())); final Map<String, Category> categoriesByKey = allCategoriesAsFlatList.stream().filter(category -> category.getKey() != null).collect(toMap(Category::getKey, Function.<Category>identity())); final Map<String, List<Category>> childrenByParentId = getChildrenByParentIdMap(allCategoriesAsFlatList); return new CategoryTreeImpl(roots, allAsFlatList, categoriesByLocaleAndSlug, categoriesById, categoriesByKey ,childrenByParentId, subtreeRoots); }
public CategoryTree create(final List<Category> allCategoriesAsFlatList) { final Predicate<Category> isRootCategory = c -> c.getParent() == null; final List<Category> roots = allCategoriesAsFlatList.parallelStream().filter(isRootCategory).collect(toList()); final List<Category> allAsFlatList = allCategoriesAsFlatList; final Map<LocalizedStringEntry, Category> categoriesByLocaleAndSlug = new HashMap<>(); allCategoriesAsFlatList.forEach(category -> { final Set<Locale> localesForTheCategory = category.getSlug().getLocales(); localesForTheCategory.forEach(locale -> { final LocalizedStringEntry stringsEntry = LocalizedStringEntry.of(locale, category.getSlug().get(locale)); categoriesByLocaleAndSlug.put(stringsEntry, category); }); }); final Map<String, Category> categoriesById = allCategoriesAsFlatList.stream().collect(toMap(Category::getId, Function.<Category>identity())); final Map<String, List<Category>> childrenByParentId = new HashMap<>(); allCategoriesAsFlatList.forEach(category -> Optional.ofNullable(category.getParent()).ifPresent(parentReference -> { final String parentId = parentReference.getId(); final List<Category> entries = childrenByParentId.getOrDefault(parentId, new LinkedList<>()); entries.add(category); childrenByParentId.put(parentId, entries); }) ); return new CategoryTreeImpl(roots, allAsFlatList, categoriesByLocaleAndSlug, categoriesById, childrenByParentId); } }
public static CategoryTree create(final List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { final List<Category> categoryTreeList = categoriesOrganizedAsTree(allCategoriesAsFlatListWithoutChildrenSettings); final List<Category> allAsFlatList = getAllRecursive(categoryTreeList); final Map<LocaleSlugPair, Category> categoriesByLocaleAndSlug = buildBySlugMap(allAsFlatList); final Map<String, Category> categoriesById = buildByIdMap(allAsFlatList); return new CategoryTreeImpl(categoryTreeList, allAsFlatList, categoriesByLocaleAndSlug, categoriesById); }
public static CategoryTree create(final List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { final List<Category> categoryTreeList = categoriesOrganizedAsTree(allCategoriesAsFlatListWithoutChildrenSettings); final List<Category> allAsFlatList = getAllRecursive(categoryTreeList); final Map<LocaleSlugPair, Category> categoriesByLocaleAndSlug = buildBySlugMap(allAsFlatList); final Map<String, Category> categoriesById = buildByIdMap(allAsFlatList); return new CategoryTreeImpl(categoryTreeList, allAsFlatList, categoriesByLocaleAndSlug, categoriesById); }
public static CategoryTree create(final List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { final List<Category> categoryTreeList = categoriesOrganizedAsTree(allCategoriesAsFlatListWithoutChildrenSettings); final List<Category> allAsFlatList = getAllRecursive(categoryTreeList); final Map<LocaleSlugPair, Category> categoriesByLocaleAndSlug = buildBySlugMap(allAsFlatList); final Map<String, Category> categoriesById = buildByIdMap(allAsFlatList); return new CategoryTreeImpl(categoryTreeList, allAsFlatList, categoriesByLocaleAndSlug, categoriesById); }