1 package net.sf.openrocket.motor;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashSet;
10 * Class containing information about motor manufacturers.
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14 public class Manufacturer {
16 private static Set<Manufacturer> manufacturers = new HashSet<Manufacturer>();
19 // AeroTech has many name combinations...
20 List<String> names = new ArrayList<String>();
21 for (String s : new String[] { "A", "AT", "AERO", "AEROT", "AEROTECH" }) {
23 names.add(s + "-RMS");
24 names.add(s + "-RCS");
25 names.add("RCS-" + s);
26 names.add(s + "-APOGEE");
30 // Aerotech has single-use, reload and hybrid motors
31 manufacturers.add(new Manufacturer("AeroTech", "AeroTech", Motor.Type.UNKNOWN,
32 names.toArray(new String[0])));
34 manufacturers.add(new Manufacturer("Alpha Hybrid Rocketry LLC", "Alpha Hybrid Rocketry", Motor.Type.HYBRID,
35 "AHR", "ALPHA", "ALPHA HYBRID", "ALPHA HYBRIDS", "ALPHA HYBRIDS ROCKETRY"));
37 // TODO: HIGH: AMW/ProX - how to classify?
39 manufacturers.add(new Manufacturer("Animal Motor Works", "Animal Motor Works", Motor.Type.RELOAD,
40 "AMW", "AW", "ANIMAL"));
42 manufacturers.add(new Manufacturer("Apogee", "Apogee", Motor.Type.SINGLE,
45 manufacturers.add(new Manufacturer("Cesaroni Technology Inc.", "Cesaroni Technology", Motor.Type.RELOAD,
46 "CES", "CESARONI", "CESARONI TECHNOLOGY INCORPORATED", "CTI",
47 "CS", "CSR", "PRO38", "ABC"));
49 manufacturers.add(new Manufacturer("Contrail Rockets", "Contrail Rockets", Motor.Type.HYBRID,
50 "CR", "CONTR", "CONTRAIL", "CONTRAIL ROCKET"));
52 manufacturers.add(new Manufacturer("Estes", "Estes", Motor.Type.SINGLE,
55 // Ellis Mountain has both single-use and reload motors
56 manufacturers.add(new Manufacturer("Ellis Mountain", "Ellis Mountain", Motor.Type.UNKNOWN,
57 "EM", "ELLIS", "ELLIS MOUNTAIN ROCKET", "ELLIS MOUNTAIN ROCKETS"));
59 manufacturers.add(new Manufacturer("Gorilla Rocket Motors", "Gorilla Rocket Motors", Motor.Type.RELOAD,
60 "GR", "GORILLA", "GORILLA ROCKET", "GORILLA ROCKETS", "GORILLA MOTOR",
61 "GORILLA MOTORS", "GORILLA ROCKET MOTOR"));
63 manufacturers.add(new Manufacturer("HyperTEK", "HyperTEK", Motor.Type.HYBRID,
66 manufacturers.add(new Manufacturer("Kosdon by AeroTech", "Kosdon by AeroTech", Motor.Type.RELOAD,
67 "K", "KBA", "K-AT", "KOS", "KOSDON", "KOSDON/AT", "KOSDON/AEROTECH"));
69 manufacturers.add(new Manufacturer("Loki Research", "Loki Research", Motor.Type.RELOAD,
72 manufacturers.add(new Manufacturer("Public Missiles, Ltd.", "Public Missiles", Motor.Type.SINGLE,
73 "PM", "PML", "PUBLIC MISSILES LIMITED"));
75 manufacturers.add(new Manufacturer("Propulsion Polymers", "Propulsion Polymers", Motor.Type.HYBRID,
76 "PP", "PROP", "PROPULSION"));
78 manufacturers.add(new Manufacturer("Quest", "Quest", Motor.Type.SINGLE,
81 manufacturers.add(new Manufacturer("RATT Works", "RATT Works", Motor.Type.HYBRID,
82 "RATT", "RT", "RTW"));
84 manufacturers.add(new Manufacturer("Roadrunner Rocketry", "Roadrunner Rocketry", Motor.Type.SINGLE,
87 manufacturers.add(new Manufacturer("Rocketvision", "Rocketvision", Motor.Type.SINGLE,
88 "RV", "ROCKET VISION"));
90 manufacturers.add(new Manufacturer("Sky Ripper Systems", "Sky Ripper Systems", Motor.Type.HYBRID,
91 "SR", "SRS", "SKYR", "SKYRIPPER", "SKY RIPPER", "SKYRIPPER SYSTEMS"));
93 manufacturers.add(new Manufacturer("West Coast Hybrids", "West Coast Hybrids", Motor.Type.HYBRID,
94 "WCH", "WCR", "WEST COAST", "WEST COAST HYBRID"));
96 // German WECO Feuerwerk, previously Sachsen Feuerwerk
97 manufacturers.add(new Manufacturer("WECO Feuerwerk", "WECO Feuerwerk", Motor.Type.SINGLE,
98 "WECO", "WECO FEUERWERKS", "SF", "SACHSEN", "SACHSEN FEUERWERK",
99 "SACHSEN FEUERWERKS"));
102 // Check that no duplicates have appeared
103 for (Manufacturer m1 : manufacturers) {
104 for (Manufacturer m2 : manufacturers) {
107 for (String name : m1.getAllNames()) {
108 if (m2.matches(name)) {
109 throw new IllegalStateException("Manufacturer name clash between " +
110 "manufacturers " + m1 + " and " + m2 + " name " + name);
119 private final String displayName;
120 private final String simpleName;
121 private final Set<String> allNames;
122 private final Set<String> searchNames;
123 private final Motor.Type motorType;
126 private Manufacturer(String displayName, String simpleName, Motor.Type motorType, String... alternateNames) {
127 this.displayName = displayName;
128 this.simpleName = simpleName;
129 this.motorType = motorType;
130 if (motorType == null) {
131 throw new IllegalArgumentException("motorType cannot be null");
134 Set<String> all = new HashSet<String>();
135 Set<String> search = new HashSet<String>();
137 all.add(displayName);
139 search.add(generateSearchString(displayName));
140 search.add(generateSearchString(simpleName));
142 for (String name : alternateNames) {
144 search.add(generateSearchString(name));
147 this.allNames = Collections.unmodifiableSet(all);
148 this.searchNames = Collections.unmodifiableSet(search);
153 * Returns the display name of the manufacturer. This is the value that
154 * should be presented in the UI to the user.
156 * @return the display name
158 public String getDisplayName() {
164 * Returns the simple name of the manufacturer. This should be used for example
165 * when saving the manufacturer for compatibility.
167 * @return the simple name.
169 public String getSimpleName() {
175 * Return all names of the manufacturer. This includes all kinds of
176 * codes that correspond to the manufacturer (for example "A" for AeroTech).
178 * @return an unmodifiable set of the alternative names.
180 public Set<String> getAllNames() {
186 * Return the motor type that this manufacturer produces if it produces only one motor type.
187 * If the manufacturer manufactures multiple motor types or the type is unknown,
188 * type <code>UNKNOWN</code> is returned.
190 * @return the manufactured motor type, or <code>UNKNOWN</code>.
192 public Motor.Type getMotorType() {
198 * Check whether the display, simple or any of the alternative names matches the
199 * specified name. Matching is performed case insensitively and ignoring any
200 * non-letter and non-number characters.
202 * @param name the name to search for.
203 * @return whether this manufacturer matches the request.
205 public boolean matches(String name) {
208 return this.searchNames.contains(generateSearchString(name));
213 * Return the display name of the manufacturer.
216 public String toString() {
222 * Returns a manufacturer for the given name. The manufacturer is searched for
223 * within the manufacturers and if a match is found the corresponding
224 * object is returned. If not, a new manufacturer is returned with display and
225 * simple name the name specified. Subsequent requests for the same (or corresponding)
226 * manufacturer name will return the same object.
228 * @param name the manufacturer name to search for.
229 * @return the Manufacturer object corresponding the name.
231 public static synchronized Manufacturer getManufacturer(String name) {
232 for (Manufacturer m : manufacturers) {
237 Manufacturer m = new Manufacturer(name.trim(), name.trim(), Motor.Type.UNKNOWN);
238 manufacturers.add(m);
245 private String generateSearchString(String str) {
246 return str.toLowerCase().replaceAll("[^a-zA-Z0-9]+", " ").trim();