DGP - design report figure honors rotation angle of main figure; added rocksim consta...
[debian/openrocket] / core / src / net / sf / openrocket / motor / Manufacturer.java
1 package net.sf.openrocket.motor;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashSet;
6 import java.util.List;
7 import java.util.Set;
8
9 /**
10  * Class containing information about motor manufacturers.
11  * 
12  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
13  */
14 public class Manufacturer {
15         
16         private static Set<Manufacturer> manufacturers = new HashSet<Manufacturer>();
17         static {
18                 
19                 // AeroTech has many name combinations...
20                 List<String> names = new ArrayList<String>();
21                 for (String s : new String[] { "A", "AT", "AERO", "AEROT", "AEROTECH" }) {
22                         names.add(s);
23                         names.add(s + "-RMS");
24                         names.add(s + "-RCS");
25                         names.add("RCS-" + s);
26                         names.add(s + "-APOGEE");
27                 }
28                 names.add("ISP");
29                 
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])));
33                 
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"));
36                 
37                 // TODO: HIGH: AMW/ProX - how to classify?
38                 
39                 manufacturers.add(new Manufacturer("Animal Motor Works", "Animal Motor Works", Motor.Type.RELOAD,
40                                 "AMW", "AW", "ANIMAL"));
41                 
42                 manufacturers.add(new Manufacturer("Apogee", "Apogee", Motor.Type.SINGLE,
43                                 "AP", "APOG", "P"));
44                 
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"));
48                 
49                 manufacturers.add(new Manufacturer("Contrail Rockets", "Contrail Rockets", Motor.Type.HYBRID,
50                                 "CR", "CONTR", "CONTRAIL", "CONTRAIL ROCKET"));
51                 
52                 manufacturers.add(new Manufacturer("Estes", "Estes", Motor.Type.SINGLE,
53                                 "E", "ES"));
54                 
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"));
58                 
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"));
62                 
63                 manufacturers.add(new Manufacturer("HyperTEK", "HyperTEK", Motor.Type.HYBRID,
64                                 "H", "HT", "HYPER"));
65                 
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"));
68                 
69                 manufacturers.add(new Manufacturer("Loki Research", "Loki Research", Motor.Type.RELOAD,
70                                 "LOKI", "LR"));
71                 
72                 manufacturers.add(new Manufacturer("Public Missiles, Ltd.", "Public Missiles", Motor.Type.SINGLE,
73                                 "PM", "PML", "PUBLIC MISSILES LIMITED"));
74                 
75                 manufacturers.add(new Manufacturer("Propulsion Polymers", "Propulsion Polymers", Motor.Type.HYBRID,
76                                 "PP", "PROP", "PROPULSION"));
77                 
78                 manufacturers.add(new Manufacturer("Quest", "Quest", Motor.Type.SINGLE,
79                                 "Q", "QU"));
80                 
81                 manufacturers.add(new Manufacturer("RATT Works", "RATT Works", Motor.Type.HYBRID,
82                                 "RATT", "RT", "RTW"));
83                 
84                 manufacturers.add(new Manufacturer("Roadrunner Rocketry", "Roadrunner Rocketry", Motor.Type.SINGLE,
85                                 "RR", "ROADRUNNER"));
86                 
87                 manufacturers.add(new Manufacturer("Rocketvision", "Rocketvision", Motor.Type.SINGLE,
88                                 "RV", "ROCKET VISION"));
89                 
90                 manufacturers.add(new Manufacturer("Sky Ripper Systems", "Sky Ripper Systems", Motor.Type.HYBRID,
91                                 "SR", "SRS", "SKYR", "SKYRIPPER", "SKY RIPPER", "SKYRIPPER SYSTEMS"));
92                 
93                 manufacturers.add(new Manufacturer("West Coast Hybrids", "West Coast Hybrids", Motor.Type.HYBRID,
94                                 "WCH", "WCR", "WEST COAST", "WEST COAST HYBRID"));
95                 
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"));
100                 
101
102                 // Check that no duplicates have appeared
103                 for (Manufacturer m1 : manufacturers) {
104                         for (Manufacturer m2 : manufacturers) {
105                                 if (m1 == m2)
106                                         continue;
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);
111                                         }
112                                 }
113                         }
114                 }
115         }
116         
117
118
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;
124         
125         
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");
132                 }
133                 
134                 Set<String> all = new HashSet<String>();
135                 Set<String> search = new HashSet<String>();
136                 
137                 all.add(displayName);
138                 all.add(simpleName);
139                 search.add(generateSearchString(displayName));
140                 search.add(generateSearchString(simpleName));
141                 
142                 for (String name : alternateNames) {
143                         all.add(name);
144                         search.add(generateSearchString(name));
145                 }
146                 
147                 this.allNames = Collections.unmodifiableSet(all);
148                 this.searchNames = Collections.unmodifiableSet(search);
149         }
150         
151         
152         /**
153          * Returns the display name of the manufacturer.  This is the value that
154          * should be presented in the UI to the user.
155          * 
156          * @return      the display name
157          */
158         public String getDisplayName() {
159                 return displayName;
160         }
161         
162         
163         /**
164          * Returns the simple name of the manufacturer.  This should be used for example
165          * when saving the manufacturer for compatibility.
166          * 
167          * @return      the simple name.
168          */
169         public String getSimpleName() {
170                 return simpleName;
171         }
172         
173         
174         /**
175          * Return all names of the manufacturer.  This includes all kinds of
176          * codes that correspond to the manufacturer (for example "A" for AeroTech).
177          * 
178          * @return      an unmodifiable set of the alternative names.
179          */
180         public Set<String> getAllNames() {
181                 return allNames;
182         }
183         
184         
185         /**
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. 
189          * 
190          * @return      the manufactured motor type, or <code>UNKNOWN</code>.
191          */
192         public Motor.Type getMotorType() {
193                 return motorType;
194         }
195         
196         
197         /**
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.
201          * 
202          * @param name  the name to search for.
203          * @return              whether this manufacturer matches the request.
204          */
205         public boolean matches(String name) {
206                 if (name == null)
207                         return false;
208                 return this.searchNames.contains(generateSearchString(name));
209         }
210         
211         
212         /**
213          * Return the display name of the manufacturer.
214          */
215         @Override
216         public String toString() {
217                 return displayName;
218         }
219         
220         
221         /**
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.
227          * 
228          * @param name  the manufacturer name to search for.
229          * @return              the Manufacturer object corresponding the name.
230          */
231         public static synchronized Manufacturer getManufacturer(String name) {
232                 for (Manufacturer m : manufacturers) {
233                         if (m.matches(name))
234                                 return m;
235                 }
236                 
237                 Manufacturer m = new Manufacturer(name.trim(), name.trim(), Motor.Type.UNKNOWN);
238                 manufacturers.add(m);
239                 return m;
240         }
241         
242         
243
244
245         private String generateSearchString(String str) {
246                 return str.toLowerCase().replaceAll("[^a-zA-Z0-9]+", " ").trim();
247         }
248         
249 }