-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathApplicationInterface.java
More file actions
124 lines (94 loc) · 3.19 KB
/
Copy pathApplicationInterface.java
File metadata and controls
124 lines (94 loc) · 3.19 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.application;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.enums.InputCommand;
import com.enums.SplitStrategyType;
import com.factory.interfaces.IDataStoreFactory;
import com.factory.interfaces.IStrategyListFactory;
import com.interfaces.IApplication;
import com.interfaces.IApplicationInterface;
import com.ioParser.interfaces.IInputReader;
import com.ioParser.interfaces.IResultFormatter;
import com.strategies.splitObjects.SplitResult;
import com.user.UserDetails;
// TODO: Auto-generated Javadoc
/**
* The Class ApplicationInterface.
*/
public class ApplicationInterface implements IApplicationInterface {
/** The application. */
private IApplication application;
/** The data store factory. */
private IDataStoreFactory dataStoreFactory;
/** The strategy list factory. */
private IStrategyListFactory strategyListFactory;
/** The result formatter. */
private IResultFormatter resultFormatter;
/** The input reader. */
private IInputReader inputReader;
/**
* Instantiates a new application interface.
*
* @param dataStoreFactory the data store factory
* @param strategyListFactory the strategy list factory
* @param resultFormatter the result formatter
* @param inputReader the input reader
*/
public ApplicationInterface(IDataStoreFactory dataStoreFactory, IStrategyListFactory strategyListFactory,
IResultFormatter resultFormatter, IInputReader inputReader) {
super();
this.dataStoreFactory = dataStoreFactory;
this.strategyListFactory = strategyListFactory;
this.resultFormatter = resultFormatter;
this.inputReader = inputReader;
}
/**
* Instantiate application.
*/
@Override
public void instantiateApplication() {
this.application = new Application(dataStoreFactory, strategyListFactory, Arrays.asList((String) SplitStrategyType.EQUAL.name(),(String) SplitStrategyType.EXACT.name(), (String)SplitStrategyType.PERCENT.name()));
}
/**
* Run input string.
*
* @param input the input
* @return the list
*/
@Override
public List<String> runInputString(String input) {
String[] inputArr = input.split(" ");
List<String> inputList = new ArrayList<String>();
int i = 1;
while (i < inputArr.length) {
inputList.add(inputArr[i]);
i++;
}
if (InputCommand.EXPENSE == InputCommand.valueOf(inputArr[0])) {
this.application.addExpense(this.inputReader.parseInput(inputList));
return Arrays.asList();
}
if (InputCommand.SHOW == InputCommand.valueOf(inputArr[0])) {
SplitResult splitResult;
if (inputList.size() == 0) {
splitResult = this.application.getAllBalances();
} else {
splitResult = this.application.getBalanceForUser(inputList.get(0));
}
// System.out.println("result" + splitResult.getOwedBy() + " " + splitResult.getOwedTo());
return this.resultFormatter.getFormattedResult(splitResult, this.dataStoreFactory.getUserDataStore());
}
return new ArrayList<String>();
}
/**
* Adds the new user.
*
* @param userDetails the user details
* @return true, if successful
*/
@Override
public boolean addNewUser(UserDetails userDetails) {
return this.dataStoreFactory.getUserDataStore().addNewUser(userDetails);
}
}