|
19 | 19 |
|
20 | 20 | package quickfix; |
21 | 21 |
|
22 | | -import java.util.ArrayList; |
23 | 22 | import java.util.Date; |
24 | | -import java.util.HashMap; |
25 | 23 |
|
26 | 24 | /** |
27 | 25 | * A field type enum class. |
28 | 26 | */ |
29 | | -public class FieldType { |
30 | | - private final int ordinal; |
31 | | - private final String name; |
32 | | - private final Class<?> javaType; |
33 | | - private static final HashMap<String, FieldType> values = new HashMap<String, FieldType>(); |
34 | | - private static final ArrayList<FieldType> ordinalToValue = new ArrayList<FieldType>(); |
| 27 | +public enum FieldType { |
35 | 28 |
|
36 | | - private FieldType(String name) { |
37 | | - this(name, String.class); |
38 | | - } |
| 29 | + UNKNOWN, |
| 30 | + STRING, |
| 31 | + CHAR, |
| 32 | + PRICE(Double.class), |
| 33 | + INT(Integer.class), |
| 34 | + AMT(Double.class), |
| 35 | + QTY(Double.class), |
| 36 | + CURRENCY, |
| 37 | + MULTIPLEVALUESTRING, |
| 38 | + MULTIPLESTRINGVALUE, // QFJ-881 |
| 39 | + EXCHANGE, |
| 40 | + UTCTIMESTAMP(Date.class), |
| 41 | + BOOLEAN(Boolean.class), |
| 42 | + LOCALMKTDATE, |
| 43 | + DATA, |
| 44 | + FLOAT(Double.class), |
| 45 | + PRICEOFFSET(Double.class), |
| 46 | + MONTHYEAR, |
| 47 | + DAYOFMONTH(Integer.class), |
| 48 | + UTCDATEONLY(Date.class), |
| 49 | + UTCDATE(Date.class), |
| 50 | + UTCTIMEONLY(Date.class), |
| 51 | + TIME, |
| 52 | + NUMINGROUP(Integer.class), |
| 53 | + PERCENTAGE(Double.class), |
| 54 | + SEQNUM(Integer.class), |
| 55 | + LENGTH(Integer.class), |
| 56 | + COUNTRY; |
39 | 57 |
|
40 | | - private FieldType(String name, Class<?> javaType) { |
41 | | - this.javaType = javaType; |
42 | | - this.name = name; |
43 | | - ordinal = ordinalToValue.size(); |
44 | | - ordinalToValue.add(this); |
45 | | - values.put(name, this); |
46 | | - } |
| 58 | + private final Class<?> javaType; |
47 | 59 |
|
48 | | - public String getName() { |
49 | | - return name; |
| 60 | + FieldType(Class<?> javaType) { |
| 61 | + this.javaType = javaType; |
50 | 62 | } |
51 | 63 |
|
52 | | - public int getOrdinal() { |
53 | | - return ordinal; |
| 64 | + FieldType() { |
| 65 | + this(String.class); |
54 | 66 | } |
55 | 67 |
|
56 | 68 | public Class<?> getJavaType() { |
57 | 69 | return javaType; |
58 | 70 | } |
59 | 71 |
|
60 | | - public static FieldType fromOrdinal(int ordinal) { |
61 | | - if (ordinal < 0 || ordinal >= ordinalToValue.size()) { |
62 | | - throw new RuntimeError("invalid field type ordinal: " + ordinal); |
63 | | - } |
64 | | - return ordinalToValue.get(ordinal); |
65 | | - } |
66 | | - |
67 | | - public static FieldType fromName(String fixVersion, String name) { |
68 | | - FieldType type = values.get(name); |
69 | | - return type != null ? type : FieldType.Unknown; |
70 | | - } |
71 | | - |
72 | 72 | @Override |
73 | 73 | public String toString() { |
74 | | - return getClass().getSimpleName() + "[" + getName() + "," + getJavaType() + "," + getOrdinal() + "]"; |
| 74 | + return getClass().getSimpleName() + "[" + name() + "," + javaType + "," + ordinal() + "]"; |
75 | 75 | } |
76 | 76 |
|
77 | | - public final static FieldType Unknown = new FieldType("UNKNOWN"); |
78 | | - public final static FieldType String = new FieldType("STRING"); |
79 | | - public final static FieldType Char = new FieldType("CHAR"); |
80 | | - public final static FieldType Price = new FieldType("PRICE", Double.class); |
81 | | - public final static FieldType Int = new FieldType("INT", Integer.class); |
82 | | - public final static FieldType Amt = new FieldType("AMT", Double.class); |
83 | | - public final static FieldType Qty = new FieldType("QTY", Double.class); |
84 | | - public final static FieldType Currency = new FieldType("CURRENCY"); |
85 | | - public final static FieldType MultipleValueString = new FieldType("MULTIPLEVALUESTRING"); |
86 | | - public final static FieldType MultipleStringValue = new FieldType("MULTIPLESTRINGVALUE"); // QFJ-881 |
87 | | - public final static FieldType Exchange = new FieldType("EXCHANGE"); |
88 | | - public final static FieldType UtcTimeStamp = new FieldType("UTCTIMESTAMP", Date.class); |
89 | | - public final static FieldType Boolean = new FieldType("BOOLEAN", Boolean.class); |
90 | | - public final static FieldType LocalMktDate = new FieldType("LOCALMKTDATE"); |
91 | | - public final static FieldType Data = new FieldType("DATA"); |
92 | | - public final static FieldType Float = new FieldType("FLOAT", Double.class); |
93 | | - public final static FieldType PriceOffset = new FieldType("PRICEOFFSET", Double.class); |
94 | | - public final static FieldType MonthYear = new FieldType("MONTHYEAR"); |
95 | | - public final static FieldType DayOfMonth = new FieldType("DAYOFMONTH", Integer.class); |
96 | | - public final static FieldType UtcDateOnly = new FieldType("UTCDATEONLY", Date.class); |
97 | | - public final static FieldType UtcDate = new FieldType("UTCDATE", Date.class); |
98 | | - public final static FieldType UtcTimeOnly = new FieldType("UTCTIMEONLY", Date.class); |
99 | | - public final static FieldType Time = new FieldType("TIME"); |
100 | | - public final static FieldType NumInGroup = new FieldType("NUMINGROUP", Integer.class); |
101 | | - public final static FieldType Percentage = new FieldType("PERCENTAGE", Double.class); |
102 | | - public final static FieldType SeqNum = new FieldType("SEQNUM", Integer.class); |
103 | | - public final static FieldType Length = new FieldType("LENGTH", Integer.class); |
104 | | - public final static FieldType Country = new FieldType("COUNTRY"); |
105 | | - |
| 77 | + public static FieldType fromName(String fixVersion, String name) { |
| 78 | + try { |
| 79 | + return FieldType.valueOf(name); |
| 80 | + } catch (IllegalArgumentException iae) { |
| 81 | + return UNKNOWN; |
| 82 | + } |
| 83 | + } |
106 | 84 | } |
0 commit comments