package net.sf.openrocket.database;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
import java.util.List;
-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.util.BugException;
-public class ComponentPresetDao {
+public interface ComponentPresetDao {
- private final List<ComponentPreset> templates = new ArrayList<ComponentPreset>();
-
- // Package scope constructor to control creation pattern.
- ComponentPresetDao() {}
+ public List<ComponentPreset> listAll();
- void initialize() throws IOException {
-
- 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);
- this.insert(preset);
- } catch ( InvalidComponentPresetException ex ) {
- throw new BugException( ex );
- }
- }
- }
+ public void insert( ComponentPreset preset );
+
+ public List<ComponentPreset> listForType( ComponentPreset.Type type );
+
+ /**
+ * Return a list of component presets based on the type.
+ * All components returned will be of Type type.
+ *
+ * @param type
+ * @param favorite if true, only return the favorites. otherwise return all matching.
+ * @return
+ */
+ public List<ComponentPreset> listForType( ComponentPreset.Type type, boolean favorite );
+
+ public List<ComponentPreset> listForTypes( ComponentPreset.Type ... type );
- public List<ComponentPreset> listAll() {
- return templates;
- }
+ public List<ComponentPreset> listForTypes( List<ComponentPreset.Type> types );
+
+ public void setFavorite( ComponentPreset preset, ComponentPreset.Type type, boolean favorite );
- public void insert( ComponentPreset preset ) {
- templates.add(preset);
- }
+ public List<ComponentPreset> find( String manufacturer, String partNo );
-}
+}
\ No newline at end of file