create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / file / rocksim / RocksimFinishCode.java
1 /*
2  * RocksimFinishCode.java
3  */
4 package net.sf.openrocket.file.rocksim;
5
6 import net.sf.openrocket.rocketcomponent.ExternalComponent;
7
8 /**
9  * Models the finish of a component.
10  */
11 public enum RocksimFinishCode {
12     POLISHED(0, ExternalComponent.Finish.POLISHED),
13     GLOSS(1, ExternalComponent.Finish.SMOOTH),
14     MATT(2, ExternalComponent.Finish.NORMAL),
15     UNFINISHED(3, ExternalComponent.Finish.UNFINISHED);
16
17     /** The Rocksim code (from XML). */
18     private final int ordinal;
19     
20     /** The corresponding OpenRocket finish. */
21     private final ExternalComponent.Finish finish;
22
23     /**
24      * Constructor.
25      * 
26      * @param idx   the Rocksim enum value
27      * @param theFinish  the OpenRocket finish
28      */
29     private RocksimFinishCode(int idx, ExternalComponent.Finish theFinish) {
30         ordinal = idx;
31         finish = theFinish;
32     }
33
34     /**
35      * Get the OpenRocket finish.
36      * 
37      * @return a Finish instance
38      */
39     public ExternalComponent.Finish asOpenRocket() {
40         return finish;
41     }
42
43     /**
44      * Lookup an instance of this enum from a Rocksim value.
45      * 
46      * @param rocksimFinishCode  the Rocksim value
47      * 
48      * @return an instance of this enum; Defaults to MATT
49      */
50     public static RocksimFinishCode fromCode(int rocksimFinishCode) {
51         RocksimFinishCode[] values = values();
52         for (RocksimFinishCode value : values) {
53             if (value.ordinal == rocksimFinishCode) {
54                 return value;
55             }
56         }
57         return MATT; //Default
58     }
59
60     /**
61      * Get the ordinal code.
62      *
63      * @param type  the OR type
64      *
65      * @return  the Rocksim XML value
66      */
67     public static int toCode(ExternalComponent.Finish type) {
68         if (type.equals(ExternalComponent.Finish.UNFINISHED)) {
69             return UNFINISHED.ordinal;
70         }
71         if (type.equals(ExternalComponent.Finish.POLISHED)) {
72             return POLISHED.ordinal;
73         }
74         if (type.equals(ExternalComponent.Finish.SMOOTH)) {
75             return GLOSS.ordinal;
76         }
77         return MATT.ordinal;
78     }
79
80 }
81