- // List of all ComponentPresets
- private final List<ComponentPreset> templates = new ArrayList<ComponentPreset>();
-
- // Package scope constructor to control creation pattern.
- public ComponentPresetDao() {}
-
- public void initialize() throws IOException {
-
- Set<String> favorites = Application.getPreferences().getComponentFavorites();
-
- InputStream is = ComponentPresetDao.class.getResourceAsStream("/datafiles/bodytubepresets.csv");
-
- PresetCSVReader parser = new PresetCSVReader(is);
- List<TypedPropertyMap> list = parser.parse();
- for( TypedPropertyMap o : list ) {
- try {
- ComponentPreset preset = ComponentPreset.create(o);
- if ( favorites.contains(preset.preferenceKey())) {
- preset.setFavorite(true);
- }
- this.insert(preset);
- } catch ( InvalidComponentPresetException ex ) {
- throw new BugException( ex );
- }
- }
-
-
- }
-
- public List<ComponentPreset> listAll() {
- return templates;
- }
-
- public void insert( ComponentPreset preset ) {
- templates.add(preset);
- }
-
- public List<ComponentPreset> listForType( ComponentPreset.Type type ) {
- if ( type == null ) {
- return Collections.<ComponentPreset>emptyList();
- }
-
- List<ComponentPreset> result = new ArrayList<ComponentPreset>(templates.size()/6);
-
- for( ComponentPreset preset : templates ) {
- if ( preset.get(ComponentPreset.TYPE).equals(type) ) {
- result.add(preset);
- }
- }
- return result;