-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackEndContainer.java
More file actions
216 lines (179 loc) · 5.87 KB
/
BackEndContainer.java
File metadata and controls
216 lines (179 loc) · 5.87 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package backEnd;
import java.io.IOException;
import java.util.ArrayList;
import algorithms.TournamentAlgorithms;
import apiHandlers.YouTubeAPIHandler;
import javafx.stage.Stage;
import listDataStructure.BasicItem;
import listDataStructure.ChuseList;
import listDataStructure.RankingList;
import mediaFileImportHandling.AudioFileHandler;
import mediaFileImportHandling.ImageFileHandler;
import mediaFileImportHandling.TextFileHandler;
import xmlHandling.XMLHandler;
/**
*
* BackEndContainer is a class which contains instantiations of all the back-end elements of the program, such as
* the lists, the tournament algorithm and the methods associated with these things. This container can be distributed
* amongst all the different GUI controllers and allows for the program to follow the Model View Controller paradigm.
*
* Date created: 13/03/2019
* Date last edited: 15/03/2019
* Last edited by: Dan Jackson
*
* @author Dan Jackson
*
*/
public class BackEndContainer {
private ChuseList current_list;
//variable to hold the list as it was created - this NEVER changes for the same set of items
private ChuseList original_list;
//instantiation of the tournament comparison algorithm
private TournamentAlgorithms comparison;
//current set of results
private RankingList current_results;
//most recent set of losers
private ChuseList losers;
//boolean check as to whether it is a fresh, uncompared list or whether losers are being compared to
private Boolean comparingLosers;
/**
* Constructor function for the BackEndContainer object. Sets the current list and
* current results equal to null.
*/
public BackEndContainer() {
current_list = null;
current_results = null;
}
/**
* Method to create a new list of text items by selecting a collection of text items from
* a local file browser.
* @param stage
*/
public void loadTextFiles(Stage stage) {
current_list = new ChuseList();
original_list = new ChuseList();
ArrayList<BasicItem> text_items = TextFileHandler.openMultipleTextFiles(stage);
current_list.addItemArray(text_items);
original_list.addItemArray(text_items);
}
/**
* Method to create a new list of image items by selecting a collection of image items from
* a local file browser.
* @param stage
*/
public void loadImageFiles(Stage stage) {
current_list = new ChuseList();
original_list = new ChuseList();
ArrayList<BasicItem> image_items = ImageFileHandler.openMultipleImageFiles(stage);
current_list.addItemArray(image_items);
original_list.addItemArray(image_items);
}
/**
* Method to create a new list of audio items by selecting a collection of audio items from
* a local file browser.
* @param stage
*/
public void loadAudioFiles(Stage stage) {
current_list = new ChuseList();
original_list = new ChuseList();
ArrayList<BasicItem> audio_items = AudioFileHandler.openMultipleAudioFiles(stage);
current_list.addItemArray(audio_items);
original_list.addItemArray(audio_items);
}
/**
* Method to return the current list.
* @return current_list
*/
public ChuseList getCurrentList() {
return this.current_list;
}
/**
* Method to create a list of basic items from an array list of strings.
* @param content
*/
public void createBasicItemList(ArrayList<String> content) {
current_list = new ChuseList();
original_list = new ChuseList();
for(String item_title : content) {
current_list.addItem(new BasicItem(item_title));
original_list.addItem(new BasicItem(item_title));
}
}
/**
* Method to get the ranked results.
* @return current_results
*/
public RankingList getRankedResults() {
if(comparingLosers) {
current_results.addRankedResults(comparison.getUnrankedResults());
} else {
current_results = comparison.getRankedResults();
}
return current_results;
}
/**
* Method to get the losers from the most recent comparison.
* @return
*/
public ChuseList getLosers() {
losers = comparison.getLosers();
return this.losers;
}
/**
* Method to save the current list to an XML file.
* @param file_path
*/
public void saveCurrentListToXML(String file_path) {
// XMLHandler.buildXMLFromList(this.original_list, file_path);
// NEW
XMLHandler.buildXMLFromList(this.original_list, file_path, this.current_results);
}
public void loadXMLForComparison(String file_path) {
current_list = XMLHandler.buildListFromXML(file_path);
original_list = XMLHandler.buildListFromXML(file_path);
}
/**
* Method to create a list of YouTube video items when given a playlist URL.
* @param playlist_url
* @throws IOException
*/
public void createYouTubeList(String playlist_url) throws IOException {
current_list = YouTubeAPIHandler.getPlaylistData(playlist_url);
original_list = YouTubeAPIHandler.getPlaylistData(playlist_url);
}
/**
* Method to start a tournament comparison with the current list.
*/
public void startComparison() {
comparison = new TournamentAlgorithms(this.current_list);
}
/**
* Method to set the current list equal to the losers, ready to perform a
* tournament comparison of the losers to further define the results of a
* comparison.
*/
public void compareLosers() {
this.current_list = this.losers;
}
/**
* Method to get the tournament comparison object.
* @return
*/
public TournamentAlgorithms getComparison() {
return comparison;
}
/**
* Method to set the boolean comparing losers check.
* @param state - true/false
*/
public void setComparingLosers(Boolean state) {
this.comparingLosers = state;
}
/**
* Method to get the size of the current list.
* @return
*/
public int getCurrentListSize() {
return this.current_list.getSize();
}
}