-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
116 lines (91 loc) · 4.01 KB
/
Main.java
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
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import constants.Role;
import pojo.Card;
import pojo.City;
import pojo.Faculty;
import pojo.Field;
import pojo.Member;
import repository.CardRepository;
import repository.CityRepository;
import repository.FacultyRepository;
import repository.FieldRepository;
import repository.MemberRepository;
import service.CardService;
import service.CardServiceImpl;
import service.CityService;
import service.CityServiceImpl;
import service.FacultyService;
import service.FacultyServiceImpl;
import service.FieldService;
import service.FieldServiceImpl;
import service.MemberService;
import service.MemberServiceImpl;
public class Main {
static Path[] paths = new Path[] { Paths.get("data/fields.txt"), Paths.get("data/faculties.txt"),
Paths.get("data/cities.txt"), Paths.get("data/members.txt"), Paths.get("data/cards.txt") };
static MemberRepository memberRepository = new MemberRepository();
static MemberService memberService = new MemberServiceImpl(memberRepository);
static FieldRepository fieldRepository = new FieldRepository();
static FieldService fieldService = new FieldServiceImpl(fieldRepository);
static FacultyRepository facultyRepository = new FacultyRepository();
static FacultyService facultyService = new FacultyServiceImpl(facultyRepository);
static CityRepository cityRepository = new CityRepository();
static CityService cityService = new CityServiceImpl(cityRepository);
static CardRepository cardRepository = new CardRepository();
static CardService cardService = new CardServiceImpl(cardRepository);
public static void main(String[] args) {
// loading our datasources with existing members
try {
loadFields();
loadFaculties();
loadCities();
loadMembers();
loadCards();
//moderator.addMember();
System.out.println();
} catch (IOException exception) {
System.out.println(exception.getMessage());
}
}
public static void loadFields() throws IOException {
Files.lines(paths[0]).forEach(line -> {
String[] words = line.split(",");
fieldService.addField(
new Field(Integer.valueOf(words[0]), words[1], words[2], words[3], Integer.valueOf(words[4])));
});
}
public static void loadFaculties() throws IOException {
Files.lines(paths[1]).forEach(line -> {
String[] words = line.split(",");
facultyService.addFaculty(new Faculty(Integer.valueOf(words[0]), words[1], words[2],
(ArrayList<Field>) fieldService.getAllFields()));
});
}
public static void loadCities() throws IOException {
Files.lines(paths[2]).forEach(line -> {
String[] words = line.split(",");
cityService.addCity(new City(Integer.valueOf(words[0]), words[1], words[2],
(ArrayList<Faculty>) facultyService.getFacultyList()));
});
}
public static void loadMembers() throws IOException {
Files.lines(paths[3]).forEach(line -> {
String[] words = line.split(",");
memberService.addMember(new Member(Integer.valueOf(words[0]), words[1], words[2], words[3], words[4],
words[5], Integer.valueOf(words[6]), Integer.valueOf(words[7]), Integer.valueOf(words[8]),
Integer.valueOf(words[9]), Integer.valueOf(words[10]), Boolean.valueOf(words[11])));
});
}
public static void loadCards() throws IOException {
Files.lines(paths[4]).forEach(line -> {
String[] words = line.split(",");
cardService.addCard(new Card(Integer.valueOf(words[0]), Integer.valueOf(words[1]), Integer.valueOf(words[2]), words[3], words[4], words[5], words[6], words[7]));
});
}
}