-
Notifications
You must be signed in to change notification settings - Fork 1
/
BatchInputProcessor.java
84 lines (80 loc) · 2.46 KB
/
BatchInputProcessor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Properties;
/**
* Handles batch input processing using properties file.
*/
public class BatchInputProcessor {
/**
* Run batch input using properties file.
* @param filename properties filename
*/
public static void run(String filename) {
String methodName = "";
ArrayList<String> methodParams = new ArrayList<String>();
try {
// Extract batch input from property file.
Properties props = new Properties();
FileInputStream input = new FileInputStream(filename);
props.load(input);
String value = props.getProperty("p1.batch.input");
// Parse input for method names and parameters.
String[] tokens = value.split(",");
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].charAt(0) == '#' && methodName == "") {
methodName = tokens[i];
} else if (tokens[i].charAt(0) == '#' && methodName != "") {
executeMethod(methodName, methodParams);
methodName = tokens[i];
methodParams.clear();
} else {
methodParams.add(tokens[i]);
}
}
if (methodName != "") {
executeMethod(methodName, methodParams);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Execute method with name and parameters.
* @param methodName name of method to execute
* @param methodParams list of parameters to pass to method
*/
private static void executeMethod(String methodName, ArrayList<String> methodParams) {
switch (methodName) {
case "#newCustomer":
BankingSystem.newCustomer(methodParams.get(0), methodParams.get(1), methodParams.get(2), methodParams.get(3));
break;
case "#openAccount":
BankingSystem.openAccount(methodParams.get(0), methodParams.get(1), methodParams.get(2));
break;
case "#closeAccount":
BankingSystem.closeAccount(methodParams.get(0));
break;
case "#deposit":
BankingSystem.deposit(methodParams.get(0), methodParams.get(1));
break;
case "#withdraw":
BankingSystem.withdraw(methodParams.get(0), methodParams.get(1));
break;
case "#transfer":
BankingSystem.transfer(methodParams.get(0), methodParams.get(1), methodParams.get(2));
break;
case "#accountSummary":
BankingSystem.accountSummary(methodParams.get(0));
break;
case "#reportA":
BankingSystem.reportA();
break;
case "#reportB":
BankingSystem.reportB(methodParams.get(0), methodParams.get(1));
break;
default:
System.out.println("Could not find method to execute");
break;
}
}
}