· 8 years ago · Jan 23, 2018, 01:36 AM
1package ca3;
2
3import java.util.Map;
4import java.util.TreeMap;
5import java.util.Iterator;
6import java.util.List;
7import java.util.ArrayList;
8import java.io.*;
9import java.util.logging.Level;
10import java.util.logging.Logger;
11import javazoom.jl.decoder.*;
12import javax.sound.sampled.UnsupportedAudioFileException;
13
14/**
15 * The ExeterSoundSystem will require a Manager class to manage all of the
16 * collections for objects such as MP3s, Genres, Playlists and Users. All of
17 * the necessary methods are enlisted here for the operation and management of
18 * the system.
19 *
20 * @author Team A
21 * @version March 1st 2011
22 */
23public class Manager implements ManagerInterface {
24 // private variables defined (constants and maps)
25
26 private Map userMap, mp3Map, playlistMap, genreMap;
27 private String USER_FILE, MP3_FILE, PLAYLIST_FILE, GENRE_FILE;
28 private User currentUser;
29 private MP3 importedMp3, currentMp3;
30 private long mp3ID;
31 private int volume;
32 private byte MAX_FILE_SIZE;
33 private boolean shuffle;
34
35 /**
36 * Constructor for the Manager class, requiring no arguments. This constructor
37 * calls on loadMapData() to decide about the state of it's maps.
38 */
39 public Manager() throws FileNotFoundException, IOException, ClassNotFoundException {
40 USER_FILE = "user.ser";
41 MP3_FILE = "mp3.ser";
42 PLAYLIST_FILE = "playlist.ser";
43 GENRE_FILE = "genre.ser";
44 currentUser = null;
45 currentMp3 = null;
46 importedMp3 = null;
47 shuffle = false;
48 volume = 50;
49 loadMapData();
50 }
51
52 /**
53 * Method to determine the states of the maps in the Manager class. It will
54 * either populate them with serialised map files, or create new maps.
55 */
56 public void loadMapData() throws FileNotFoundException, IOException, ClassNotFoundException {
57 try {
58 String[] filenames = {USER_FILE, MP3_FILE, PLAYLIST_FILE, GENRE_FILE};
59 Map[] maplist = new Map[4];
60 for (int i = 0; i < maplist.length; i++) {
61 ObjectInputStream o = new ObjectInputStream(new FileInputStream(filenames[i]));
62 maplist[i] = (TreeMap) o.readObject();
63 o.close();
64 }
65 userMap = maplist[0];
66 mp3Map = maplist[1];
67 playlistMap = maplist[2];
68 genreMap = maplist[3];
69 mp3ID = mp3Map.size();
70 } catch (Exception e) {
71 userMap = new TreeMap();
72 mp3Map = new TreeMap();
73 playlistMap = new TreeMap();
74 genreMap = new TreeMap();
75 mp3ID = 0;
76 }
77 }
78
79 /** Get imported mp3 method, the mp3 currently being imported (if so)
80 *
81 * @return importedMp3 the current imported mp3
82 */
83 public MP3 getImportedMp3() {
84 return importedMp3;
85 }
86
87 /** Login Method, This method is designed to allow the prospective user to log
88 * onto the system with there unique id. It takes in the username string and the
89 * password string
90 *
91 * @param username unique ID of user
92 * @param password password of user
93 */
94 public void login(String username, String password) {
95 if (isLoginValid(username, password) == true) {
96 currentUser = (User) userMap.get(username);
97 } else {
98 System.out.println("The login details you have entered are not recognised. Please"
99 + "try again.");
100 }
101 }
102
103 /** LoginCheck Method, This method is designed to check the username and password
104 * against data already in the system to ensure that the user exists.
105 *
106 * @param username unique ID of user
107 * @param password password of user
108 * @return result it is valid or it isn't
109 */
110 public boolean isLoginValid(String username, String password) {
111 if (userMap.containsKey(username)) {
112 User tempUser = (User) userMap.get(username);
113 if (tempUser.getPassword().equals(password)) {
114 return true;
115 }
116 }
117 return false;
118 }
119
120 /** Register Method, This method takes in new information for the system. This
121 * includes a username, a password and to another copy of their password for
122 * verification purposes.
123 *
124 * @param username unique ID of user
125 * @param password password of user
126 * @param passwordcheck a second entry of password for verification
127 */
128 public void register(String username, String password, String passwordCheck) {
129 if (isItemUnique(username, userMap) == true) {
130 if (doPasswordsMatch(password, passwordCheck) == true) {
131 User thisUser = new User(username, password);
132 userMap.put(username, thisUser);
133 System.out.println("Successfully registered");
134 } else {
135 System.out.println("The passwords do not match. Please try again.");
136 }
137 } else {
138 System.out.println("This username has already been taken. Please try another.");
139 }
140 }
141
142 /** This public method is called by other methods when a check is required to
143 * see if 2 user input passwords match one another.
144 *
145 * @param password password of user
146 * @param passwordCheck a second entry of password for verification
147 * @return result they match or they do not match
148 */
149 public boolean doPasswordsMatch(String password, String passwordCheck) {
150 if (password.equals(passwordCheck)) {
151 return true;
152 } else {
153 return false;
154 }
155 }
156
157 /** This public method is called by other methods when a check is required to
158 * see if an input username is unique or not.
159 *
160 * @param username unique ID of the user
161 * @return result it is unique or it isn't
162 */
163 public boolean isItemUnique(Object item, Map map) {
164 if (map.containsKey(item)) {
165 return false;
166 } else {
167 return true;
168 }
169 }
170
171 /**Modify Account Method, Modify account is used to allow the users to change
172 * their password. This method also requires that the old password is entered to
173 * verify who is modifying the account, and that the new password is entered twice
174 * to verify it's correct. This might call isLoginValid() and doPasswordsMatch()
175 *
176 * @param oldPassword the existing password of the user to be changed
177 * @param newPassword a new password the user wishes to use
178 * @param newPasswordChecker a validity checker on the new password
179 */
180 public void modifyAccount(String oldPassword, String newPassword, String newPasswordCheck) {
181 if (doPasswordsMatch(oldPassword, currentUser.getPassword()) == true) {
182 if (doPasswordsMatch(newPassword, newPasswordCheck) == true) {
183 currentUser.setPassword(newPassword);
184 System.out.println("New password accepted.");
185 } else {
186 System.out.println("New passwords did not match. Please try again.");
187 }
188 } else {
189 System.out.println("Your old password is not correct. Please try again");
190 }
191 }
192
193 /** Logout Method, A simple script to allow users to log out of the application
194 */
195 public void logout() {
196 // > CA4 Command to close main screen and return to login screen <
197 currentUser = null;
198 }
199
200 /**Previous Track Method, Used with the music controls to be able to return to the
201 * previous track in this list created by filtering the main screen.
202 *
203 * @param thisList list containing the mp3s to be played
204 * @return MP3 mp3 now selected in the list
205 */
206 public MP3 previousTrack(Map thisList) {
207 int counter = 0;
208 MP3[] tempArray = new MP3[thisList.size()];
209 Iterator iterator = thisList.entrySet().iterator();
210 while (iterator.hasNext()) {
211 MP3 tempMP3 = (MP3) iterator.next();
212 tempArray[counter] = tempMP3;
213 counter++;
214 }
215 Map thisMap = new TreeMap();
216 counter = 0;
217 for (int i = tempArray.length - 1; i > -1; i--) {
218 thisMap.put(counter, tempArray[i]);
219 }
220 return nextTrack(thisMap);
221 }
222
223 /** Next Track Method, Used with the music controls to be able to move on to the
224 * next track.
225 *
226 * @param thisList list containing the mp3s to be played
227 * @return MP3 mp3 now selected in the list
228 */
229 public MP3 nextTrack(Map thisList) {
230 MP3 tempMP3 = null;
231 Iterator iterator = thisList.entrySet().iterator();
232 while (iterator.hasNext()) {
233 tempMP3 = (MP3) iterator.next();
234 if (tempMP3.equals(currentMp3)) {
235 break;
236 }
237 }
238 if (iterator.hasNext()) {
239 currentMp3 = (MP3) iterator.next();
240 return currentMp3;
241 } else {
242 return currentMp3;
243 }
244 }
245
246 /** Play Track Method, Used with the music controls to be able to play the track
247 *
248 * @param thisList list containing the mp3s to be played
249 * @param time time in the song that it should be played at
250 */
251 public void playTrack(MP3 thisMp3) {
252 currentMp3 = thisMp3;
253 thisMp3.play();
254 // WILLLLLLL we need to pass the play function a frame to start playing at.
255 }
256
257 public void playTrack_pauser(MP3 thisMp3) {
258 currentMp3 = thisMp3;
259 thisMp3.play_from_pause();
260
261 // WILLLLLLL we need to pass the play function a frame to start playing at.
262 }
263
264 /** Stop Track Method, Used with the music controls to be able to stop the track
265 *
266 * @param thisList list containing the mp3s to be played
267 */
268 public void stopTrack(MP3 thisMp3) {
269 thisMp3.stop();
270 }
271
272 /** Pause Track Method, Used with the music controls to be able to pause the track
273 *
274 * @param thisList list containing the mp3s to be played
275 * @return time time in the song that it is paused at
276 */
277 public int pauseTrack(MP3 thisMp3) {
278 thisMp3.stop();
279 int something = currentMp3.getCurFrame();
280 // WILLLLLLL do you know how to pass the current frame here at the stop?
281 return 0;
282 }
283
284 /** Rewind Track Method Used with the music controls to be able to rewind the track
285 *
286 * @param thisList list containing the mp3s to be played
287 */
288 public void rewindTrack(MP3 thisMp3) {
289 thisMp3.rewind();
290 }
291
292 /** Fast Forward Track Method Used with the music controls to be able to fast
293 * forward the track
294 *
295 * @param thisList list containing the mp3s to be played
296 */
297 public void fastForwardTrack(MP3 thisMp3) {
298 thisMp3.fastForward();
299 }
300
301 /** Get Volume Method, This method gets the current volume level.
302 *
303 * @return volume int value to get the volume (0 - 100)
304 */
305 public int setVolume() {
306 return volume;
307 }
308
309 /** Set Volume Method, This method changes the volume using an int variable to set
310 * the level
311 *
312 * @param volume int value to set the volume (0 - 100)
313 */
314 public void setVolume(int value) {
315 volume = value;
316 }
317
318 /** Get Main Library Method, Designed to work on the click of the main libary button.
319 * Pulling all the songs into a linked list and displaying these in the main table
320 *
321 * @return mp3list list of every mp3 in the system
322 */
323 public Map getLibrary() {
324 return mp3Map;
325 }
326
327 /** Get My Imported MP3 Method, Similar to Get Main Library Method.However designed
328 * to show only the the songs that that user has imported. This can be determined by
329 * the User which is passed through the parameters
330 *
331 * @param user unique user id
332 * @return mp3list list of every mp3 user has imported
333 */
334 public Map getMyImportedMP3(User user) {
335 Map thisMap = new TreeMap();
336 Iterator iterator = mp3Map.entrySet().iterator();
337 while (iterator.hasNext()) {
338 MP3 tempMP3 = (MP3) iterator.next();
339 if (tempMP3.getUser().equals(user)) {
340 thisMap.put(tempMP3.getName(), tempMP3);
341 }
342 }
343 return thisMap;
344 }
345
346 /** Get Playlist Method, This returns all of the songs in a given playlist
347 *
348 * @param playlist playlist selected by user
349 * @return mp3list list of every mp3 in the playlist
350 */
351 public List getPlaylist(Playlist playlist) {
352 return playlist.getList();
353 }
354
355 /** Get Genre Method, This returns all of the songs in a given genre
356 *
357 * @param genre playlist selected by user
358 * @return mp3list list of every mp3 in the playlist
359 */
360 public Map getGenre(Genre genre) throws ID3v2FormatException {
361 Map thisMap = new TreeMap();
362 Iterator iterator = mp3Map.entrySet().iterator();
363 while (iterator.hasNext()) {
364 MP3 tempMP3 = (MP3) iterator.next();
365 if (tempMP3.getGenre().equals(genre)) {
366 thisMap.put(tempMP3.getName(), tempMP3);
367 }
368 }
369 return thisMap;
370 }
371
372 /** Get MP3 Stats Method, This method is used to show the current song
373 * information playing.
374 *
375 * @param mp3 mp3 currently playing
376 * @return info song info of mp3
377 */
378
379
380 /** Get Playlist List Method, Playlist list refers to the list featured on the home
381 * screen with the list of currently added playlists, not songs in the playlist
382 *
383 * @param user user owning the playlists to be displayed
384 * @return playlists all of the playlists they own
385 */
386 public Map getPlaylistList(User user) {
387 Map thisMap = new TreeMap();
388 Iterator iterator = playlistMap.entrySet().iterator();
389 while (iterator.hasNext()) {
390 Playlist tempPlaylist = (Playlist) iterator.next();
391 if (tempPlaylist.getUser().equals(user)) {
392 thisMap.put(tempPlaylist.getName(), tempPlaylist);
393 }
394 }
395 return thisMap;
396 }
397
398 /** Get Genre List Method, Genre list refers to the list featured on the home
399 * screen with the list of currently added genres, not songs in the genre
400 *
401 * @return genres all of the genres in the system
402 */
403 public Map getGenreList() {
404 return genreMap;
405 }
406
407 /** Populate Main Table Method, this method actually pastes the relevant list
408 * into the main table to be viewed. It will be called whenever it needs to be
409 * updated (ie. opening main screen, entering new search etc.)
410 *
411 * @param mp3list list of mp3s to be displayed
412 */
413 public void populateMainTable(Map thisList) {
414 Iterator iterator = thisList.entrySet().iterator();
415 while (iterator.hasNext()) {
416 MP3 tempMp3 = (MP3) iterator.next();
417 displayMP3(tempMp3);
418 }
419 }
420
421 /**Display User MP3 Method, Shows extra information about the mp3 selected
422 * in the Modify MP3 screen.
423 *
424 * @param mp3 the mp3 for the info being displayed
425 */
426 public void displayMP3(MP3 thisMp3) {
427 System.out.println(thisMp3.getName() + " | "
428 + thisMp3.getArtist() + " | "
429 + thisMp3.getAlbum() + " | "
430 + thisMp3.getGenre().getName());
431 }
432
433 /** Populate Side Tables Method, this method actually pastes the relevant list
434 * into the side tables to be viewed. It will be called whenever it needs to be
435 * updated (ie. opening main screen, adding new genre / playlist etc.)
436 * The isGenre boolean refers to whether the genre sidebar or the playlist sidebar
437 * is being populated.
438 *
439 * @param mp3list list of mp3s to be displayed
440 * @param choice either playlist or genre
441 */
442 public void populateSideTable(Map thisList, boolean isGenre) {
443 Iterator iterator = thisList.entrySet().iterator();
444 while (iterator.hasNext()) {
445 if (isGenre == true) {
446 Genre tempGenre = (Genre) iterator.next();
447 System.out.println(tempGenre.getName());
448 } else {
449 Playlist tempPlaylist = (Playlist) iterator.next();
450 System.out.println(tempPlaylist.getName());
451 }
452 }
453 }
454
455 /** Search Method, this method takes the imput from search and the selected areas
456 * designated.
457 *
458 * @param query the search info typed in by user
459 * @param titlechoice was title ticked for searching?
460 * @param artistchoice was artist ticked for searching?
461 * @param albumchoice was album ticked for searching?
462 * @param genrechoice was genre ticked for searching?
463 * @return mp3list list of mp3s to be displayed
464 */
465 public Map search(String query, boolean title, boolean artist,
466 boolean album, boolean genre) throws FileNotFoundException, NoMPEGFramesException, ID3v2FormatException, FileNotFoundException, IOException {
467 Map thisMap = new TreeMap();
468 if (isSearchEmpty(query) == true) {
469 System.out.println("No search query provided");
470 } else {
471 Iterator iterator = mp3Map.entrySet().iterator();
472 while (iterator.hasNext()) {
473 MP3 tempMP3 = (MP3) iterator.next();
474 if (title == true && tempMP3.getTitle().equals(query)) {
475 thisMap.put(tempMP3.getName(), tempMP3);
476 }
477 if (artist == true && tempMP3.getArtist().equals(query)) {
478 thisMap.put(tempMP3.getName(), tempMP3);
479 }
480 if (album == true && tempMP3.getAlbum().equals(query)) {
481 thisMap.put(tempMP3.getName(), tempMP3);
482 }
483 if (genre == true && tempMP3.getGenre().getName().equals(query)) {
484 thisMap.put(tempMP3.getName(), tempMP3);
485 }
486 }
487 }
488 return thisMap;
489 }
490
491 /** This public method is called by the search method to check whether or not the
492 * search query typed in was empty or not
493 *
494 * @param query the search info typed in by user
495 * @return result either true (empty) or false (not empty)
496 */
497 public boolean isSearchEmpty(String query) {
498 if (query.length() == 0) {
499 return true;
500 } else {
501 return false;
502 }
503 }
504
505 /** Set Shuffle Method, This method checks to see if the shuffle button has been
506 * checked
507 *
508 * @param choice shuffle is turned on or off by user
509 */
510 public void setShuffle(boolean value) {
511 shuffle = value;
512 }
513
514 /** Get Shuffle Method This method returns to the user whether or not shuffle has
515 * been enabled
516 *
517 * @return choice shuffle is turned on or off by user
518 */
519 public boolean getShuffle() {
520 return shuffle;
521 }
522
523 /** Set Clipboard Method, sets a flag on any mp3 whenever the clipboard is applied
524 * for that mp3
525 *
526 * @param choice mp3 is flagged or not flagged by user
527 * @param mp3 individual mp3 being flagged
528 */
529 public void setClipboard(boolean value, MP3 thisMp3) {
530 thisMp3.setFlag(value);
531 }
532
533 /**Import Mp3 Method, This method is used for the importing of MP3, it takes in all
534 * the information that is required through the parameters and also allows for the
535 * throwing of many exceptions in the import of the songs by public methods
536 *
537 * @param user user that is doing the import
538 * @param location location of the mp3 to be imported
539 */
540 public void importMP3(User user, String location) throws FileNotFoundException, NoMPEGFramesException, IOException, ID3v2FormatException, UnsupportedAudioFileException, IOException, JavaLayerException {
541 // Transfer the file to the central location first
542
543 // Then create the MP3 object
544 infoManager infoM = new infoManager(location);
545 Genre tempGenre;
546 MP3 newMp3;
547 if (infoM.ID3v2exist() == true) {
548 if (isItemUnique(infoM.getGenre(), genreMap) == true) {
549 tempGenre = null;
550 } else {
551 tempGenre = (Genre) genreMap.get(infoM.getGenre());
552 }
553 newMp3 = new MP3(mp3ID, location, infoM.getArtist(), infoM.getTitle(), infoM.getAlbum(), tempGenre, user);
554 } else {
555 newMp3 = new MP3(mp3ID, location, "Unknown Artist", "Unknown Title", "Unkown Album", null, user);
556 }
557 importedMp3 = newMp3;
558 mp3Map.put(mp3ID, newMp3);
559 mp3ID++;
560 }
561
562 /** Set MP3 Info Method, This method saves the change in the information of
563 * the mp3
564 *
565 * @param mp3 the mp3 for the info being saved
566 * @param title title of the mp3
567 * @param artist artist of the mp3
568 * @param album album of the mp3
569 * @param genre genre of the mp3
570 */
571 public void setMp3Info(MP3 thisMp3, String title, String artist,
572 String album, Genre genre) {
573 thisMp3.setTitle(title);
574 thisMp3.setArtist(artist);
575 thisMp3.setAlbum(album);
576 thisMp3.setGenre(genre);
577 }
578
579 /** This public method checks if the file type being uploaded is actually an mp3
580 *
581 * @param location location of the mp3 being imported
582 * @return result File type is an mp3 or it isn't
583 */
584 public boolean isFileTypeValid(String location) {
585 // WILLLLLLL do you know how to check a file's type meta data?
586
587 if (currentMp3.isMp3() == true) {
588 return true;
589
590 } else {
591 return false;
592 }
593 }
594
595 /** This public method checks if the file being uploaded is too large or not
596 *
597 * @param location location of the mp3 being imported
598 * @return result File type is too large or it isn't
599 */
600 public boolean isFileSizeValid(String location) {
601 if (currentMp3.getSizer() > 10485760 || currentMp3.getSizer() < 1024) {
602 return false;
603
604 } else {
605 return true;
606 }
607
608 }
609
610 /** Delete Genre Method, Allows a user to delete a genre from the system
611 *
612 * @param genre genre to be deleted by user
613 */
614 public void deleteGenre(Genre genre) {
615 genreMap.remove(genre.getName());
616 }
617
618 /** Get User Genre Method, This method is very similar to the getGenre() method,
619 * however this only returns the genres that the user has uploaded themselves
620 *
621 * @param user user to determine which genres to display
622 * @return genrelist list of genres that user has uploaded
623 */
624 public Map getUserGenreList(User user) {
625 Map thisMap = new TreeMap();
626 Iterator iterator = genreMap.entrySet().iterator();
627 while (iterator.hasNext()) {
628 Genre tempGenre = (Genre) iterator.next();
629 if (tempGenre.getUser().equals(user)) {
630 thisMap.put(tempGenre.getName(), tempGenre);
631 }
632 }
633 return thisMap;
634 }
635
636 /** This public method is called when the user genre list needs to be updated.
637 * For example, on loading the Modify Genre screen, or when a genre is deleted
638 *
639 * @param genrelist list of genres that user has uploaded
640 */
641 public void populateUserGenreList(Map thisList) {
642 Iterator iterator = thisList.entrySet().iterator();
643 while (iterator.hasNext()) {
644 Genre tempGenre = (Genre) iterator.next();
645 displayUserGenre(tempGenre);
646 }
647 }
648
649 /**Display User Genre Method, Shows extra information about the genre selected
650 * in the Modify Genre screen.
651 *
652 * @param genre the genre for the info being displayed
653 */
654 public void displayUserGenre(Genre genre) {
655 System.out.println(genre.getName() + " | "
656 + genre.getInfo());
657 }
658
659 /** Set Genre Info Method, This method saves the change in the information of
660 * the genre
661 *
662 * @param genre the genre for the info being saved
663 * @param name the name of the genre
664 * @param information the information of the genre
665 */
666 public void setGenreInfo(Genre genre, String name, String information) {
667 if (isItemUnique(name, genreMap) == true) {
668 genre.setName(name);
669 System.out.println("Genre name created.");
670 } else {
671 System.out.println("This genre name has already been taken. Please try another.");
672 }
673 genre.setInfo(information);
674 }
675
676 /** Delete MP3 Method, Allows a user to delete an MP3 from the system
677 *
678 * @param thisMp3 mp3 to be deleted by user
679 */
680 public void deleteMP3(MP3 thisMp3) {
681 mp3Map.remove(thisMp3.getName());
682 }
683
684 /** Get User MP3 Method, This method only returns the mp3s that the user has
685 * uploaded themselves
686 *
687 * @param user user to determine which genres to display
688 * @return mp3list list of mp3s that user has uploaded
689 */
690 public Map getUserMP3List(User user) {
691 Map thisMap = new TreeMap();
692 Iterator iterator = mp3Map.entrySet().iterator();
693 while (iterator.hasNext()) {
694 MP3 tempMP3 = (MP3) iterator.next();
695 if (tempMP3.getUser().equals(user)) {
696 thisMap.put(tempMP3.getName(), tempMP3);
697 }
698 }
699 return thisMap;
700 }
701
702 /** This public method is called when the user mp3 list needs to be updated.
703 * For example, on loading the Modify MP3 screen, or when an mp3 is deleted
704 *
705 * @param mp3list list of mp3s that user has uploaded
706 */
707 public void populateUserMP3List(Map thisList) {
708 Iterator iterator = thisList.entrySet().iterator();
709 while (iterator.hasNext()) {
710 MP3 tempMp3 = (MP3) iterator.next();
711 System.out.println(tempMp3.getTitle());
712 }
713 }
714
715 /** Delete MP3 from playlist Method, Allowing the deletion of an MP3 from a
716 * playlist. The playlists at this point (because they have been displayed)
717 * should already have been filtered to the authorised user. Therefore no
718 * user argument is required
719 *
720 * @param playlist the playlist containing the mp3s
721 * @param thisMp3 the mp3 to be deleted from the playlist
722 */
723 public void deleteMp3FromPlaylist(Playlist playlist, MP3 thisMp3) {
724 playlist.deleteMP3(thisMp3);
725 }
726
727 /** Add MP3s to Playlist Method, allowing mp3s from the clipboard to be added
728 * to the playlist. Clipboard is set by flagging mp3s on the main screen
729 *
730 * @param playlist the playlist containing the mp3s
731 * @param clipboard the list of mp3s to be added to it
732 */
733 public void addMp3sToPlaylist(Playlist playlist, Map clipboard) {
734 Map thisMap = new TreeMap();
735 Iterator iterator = mp3Map.entrySet().iterator();
736 while (iterator.hasNext()) {
737 MP3 tempMp3 = (MP3) iterator.next();
738 playlist.addMP3(tempMp3);
739 }
740 }
741
742 /** This public method is called from the above public method, to generate
743 * the clipboard LinkedList based on the MP3s that have been flagged on the
744 * main screen
745 *
746 * @return mp3list list of flagged mp3s on main screen
747 */
748 public Map generateClipboard() {
749 Map thisMap = new TreeMap();
750 Iterator iterator = mp3Map.entrySet().iterator();
751 while (iterator.hasNext()) {
752 MP3 tempMP3 = (MP3) iterator.next();
753 if (tempMP3.getFlag() == true) {
754 thisMap.put(tempMP3.getName(), tempMP3);
755 }
756 }
757 return thisMap;
758 }
759
760 /** Set Playlist Info Method, This method saves the change in the name of
761 * the playlist
762 *
763 * @param playlist the playlist for the name being saved
764 * @param name the name of the playlist
765 */
766 public void setPlaylistInfo(Playlist playlist, String name) {
767 if (isItemUnique(name, playlistMap) == true) {
768 playlist.setName(name);
769 System.out.println("Playlist name created.");
770 } else {
771 System.out.println("This playlist name has already been taken. Please try another.");
772 }
773 }
774
775 /** Delete Playlist Method, Allows a user to delete a playlist from the system
776 *
777 * @param playlist the playlist for the name being saved
778 * @param name the name of the playlist
779 */
780 public void deletePlaylist(Playlist playlist) {
781 playlistMap.remove(playlist.getName());
782 }
783
784 /** Create Playlist Method, This method creates an empty playlist
785 *
786 * @param name the name of the playlist
787 */
788 public void createPlaylist(String name) {
789 if (isItemUnique(name, playlistMap) == true) {
790 Playlist thisPlaylist = new Playlist(currentUser, name);
791 playlistMap.put(name, thisPlaylist);
792 System.out.println("Playlist created");
793 } else {
794 System.out.println("The playlist name is already in use. Please try another");
795 }
796 }
797
798 /** Create Genre Method, This method creates an empty genre
799 *
800 * @param name the name of the genre
801 */
802 public void createGenre(String name) {
803 if (isItemUnique(name, genreMap) == true) {
804 Genre thisGenre = new Genre(currentUser, name);
805 genreMap.put(name, thisGenre);
806 System.out.println("Genre created");
807 } else {
808 System.out.println("The genre name is already in use. Please try another");
809 }
810 }
811
812 public void playTrack(MP3 thisMp3, int time) {
813 throw new UnsupportedOperationException("Not supported yet.");
814 }
815}