1 package net.sf.openrocket.motor;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashSet;
7 import java.util.Locale;
11 * Class containing information about motor manufacturers.
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public class Manufacturer {
17 private static Set<Manufacturer> manufacturers = new HashSet<Manufacturer>();
20 // AeroTech has many name combinations...
21 List<String> names = new ArrayList<String>();
22 for (String s : new String[] { "A", "AT", "AERO", "AEROT", "AEROTECH" }) {
24 names.add(s + "-RMS");
25 names.add(s + "-RCS");
26 names.add("RCS-" + s);
27 names.add(s + "-APOGEE");
31 // Aerotech has single-use, reload and hybrid motors
32 manufacturers.add(new Manufacturer("AeroTech", "AeroTech", Motor.Type.UNKNOWN,
33 names.toArray(new String[0])));
35 manufacturers.add(new Manufacturer("Alpha Hybrid Rocketry LLC", "Alpha Hybrid Rocketry", Motor.Type.HYBRID,
36 "AHR", "ALPHA", "ALPHA HYBRID", "ALPHA HYBRIDS", "ALPHA HYBRIDS ROCKETRY"));
38 // TODO: HIGH: AMW/ProX - how to classify?
40 manufacturers.add(new Manufacturer("Animal Motor Works", "Animal Motor Works", Motor.Type.RELOAD,
41 "AMW", "AW", "ANIMAL"));
43 manufacturers.add(new Manufacturer("Apogee", "Apogee", Motor.Type.SINGLE,
46 manufacturers.add(new Manufacturer("Cesaroni Technology Inc.", "Cesaroni Technology", Motor.Type.RELOAD,
47 "CES", "CESARONI", "CESARONI TECHNOLOGY INCORPORATED", "CTI",
48 "CS", "CSR", "PRO38", "ABC"));
50 manufacturers.add(new Manufacturer("Contrail Rockets", "Contrail Rockets", Motor.Type.HYBRID,
51 "CR", "CONTR", "CONTRAIL", "CONTRAIL ROCKET"));
53 manufacturers.add(new Manufacturer("Estes", "Estes", Motor.Type.SINGLE,
56 // Ellis Mountain has both single-use and reload motors
57 manufacturers.add(new Manufacturer("Ellis Mountain", "Ellis Mountain", Motor.Type.UNKNOWN,
58 "EM", "ELLIS", "ELLIS MOUNTAIN ROCKET", "ELLIS MOUNTAIN ROCKETS"));
60 manufacturers.add(new Manufacturer("Gorilla Rocket Motors", "Gorilla Rocket Motors", Motor.Type.RELOAD,
61 "GR", "GORILLA", "GORILLA ROCKET", "GORILLA ROCKETS", "GORILLA MOTOR",
62 "GORILLA MOTORS", "GORILLA ROCKET MOTOR"));
64 manufacturers.add(new Manufacturer("HyperTEK", "HyperTEK", Motor.Type.HYBRID,
67 manufacturers.add(new Manufacturer("Kosdon by AeroTech", "Kosdon by AeroTech", Motor.Type.RELOAD,
68 "K", "KBA", "K-AT", "KOS", "KOSDON", "KOSDON/AT", "KOSDON/AEROTECH"));
70 manufacturers.add(new Manufacturer("Loki Research", "Loki Research", Motor.Type.RELOAD,
73 manufacturers.add(new Manufacturer("Public Missiles, Ltd.", "Public Missiles", Motor.Type.SINGLE,
74 "PM", "PML", "PUBLIC MISSILES LIMITED"));
76 manufacturers.add(new Manufacturer("Propulsion Polymers", "Propulsion Polymers", Motor.Type.HYBRID,
77 "PP", "PROP", "PROPULSION"));
79 manufacturers.add(new Manufacturer("Quest", "Quest", Motor.Type.SINGLE,
82 manufacturers.add(new Manufacturer("RATT Works", "RATT Works", Motor.Type.HYBRID,
83 "RATT", "RT", "RTW"));
85 manufacturers.add(new Manufacturer("Roadrunner Rocketry", "Roadrunner Rocketry", Motor.Type.SINGLE,
88 manufacturers.add(new Manufacturer("Rocketvision", "Rocketvision", Motor.Type.SINGLE,
89 "RV", "ROCKET VISION"));
91 manufacturers.add(new Manufacturer("Sky Ripper Systems", "Sky Ripper Systems", Motor.Type.HYBRID,
92 "SR", "SRS", "SKYR", "SKYRIPPER", "SKY RIPPER", "SKYRIPPER SYSTEMS"));
94 manufacturers.add(new Manufacturer("West Coast Hybrids", "West Coast Hybrids", Motor.Type.HYBRID,
95 "WCH", "WCR", "WEST COAST", "WEST COAST HYBRID"));
97 // German WECO Feuerwerk, previously Sachsen Feuerwerk
98 manufacturers.add(new Manufacturer("WECO Feuerwerk", "WECO Feuerwerk", Motor.Type.SINGLE,
99 "WECO", "WECO FEUERWERKS", "SF", "SACHSEN", "SACHSEN FEUERWERK",
100 "SACHSEN FEUERWERKS"));
103 // Check that no duplicates have appeared
104 for (Manufacturer m1 : manufacturers) {
105 for (Manufacturer m2 : manufacturers) {
108 for (String name : m1.getAllNames()) {
109 if (m2.matches(name)) {
110 throw new IllegalStateException("Manufacturer name clash between " +
111 "manufacturers " + m1 + " and " + m2 + " name " + name);
120 private final String displayName;
121 private final String simpleName;
122 private final Set<String> allNames;
123 private final Set<String> searchNames;
124 private final Motor.Type motorType;
127 private Manufacturer(String displayName, String simpleName, Motor.Type motorType, String... alternateNames) {
128 this.displayName = displayName;
129 this.simpleName = simpleName;
130 this.motorType = motorType;
131 if (motorType == null) {
132 throw new IllegalArgumentException("motorType cannot be null");
135 Set<String> all = new HashSet<String>();
136 Set<String> search = new HashSet<String>();
138 all.add(displayName);
140 search.add(generateSearchString(displayName));
141 search.add(generateSearchString(simpleName));
143 for (String name : alternateNames) {
145 search.add(generateSearchString(name));
148 this.allNames = Collections.unmodifiableSet(all);
149 this.searchNames = Collections.unmodifiableSet(search);
154 * Returns the display name of the manufacturer. This is the value that
155 * should be presented in the UI to the user.
157 * @return the display name
159 public String getDisplayName() {
165 * Returns the simple name of the manufacturer. This should be used for example
166 * when saving the manufacturer for compatibility.
168 * @return the simple name.
170 public String getSimpleName() {
176 * Return all names of the manufacturer. This includes all kinds of
177 * codes that correspond to the manufacturer (for example "A" for AeroTech).
179 * @return an unmodifiable set of the alternative names.
181 public Set<String> getAllNames() {
187 * Return the motor type that this manufacturer produces if it produces only one motor type.
188 * If the manufacturer manufactures multiple motor types or the type is unknown,
189 * type <code>UNKNOWN</code> is returned.
191 * @return the manufactured motor type, or <code>UNKNOWN</code>.
193 public Motor.Type getMotorType() {
199 * Check whether the display, simple or any of the alternative names matches the
200 * specified name. Matching is performed case insensitively and ignoring any
201 * non-letter and non-number characters.
203 * @param name the name to search for.
204 * @return whether this manufacturer matches the request.
206 public boolean matches(String name) {
209 return this.searchNames.contains(generateSearchString(name));
214 * Return the display name of the manufacturer.
217 public String toString() {
223 * Returns a manufacturer for the given name. The manufacturer is searched for
224 * within the manufacturers and if a match is found the corresponding
225 * object is returned. If not, a new manufacturer is returned with display and
226 * simple name the name specified. Subsequent requests for the same (or corresponding)
227 * manufacturer name will return the same object.
229 * @param name the manufacturer name to search for.
230 * @return the Manufacturer object corresponding the name.
232 public static synchronized Manufacturer getManufacturer(String name) {
233 for (Manufacturer m : manufacturers) {
238 Manufacturer m = new Manufacturer(name.trim(), name.trim(), Motor.Type.UNKNOWN);
239 manufacturers.add(m);
246 private String generateSearchString(String str) {
247 return str.toLowerCase(Locale.getDefault()).replaceAll("[^a-zA-Z0-9]+", " ").trim();