-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGui.java
More file actions
51 lines (40 loc) · 1.43 KB
/
Gui.java
File metadata and controls
51 lines (40 loc) · 1.43 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
package gui;
import price.Price;
import market.CurrentMarketObserver;
import market.CurrentMarketSide;
import price.exceptions.InvalidPriceOperation;
import java.util.HashMap;
public class Gui implements CurrentMarketObserver {
UserDisplayManager userDisplayManager = new UserDisplayManager();
public final HashMap<String, Price> lastSales = new HashMap<>();
public Gui() {
userDisplayManager.showMarketDisplay();
}
public void shutdown() {
userDisplayManager.shutdown();
}
@Override
public void updateCurrentMarket(String symbol, CurrentMarketSide buySide, CurrentMarketSide sellSide) {
userDisplayManager.updateMarketData(
symbol, buySide.getPrice(), buySide.getVolume(),
sellSide.getPrice(), sellSide.getVolume()
);
updateTicker(symbol, Math.random() < 0.5 ? buySide.getPrice() : sellSide.getPrice());
}
private void updateTicker(String symbol, Price p) {
if (p == null) return;
Price ls = lastSales.get(symbol);
char dir = '●';
if (ls != null) {
if (p.greaterThan(ls))
dir = '▲';
else if (p.lessThan(ls))
dir = '▼';
}
lastSales.put(symbol, p);
updateTicker(symbol, p, dir);
}
public void updateTicker(String product, Price p, char direction) {
userDisplayManager.updateTicker(product, p, direction);
}
}