-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
63 lines (56 loc) · 2.09 KB
/
Copy pathClient.java
File metadata and controls
63 lines (56 loc) · 2.09 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
import java.io.*;
import java.util.*;
public class Client implements Comparable<Client> {
public String id;
public HashSet<String> currencies;
public boolean positionCheck;
public int rating;
public HashMap<Instrument, Integer> position;
public static HashMap<String, Client> clientHashMap = new HashMap<>();
public Client(String csvFilename) {
String line = "";
String splitBy = ",";
try {
BufferedReader br = new BufferedReader(new FileReader(csvFilename));
int rowCount = 0;
while ((line = br.readLine()) != null) {
if (rowCount == 0) {
rowCount++;
continue;
}
String[] l = line.split(splitBy);
String id = l[0];
HashSet<String> currencies = new HashSet<>();
for (int i = 1; i <= l.length - 3; i++) {
currencies.add(l[i].replace("\"", ""));
}
boolean positionCheck = Objects.equals(l[l.length - 2], "Y");
int rating = Integer.parseInt(l[l.length - 1]);
Client client = new Client(id, currencies, positionCheck, rating);
clientHashMap.put(id, client);
rowCount++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
public Client(String id, HashSet<String> currencies, boolean positionCheck, int rating) {
this.id = id;
this.currencies = currencies;
this.positionCheck = positionCheck;
this.rating = rating;
this.position = new HashMap<>();
}
@Override
public int compareTo(Client comparable) {
return this.rating - comparable.rating;
}
public void addInstrument(Instrument instrument, int quantity) {
if (!this.position.containsKey(instrument)) {
this.position.put(instrument, quantity);
} else {
int currQuantity = this.position.get(instrument);
this.position.put(instrument, currQuantity + quantity);
}
}
}