public List<ShortcutCategoryDTO> fetchShortcuts() { final File shortcutDirectoryFile = new File(this.shortcutDirectory); if (!shortcutDirectoryFile.exists()) { shortcutDirectoryFile.mkdirs(); return Collections.emptyList(); } final File[] directoryContent = shortcutDirectoryFile.listFiles(); if (directoryContent == null) { return Collections.emptyList(); } HashMap<String, List<ShortcutDTO>> categoryMap = new HashMap<>(); for (File file : directoryContent) { if ("shortcut".equals(FilenameUtils.getExtension(file.getName()))) { ShortcutDTO shortcut = fetchShortcutDTO(shortcutDirectoryFile, file); String categoryId = shortcut.getInfo().getCategory(); if (!categoryMap.containsKey(categoryId)) { categoryMap.put(categoryId, new ArrayList<>()); } categoryMap.get(categoryId).add(shortcut); } } List<ShortcutCategoryDTO> shortcuts = new ArrayList<>(); for (Map.Entry<String, List<ShortcutDTO>> entry : categoryMap.entrySet()) { entry.getValue().sort(ShortcutDTO.nameComparator()); ShortcutCategoryDTO category = new ShortcutCategoryDTO.Builder().withId(entry.getKey()) .withName(entry.getKey()).withShortcuts(entry.getValue()).build(); shortcuts.add(tr(category)); } return shortcuts; }
public Builder(ShortcutCategoryDTO categoryDTO) { this.withId(categoryDTO.getId()).withName(categoryDTO.getName()) .withDescription(categoryDTO.getDescription()).withShortcuts(categoryDTO.getShortcuts()) .withIcon(categoryDTO.getIcon()); }