package bluej.stride.generic;

import bluej.Config;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


| Holds a list of all the blocks, and information about them (e.g. shortcut key, description) | public abstract class FrameDictionary<CATEGORY>{ public static class Entry<CATEGORY> { private final FrameFactory<? extends Frame> factory; private final List<Character> shortcutKeys; private final String name; private final String description; private final CATEGORY category; private final boolean validOnSelection; private final boolean showingInCatalogue; public Entry(char shortcutKey, FrameFactory<? extends Frame> factory, boolean validOnSelection, CATEGORY category, String nameLabel, String descriptionLabel) { this(Arrays.asList(shortcutKey), factory, validOnSelection, category, nameLabel, descriptionLabel, true); } public Entry(char shortcutKey, FrameFactory<? extends Frame> factory, boolean validOnSelection, CATEGORY category, String nameLabel, String descriptionLabel, boolean showingInCatalogue) { this(Arrays.asList(shortcutKey), factory, validOnSelection, category, nameLabel, descriptionLabel, showingInCatalogue); } private Entry(List<Character> shortcutKeys, FrameFactory<? extends Frame> factory, boolean validOnSelection, CATEGORY category, String nameLabel, String descriptionLabel, boolean showingInCatalogue) { this.shortcutKeys = new ArrayList<>(shortcutKeys); this.factory = factory; this.validOnSelection = validOnSelection; this.category = category; this.name = Config.getString(nameLabel); this.description = Config.getString(descriptionLabel); this.showingInCatalogue = showingInCatalogue; } public boolean inCategory(CATEGORY c) { return category.equals(c); } public boolean hasShortcut(char k) { return shortcutKeys.contains(k); } public List getReadOnlyShortcuts() { return Collections.unmodifiableList(shortcutKeys); } public FrameFactory getFactory() { return factory; } public String getName() { return name; } public String getDescription() { return description; } public CATEGORY getCategory() { return category; } public String getCategoryName() { return category.toString(); } public Class getBlockClass() { return factory.getBlockClass(); } public boolean isValidOnSelection() { return validOnSelection; } public boolean isShowingInCatalogue() { return showingInCatalogue; } public String getShortcuts() { StringBuilder builder = new StringBuilder(); builder.append(shortcutKeys.get(0)); for (int i = 1; i < shortcutKeys.size(); i++) { builder.append(", ").append(shortcutKeys.get(i)); } return builder.toString(); } } private final List<Entry<CATEGORY>> entries; protected FrameDictionary(List<Entry<CATEGORY>> entries) { this.entries = entries; } public List> getAllBlocks() { return entries; } public List> getBlocksInCategory(CATEGORY c) { return entries.stream().filter(e -> e.inCategory(c)).collect(Collectors.toList()); }
| Return categories | public abstract CATEGORY[] getCategories(); public abstract String[] getCategoryNames();
| Returns empty list if no block for that key | public List> getFramesForShortcutKey(char k) { return entries.stream().filter(e -> e.hasShortcut(k)).collect(Collectors.toList()); } }

.   Entry
.   Entry
.   Entry
.   inCategory
.   hasShortcut
.   getReadOnlyShortcuts
.   getFactory
.   getName
.   getDescription
.   getCategory
.   getCategoryName
.   getBlockClass
.   isValidOnSelection
.   isShowingInCatalogue
.   getShortcuts
.   FrameDictionary
.   getAllBlocks
.   getBlocksInCategory
.   getCategories
.   getCategoryNames
.   getFramesForShortcutKey




164 neLoCode + 3 LoComm