X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fdatabase%2FComponentPresetDao.java;h=a27a7f5d424304295d84c631ea261be95a019b82;hb=2bddccc8c2e80651f15e0b6c22c23f113c17610a;hp=fca47d17aad555d8b1bfdacdf6b0f2bf37b199f9;hpb=3ad331a1a95273625d88268ed7bc12c17cfcfee4;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/database/ComponentPresetDao.java b/core/src/net/sf/openrocket/database/ComponentPresetDao.java index fca47d17..a27a7f5d 100644 --- a/core/src/net/sf/openrocket/database/ComponentPresetDao.java +++ b/core/src/net/sf/openrocket/database/ComponentPresetDao.java @@ -1,73 +1,16 @@ package net.sf.openrocket.database; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Set; -import net.sf.openrocket.file.preset.PresetCSVReader; import net.sf.openrocket.preset.ComponentPreset; -import net.sf.openrocket.preset.InvalidComponentPresetException; -import net.sf.openrocket.preset.TypedPropertyMap; -import net.sf.openrocket.startup.Application; -import net.sf.openrocket.util.BugException; -public class ComponentPresetDao { +public interface ComponentPresetDao { - // List of all ComponentPresets - private final List templates = new ArrayList(); - - // Package scope constructor to control creation pattern. - public ComponentPresetDao() {} - - public void initialize() throws IOException { - - Set favorites = Application.getPreferences().getComponentFavorites(); - - InputStream is = ComponentPresetDao.class.getResourceAsStream("/datafiles/bodytubepresets.csv"); - - PresetCSVReader parser = new PresetCSVReader(is); - List 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 listAll() { - return templates; - } - - public void insert( ComponentPreset preset ) { - templates.add(preset); - } - - public List listForType( ComponentPreset.Type type ) { - if ( type == null ) { - return Collections.emptyList(); - } - - List result = new ArrayList(templates.size()/6); - - for( ComponentPreset preset : templates ) { - if ( preset.get(ComponentPreset.TYPE).equals(type) ) { - result.add(preset); - } - } - return result; + public List listAll(); + + public void insert( ComponentPreset preset ); - } + public List listForType( ComponentPreset.Type type ); /** * Return a list of component presets based on the type. @@ -77,52 +20,14 @@ public class ComponentPresetDao { * @param favorite if true, only return the favorites. otherwise return all matching. * @return */ - public List listForType( ComponentPreset.Type type, boolean favorite ) { - - if ( !favorite ) { - return listForType(type); - } + public List listForType( ComponentPreset.Type type, boolean favorite ); - List result = new ArrayList(templates.size()/6); - - for( ComponentPreset preset : templates ) { - if ( preset.isFavorite() && preset.get(ComponentPreset.TYPE).equals(type) ) { - result.add(preset); - } - } - return result; - - - } - - public List listForTypes( ComponentPreset.Type ... type ) { - - if( type == null || type.length == 0 ) { - return Collections.emptyList(); - } - - if (type.length == 1 ) { - return listForType(type[0]); - } - - List result = new ArrayList(templates.size()/6); - - for( ComponentPreset preset : templates ) { - ComponentPreset.Type presetType = preset.get(ComponentPreset.TYPE); - typeLoop: for( int i=0; i listForTypes( ComponentPreset.Type ... type ); + + public List listForTypes( List types ); - public void setFavorite( ComponentPreset preset, boolean favorite ) { - preset.setFavorite(favorite); - Application.getPreferences().setComponentFavorite( preset, favorite ); - } + public void setFavorite( ComponentPreset preset, ComponentPreset.Type type, boolean favorite ); + + public List find( String manufacturer, String partNo ); } \ No newline at end of file