1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.operation;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23
24 /***
25 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
26 * @since 0.90
27 */
28 public final class OperationFactory {
29
30 /***
31 * Prevent this class to be instanciated.
32 */
33 private OperationFactory() {
34
35 }
36
37 /***
38 * Read and return the next operation from specified inputFile
39 * <ul>
40 * Structure of InputStream : Data[size]
41 * <li>idOperation [1]</li>
42 * </ul>
43 *
44 * @param inputFile
45 * the input stream where action will be read
46 * @return the next action read into of specified inputFile
47 * @throws IOException
48 * if error occurred during the reading process from the specified
49 * input stream
50 */
51 public static Operation readNextOperation(InputStream inputFile)
52 throws IOException {
53 return getOperation(inputFile.read());
54 }
55
56 /***
57 * Read and return the correponding operation to the specified operation
58 * identifiant
59 *
60 * @param idOperation
61 * the operation identifiant
62 * @return the operation object corresponding to the specified operation
63 * identifiant
64 */
65 public static Operation getOperation(int idOperation) {
66 switch (idOperation) {
67 case IdOperations.ADD:
68 return Add.getInstance();
69 case IdOperations.ADD_ROUNDED:
70 return AddHalfRounded.getInstance();
71 case IdOperations.ADD_TRUNCATED:
72 return AddHalfTruncated.getInstance();
73 case IdOperations.AND:
74 return And.getInstance();
75 case IdOperations.AND_NOT:
76 return AndNot.getInstance();
77 case IdOperations.ANY:
78 return Any.getInstance();
79 case IdOperations.CLEAR:
80 return Clear.getInstance();
81 case IdOperations.DIV_ROUNDED:
82 return DivRounded.getInstance();
83 case IdOperations.DIV_TRUNCATED:
84 return DivTruncated.getInstance();
85 case IdOperations.INT_LIST:
86 return IntList.getInstance();
87 case IdOperations.INCREMENT:
88 return Increment.getInstance();
89 case IdOperations.DECREMENT:
90 return Decrement.getInstance();
91 case IdOperations.NEGATIVE:
92 return Negative.getInstance();
93 case IdOperations.MAX:
94 return Max.getInstance();
95 case IdOperations.MIN:
96 return Min.getInstance();
97 case IdOperations.MINUS:
98 return Remove.getInstance();
99 case IdOperations.MULT:
100 return Mult.getInstance();
101 case IdOperations.OR:
102 return Or.getInstance();
103 case IdOperations.SET:
104 return Set.getInstance();
105 case IdOperations.TARGET_LIST:
106 return TargetList.getInstance();
107 case IdOperations.XOR:
108 return Xor.getInstance();
109
110
111 case IdOperations.INT_VALUE:
112 return IntValue.getInstance();
113 case IdOperations.REGISTER_ACCESS:
114 case IdOperations.REF_VALUE:
115 case IdOperations.COUNTER:
116 case IdOperations.BIT_COUNT:
117 case IdOperations.TO_CODE:
118 case IdOperations.TO_INDEX:
119 case IdOperations.STRING_METHOD:
120 case IdOperations.OBJECT_VALUE:
121 case IdOperations.POSITION:
122 case IdOperations.LOWEST_AMONG:
123 case IdOperations.HIGHEST_AMONG:
124 case IdOperations.IF_THEN_ELSE:
125 case IdOperations.CARD_COLORS:
126 case IdOperations.CARD_TYPES:
127 case IdOperations.BASE_REGISTER_INT_VALUE:
128 case IdOperations.MANA_PAID:
129 case IdOperations.TEST_ON:
130 case IdOperations.ABSTRACT_VALUE:
131 case IdOperations.DECK_COUNTER:
132 return Dummy.getInstance();
133 default:
134 throw new InternalError("unknown idOperation :" + idOperation);
135 }
136 }
137
138 }