-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDataProvider.java
More file actions
53 lines (42 loc) · 1.64 KB
/
DataProvider.java
File metadata and controls
53 lines (42 loc) · 1.64 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
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class DataProvider {
private static final List<OrgNrData> data = new ArrayList<>();
public static void initialize() throws IOException {
InputStream in = new URL("https://raw.githubusercontent.com/organisationsnummer/meta/main/testdata/list.json").openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String json = "", line = "";
while ((line = reader.readLine()) != null) {
json = json.concat(line);
}
JSONArray rootObject = new JSONArray(json);
for (int i = 0; i < rootObject.length(); i++) {
JSONObject current = rootObject.getJSONObject(i);
data.add(new OrgNrData(
current.getString("input"),
current.getString("long_format"),
current.getString("short_format"),
current.getBoolean("valid"),
current.getString("type"),
current.getString("vat_number")
));
}
}
public static List<OrgNrData> getValid() {
return data.stream().filter(o -> o.valid).collect(Collectors.toList());
}
public static List<OrgNrData> getInvalid() {
return data.stream().filter(o -> !o.valid).collect(Collectors.toList());
}
public static List<OrgNrData> getAll() {
return data;
}
}