import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
+import net.sf.openrocket.util.BugException;
/**
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
-public class ComponentPreset extends TypedPropertyMap {
+public class ComponentPreset {
+
+ private final Map<TypedKey<?>, Object> properties = new HashMap<TypedKey<?>, Object>();
+
// TODO - Implement clone.
// Implement "freezing" so the object cannot be modified.
public enum Type {
- BodyTube,
- NoseCone
+ BODY_TUBE,
+ NOSE_CONE
}
-
+
public final static TypedKey<Double> LENGTH = new TypedKey<Double>("Length", Double.class);
public final static TypedKey<Double> INNER_DIAMETER = new TypedKey<Double>("InnerDiameter", Double.class);
public final static TypedKey<Double> OUTER_DIAMETER = new TypedKey<Double>("OuterDiameter", Double.class);
public final static TypedKey<Material> MATERIAL = new TypedKey<Material>("Material", Material.class);
- public final static TypedKey<Finish> FINISH = new TypedKey<Finish>("Finish",Finish.class);
+ public final static TypedKey<Finish> FINISH = new TypedKey<Finish>("Finish", Finish.class);
public final static TypedKey<Double> THICKNESS = new TypedKey<Double>("Thickness", Double.class);
- public final static TypedKey<Boolean> FILLED = new TypedKey<Boolean>("Filled",Boolean.class);
+ public final static TypedKey<Boolean> FILLED = new TypedKey<Boolean>("Filled", Boolean.class);
public final static TypedKey<Double> MASS = new TypedKey<Double>("Mass", Double.class);
- public final static Map<String,TypedKey<?>> keyMap = new HashMap<String,TypedKey<?>>();
+ public final static Map<String, TypedKey<?>> keyMap = new HashMap<String, TypedKey<?>>();
static {
keyMap.put(LENGTH.getName(), LENGTH);
keyMap.put(INNER_DIAMETER.getName(), INNER_DIAMETER);
private String partNo;
private String partDescription;
private Type type;
-
- public ComponentPreset() {
-
- }
-
+
+
public String getManufacturer() {
return manufacturer;
}
-
+
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
-
+
public String getPartNo() {
return partNo;
}
-
+
public void setPartNo(String partNo) {
this.partNo = partNo;
}
-
+
public String getPartDescription() {
return partDescription;
}
-
+
public void setPartDescription(String partDescription) {
this.partDescription = partDescription;
}
-
+
public Type getType() {
return type;
}
-
+
public void setType(Type type) {
this.type = type;
}
-
+
+
+ public boolean has(Object key) {
+ return properties.containsKey(key);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T get(TypedKey<T> key) {
+ Object value = properties.get(key);
+ if (value == null) {
+ throw new BugException("Preset of type " + type + " did not contain key " + key + " mfg=" + manufacturer + " partNo=" + partNo);
+ }
+ return (T) value;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T put(TypedKey<T> key, T value) {
+ return (T) properties.put(key, value);
+ }
+
+
+
+ @Override
+ public String toString() {
+ return partNo;
+ }
+
}