private static List<Category> categoriesOrganizedAsTree(List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { final List<Category> categoriesOrganizedInTrees; if (allCategoriesAsFlatListWithoutChildrenSettings == null) { categoriesOrganizedInTrees = Collections.emptyList(); LOGGER.warn(() -> "null passed for categories."); } else if (allCategoriesAsFlatListWithoutChildrenSettings.size() == 0) { categoriesOrganizedInTrees = Collections.emptyList(); } else { final Pair<List<Category>, List<Category>> partition = partition(allCategoriesAsFlatListWithoutChildrenSettings, new CategoryHasParentPredicate()); final List<Category> rootCategories = partition.getLeft(); final List<Category> categoriesWithoutParents = partition.getRight(); final Multimap<String, Category> categoriesByParentId = buildParentMultiMap(rootCategories); categoriesOrganizedInTrees = buildTreeRecursive(Optional.<Category>empty(), categoriesWithoutParents, new ArrayList<>(), categoriesByParentId); } return categoriesOrganizedInTrees; }
private static List<Category> categoriesOrganizedAsTree(List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { final List<Category> categoriesOrganizedInTrees; if (allCategoriesAsFlatListWithoutChildrenSettings == null) { categoriesOrganizedInTrees = Collections.emptyList(); LOGGER.warn(() -> "null passed for categories."); } else if (allCategoriesAsFlatListWithoutChildrenSettings.size() == 0) { categoriesOrganizedInTrees = Collections.emptyList(); } else { final Pair<List<Category>, List<Category>> partition = partition(allCategoriesAsFlatListWithoutChildrenSettings, new CategoryHasParentPredicate()); final List<Category> rootCategories = partition.getLeft(); final List<Category> categoriesWithoutParents = partition.getRight(); final Multimap<String, Category> categoriesByParentId = buildParentMultiMap(rootCategories); categoriesOrganizedInTrees = buildTreeRecursive(Optional.<Category>empty(), categoriesWithoutParents, new ArrayList<>(), categoriesByParentId); } return categoriesOrganizedInTrees; }
private static List<Category> categoriesOrganizedAsTree(List<Category> allCategoriesAsFlatListWithoutChildrenSettings) { final List<Category> categoriesOrganizedInTrees; if (allCategoriesAsFlatListWithoutChildrenSettings == null) { categoriesOrganizedInTrees = Collections.emptyList(); LOGGER.warn(() -> "null passed for categories."); } else if (allCategoriesAsFlatListWithoutChildrenSettings.size() == 0) { categoriesOrganizedInTrees = Collections.emptyList(); } else { final Pair<List<Category>, List<Category>> partition = partition(allCategoriesAsFlatListWithoutChildrenSettings, new CategoryHasParentPredicate()); final List<Category> rootCategories = partition.getLeft(); final List<Category> categoriesWithoutParents = partition.getRight(); final Multimap<String, Category> categoriesByParentId = buildParentMultiMap(rootCategories); categoriesOrganizedInTrees = buildTreeRecursive(Optional.<Category>empty(), categoriesWithoutParents, new ArrayList<>(), categoriesByParentId); } return categoriesOrganizedInTrees; }