-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataLoader.java
More file actions
44 lines (33 loc) · 1.24 KB
/
DataLoader.java
File metadata and controls
44 lines (33 loc) · 1.24 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
import java.io.FileReader;
import java.util.ArrayList;
import java.util.UUID;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;;
public class DataLoader extends DataConstants{
public static ArrayList<User> getUsers() {
ArrayList<User> users = new ArrayList<User>();
try {
FileReader reader = new FileReader(USER_FILE_NAME);
JSONParser parser = new JSONParser();
JSONArray peopleJSON = (JSONArray)new JSONParser().parse(reader);
for(int i=0; i < peopleJSON.size(); i++) {
JSONObject personJSON = (JSONObject)peopleJSON.get(i);
UUID id = UUID.fromString((String)personJSON.get(USER_ID));
String userName = (String)personJSON.get(USER_USER_NAME);
String firstName = (String)personJSON.get(USER_FIRST_NAME);
String lastName = (String)personJSON.get(USER_LAST_NAME);
int age = ((Long)personJSON.get(USER_AGE)).intValue();
String phoneNumber = (String)personJSON.get(USER_PHONE_NUMBER);
users.add(new User(id, userName, firstName, lastName, age, phoneNumber));
}
return users;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static ArrayList<Item> getItems() {
return new ArrayList<Item>();
}
}