public void makeCategories(int n) { for (int i = 1; i < n; i++) { Category category = new Category("Kategoria nr " + i); category.setId((long) i); for (int k = 1; k < 7; k++) { Category cat = new Category("[cat" + i + "] Podkategoria nr " + k); category.setId((long) (100 * i + k)); category.addSubCategory(cat); } cat.add(category); } }
public Category getCategoryByName(List<Category> categories, String categoryName) { for (Category category : categories) { if (category.nameProperty().get().equalsIgnoreCase(categoryName)) return category; if (!category.subCategoriesObservableSet().isEmpty()) { Category result = getCategoryByName( new LinkedList<>(category.subCategoriesObservableSet()), categoryName); if (result != null) { return result; } } } return null; }