aboutsummaryrefslogtreecommitdiff
path: root/jMusicHub.java
blob: 8feab623727b26ff0bb02b4374fc9c38ad1e200a (plain)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
import java.util.*;
import java.io.*;
import java.text.*;
/* TO DO :
 * Printing audiobooks sorted by author
 * Generating the javadoc
 * Doing the UML Diagramm
 * Doing the report
 * Sending in the whole thing
 * */


/** <h1>jMusicHub</h1>
 *
 * The jMusicHub class is basically the app.
 * It is used to launch the whole process.
 *
 * @author  Aimeric ADJUTOR
 * @version 1.0
 * @since   2020-11-13
 * */

public class jMusicHub {

	/** <h2>addSong</h2>
	 * addSong is used to add songs thanks to the "c" option
	 * @param scan Scanner Object
	 */
	public static Song addSong(Scanner scan){
		System.out.println("Adding a song...");
		System.out.printf("Title : ");
		String title = scan.nextLine();
		System.out.printf("Duration (in seconds) : ");
		int duration = scan.nextInt();
		System.out.printf("Content path : ");
		String trash = scan.nextLine(); //Using this because the content scan is skip after a nexInt
		String content = scan.nextLine();
		System.out.printf("Artist : ");
		String artist = scan.nextLine();
		System.out.printf("Genre (JAZZ, CLASSICAL, HIPHOP, ROCK, POP, RAP) : ");
		String choosedGenre = scan.nextLine();
		choosedGenre = choosedGenre.toUpperCase();
		Genre genre = Genre.valueOf(choosedGenre);
		System.out.println("");

		System.out.println("Do you confirm the addition of the following song ?");
		System.out.println("Title : " + title);
		System.out.println("Duration : " + duration);
		System.out.println("Content path : " + content);
		System.out.println("Artist : " + artist);
		System.out.println("Genre : " + genre);
		System.out.println("[Y/n]");
		String confirm = scan.nextLine();

		if (confirm.equalsIgnoreCase("Y")){ //if the user is ok with what he typed, create a song obj
			Song newSong = new Song(title, duration, content, artist,genre);
			return newSong;
		} else {
			System.out.println("Aborting...");
			System.out.println("");
			return null;
		}
	}

/** <h2>addAudioBook</h2>
	 * addAudioBook is used to add songs thanks to the "l" option
	 * @param scan Scanner Object
	 */
	public static AudioBook addAudioBook(Scanner scan){
		System.out.println("Adding an audiobook...");
		System.out.printf("Title : ");
		String title = scan.nextLine();
		System.out.printf("Duration (in seconds) : ");
		int duration = scan.nextInt();
		System.out.printf("Content path : ");
		String trash = scan.nextLine(); //Using this because the content scan is skip after a nexInt
		String content = scan.nextLine();
		System.out.printf("Author : ");
		String author = scan.nextLine();
		System.out.printf("Language (FRENCH, ENGLISH, ITALIAN, SPANISH, GERMAN) : ");
		String choosedLanguage = scan.nextLine();
		choosedLanguage = choosedLanguage.toUpperCase();
		Language language = Language.valueOf(choosedLanguage);
		System.out.printf("Category (TEEN, NOVEL, THEATER, SPEECH, DOCUMENTARY) : ");
		String choosedCategory = scan.nextLine();
		choosedCategory = choosedCategory.toUpperCase();
		Category category = Category.valueOf(choosedCategory);
		System.out.println("");

		System.out.println("Do you confirm the addition of the following audiobook ?");
		System.out.println("Title : " + title);
		System.out.println("Duration : " + duration);
		System.out.println("Content path : " + content);
		System.out.println("Author : " + author);
		System.out.println("Language : " + language);
		System.out.println("Category : " + category);
		System.out.println("[Y/n]");
		String confirm = scan.nextLine();

		if (confirm.equalsIgnoreCase("Y")){ //if the user is ok with what he typed, create a audiobook obj
			AudioBook newAudioBook = new AudioBook(title, duration, content, author, language, category);
			return newAudioBook;
		} else {
			System.out.println("Aborting...");
			System.out.println("");
			return null;
		}
	}

/** <h2>addAlbum</h2>
	 * addAlbum is used to add albums thanks to the "a" option
	 * @param scan Scanner Object
	 */
	public static Album addAlbum(Scanner scan){
		System.out.println("\n[DISCLAIMER : You have to register the songs after creating (a) and saving (s) the albums]\n");
		System.out.println("Adding an album...");
		System.out.printf("Title : ");
		String title = scan.nextLine();
		System.out.printf("Artist : ");
		String artist = scan.nextLine();
		System.out.printf("Date (yyyy/MM/dd) : ");
		String dateString = scan.nextLine();
		DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
		try {
			Date date = df.parse(dateString);
			System.out.println("");

			System.out.println("Do you confirm the addition of the following album ?");
			System.out.println("Title : " + title);
			System.out.println("Artist : " + artist);
			System.out.println("Date of release : " + date);
			System.out.println("[Y/n]");
			String confirm = scan.nextLine();

			if (confirm.equalsIgnoreCase("Y")){ //if the user is ok with what he typed, create an album obj
				ArrayList<Song> albumSongs = new ArrayList<Song>();
				Album newAlbum = new Album(title, 0, artist, date, albumSongs);
				return newAlbum;
			} else {
				System.out.println("Aborting...");
				System.out.println("");
				return null;
			}
		} catch (ParseException e) {
			System.out.println("Aborting...");
			System.out.println("");
			return null;
		}
	}

	/** <h2>addPlaylist</h2>
	 * addPlaylist is used to add playlist thanks to the "p" option
	 * @param scan Scanner Object
	 */
	public static Playlist addPlaylist(Scanner scan, ArrayList<Song> songs, ArrayList<AudioBook> audiobooks){
		String userInput;
		System.out.println("Adding a playlist...");
		System.out.printf("Name : ");
		String name = scan.nextLine();
		ArrayList<Song> playlistSongs = new ArrayList<Song>();
		ArrayList<AudioBook> playlistAudioBooks = new ArrayList<AudioBook>();
		System.out.println("\n[You'll have to add each song or audiobook element by element]\n");

		do {
			System.out.println("What do you want to add to this playlist ?\n[(s)ong/audio(b)ook/(q)uit]\n");
			userInput = scan.nextLine();
			switch(userInput) {
				case "s" :
					listById("songs");
					System.out.printf("\nSong ID : ");
					int songId = scan.nextInt();
					String trash = scan.nextLine();
					for (Song s : songs) { //looking for the right song
						if ( songId == s.getId() ) {
							playlistSongs.add(s);
							System.out.println("\nAdding the song "+s.getTitle()+" from "+s.getArtist()+" to the playlist "+name+"\n");
						}
					}
					break;
				case "b" :
					listById("audiobooks");
					System.out.printf("\nAudioBook ID : ");
					int audiobookId = scan.nextInt();
					trash = scan.nextLine();
					for (AudioBook b : audiobooks) { //looking for the right song
						if ( audiobookId == b.getId() ) {
							playlistAudioBooks.add(b);
							System.out.println("\nAdding the audiobook "+b.getTitle()+" from "+b.getAuthor()+" to the playlist "+name+"\n");

						}
					}
					break;
				case "q" :
					System.out.println("Quitting the addition process...\n");
					break;
				default :
					System.out.println("Unknown command.");
			}

		} while(!userInput.equals("q"));

		System.out.println("Do you confirm the addition of the following playlist ?");
		System.out.println("Name : " + name);
		System.out.println("[Y/n]");
		String confirm = scan.nextLine();

		if (confirm.equalsIgnoreCase("Y")){ //if the user is ok with what he typed, create a playlist obj
			Playlist newPlaylist = new Playlist(name, playlistSongs, playlistAudioBooks);
			return newPlaylist;
		} else {
			System.out.println("Aborting...");
			System.out.println("");
			return null;
		}
	}

/**<h2>save</h2>
 * save is used by the command "s"
 * It is used to serialize (save) arrays of a list into the type's file.i
 * Exemple : save("nameOfTheFile", elements)
 * It will save the arrayList named elements into nameOfTheFile in the working directory.
 * @param filename String
 * @param elements ArrayList
 * */
	@SuppressWarnings ("rawtypes")
	public static void save(String filename, ArrayList elements){

		// Serialization
		try {

		    // Saving of object in a file
		    FileOutputStream file = new FileOutputStream(filename);
		    ObjectOutputStream out = new ObjectOutputStream(file);

		    // Method for serialization of object
		    out.writeObject(elements);

		    out.close();
		    file.close();

		    System.out.println("Your " + filename + " have been saved.");
		}
		catch (IOException ex) {
		    System.out.println("IOException is caught");
		}
	}

/**<h2>listById</h2>
 * list is called when using the "AB", "S", "A" and "P" commands in order to list the elements in respective files.
 * @param filename String
 * */

	public static void listById(String filename){

		// Deserialization
	        try {
			// Reading the object from a file
			FileInputStream file = new FileInputStream(filename);
			ObjectInputStream in = new ObjectInputStream(file);

			switch(filename) {
				case "songs":
					@SuppressWarnings("unchecked")
					ArrayList<Song> songs = (ArrayList<Song>)in.readObject();
					in.close();
					file.close();

					System.out.println("\nSaved "+filename+" :\n");

					for (Song s : songs ){
						System.out.println(s);
					}
					break;
				case "audiobooks" :
					@SuppressWarnings("unchecked")
					ArrayList<AudioBook> audiobooks = (ArrayList<AudioBook>)in.readObject();
					in.close();
					file.close();

					System.out.println("\nSaved "+filename+" :\n");

					for (AudioBook ab : audiobooks ){
						System.out.println(ab);
					}
					break;
				case "albums" :
					@SuppressWarnings("unchecked")
					ArrayList<Album> albums = (ArrayList<Album>)in.readObject();
					in.close();
					file.close();

					System.out.println("\nSaved "+filename+" :\n");

					for (Album a : albums ){
						System.out.println(a);
					}
					break;
				case "playlists" :
					@SuppressWarnings("unchecked")
					ArrayList<Playlist> playlists = (ArrayList<Playlist>)in.readObject();
					in.close();
					file.close();

					System.out.println("\nSaved "+filename+" :\n");

					for (Playlist p : playlists ){
						System.out.println(p);
					}

					break;
			}



		}
 		catch (IOException ex) {System.out.println(filename+ " file missing.");}
		catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");}
	}

	public static void listPlaylistsByName(){
		String filename = "playlists";
		try {
			// Reading the object from a file
			FileInputStream file = new FileInputStream(filename);
			ObjectInputStream in = new ObjectInputStream(file);

			@SuppressWarnings("unchecked")
			ArrayList<Playlist> playlists = (ArrayList<Playlist>)in.readObject();
			in.close();
			file.close();

			Collections.sort(playlists, Comparator.comparing(Playlist::getName));

			System.out.println("\nSaved "+filename+", sorted by name :\n");
			for (Playlist p : playlists ){
				System.out.println(p);
			}
		}
		catch (IOException ex) {System.out.println(filename+ " file missing.");}
		catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");}
	}

	public static void listAlbumsByDate(){
		String filename = "albums";
		try {
			// Reading the object from a file
			FileInputStream file = new FileInputStream(filename);
			ObjectInputStream in = new ObjectInputStream(file);

			@SuppressWarnings("unchecked")
			ArrayList<Album> albums = (ArrayList<Album>)in.readObject();
			in.close();
			file.close();

			Collections.sort(albums, Comparator.comparing(Album::getDate));

			System.out.println("\nSaved "+filename+", sorted by name :\n");
			for (Album a : albums ){
				System.out.println(a);
			}
		}
		catch (IOException ex) {System.out.println(filename+ " file missing.");}
		catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");}
	}

public static void listAlbumsByGenre(){
		String filename = "albums";
		try {
			// Reading the object from a file
			FileInputStream file = new FileInputStream(filename);
			ObjectInputStream in = new ObjectInputStream(file);

			@SuppressWarnings("unchecked")
			ArrayList<Album> albums = (ArrayList<Album>)in.readObject();
			in.close();
			file.close();

			Collections.sort(albums, Comparator.comparing(Album::getGenre));

			System.out.println("\nSaved "+filename+", sorted by name :\n");
			for (Album a : albums ){
				System.out.println(a);
			}
		}
		catch (IOException ex) {System.out.println(filename+ " file missing.");}
		catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");}
	}

/**<h2>extract</h2>
 * Extract is used to print the content of the files and put them in the ArrayList used to add elements.
 * @param String filename
 * */
	@SuppressWarnings("rawtypes")
	public static ArrayList extract(String filename){

		// Deserialization
	        try {
			FileInputStream file = new FileInputStream(filename);
			ObjectInputStream in = new ObjectInputStream(file);

			switch (filename) {
				case "songs" :
					@SuppressWarnings("unchecked")
					ArrayList<Song> songs = (ArrayList<Song>)in.readObject();

					in.close();
					file.close();

//					listById("songs");
					int songCount=0;
					for ( Song s : songs ){
					    songCount+=1;
					}
					System.out.println("Extracted songs : "+songCount);
					return new ArrayList<Song>(songs);

				case "audiobooks" :
					@SuppressWarnings("unchecked")
					ArrayList<AudioBook> audiobooks = (ArrayList<AudioBook>)in.readObject();

					in.close();
					file.close();

//					listById("audiobooks");
					int bookCount=0;
					for ( AudioBook b : audiobooks ){
					    bookCount+=1;
					}
					System.out.println("Exctracted audiobooks : "+bookCount);
					return new ArrayList<AudioBook>(audiobooks);

				case "albums" :
					@SuppressWarnings("unchecked")
					ArrayList<Album> albums = (ArrayList<Album>)in.readObject();

					in.close();
					file.close();

//					listById("albums");
					int albumCount=0;
					for ( Album a : albums ){
					    albumCount+=1;
					}
					System.out.println("Extracted albums : "+albumCount);
					return new ArrayList<Album>(albums);

				case "playlists" :
					@SuppressWarnings("unchecked")
					ArrayList<Playlist> playlists = (ArrayList<Playlist>)in.readObject();

					in.close();
					file.close();

//					listById("playlists");
					int playlistCount=0;
					for ( Playlist p : playlists ){
					    playlistCount+=1;
					}
					System.out.println("Extracted playlists : "+playlistCount);
					return new ArrayList<Playlist>(playlists);

				default :
					return new ArrayList();
			}
		}
 		catch (IOException ex) { //mainly occur bc file is missing, leading to an empty ListArray
			System.out.println("\n"+filename+" file missing.\n");
			return new ArrayList() ;}
		catch (ClassNotFoundException ex) {System.out.println("ClassNotFoundException is caught");return null;
		}
	}

	public static void addSongToAlbum(Scanner scan, ArrayList<Album> albums, ArrayList<Song> songs){
		System.out.println("Adding a existing song to an existing album...");
		listById("songs");
		System.out.printf("\nSong's ID : ");
		int songId = scan.nextInt();
		listById("albums");
		System.out.printf("\nAlbum's ID : ");
		String trash = scan.nextLine(); //Using this because the content scan is skip after a nexInt
		int albumId = scan.nextInt();
		trash = scan.nextLine();

		for (Album a : albums) { //looking for the right album
			if ( albumId == a.getId() ) {
				for ( Song s : songs ){ //as we've found the right album, we're now looking for the right song.
					if ( songId == s.getId() ){
						System.out.println("\nAdding "+s.getTitle()+" from "+s.getArtist()+" to "+a.getTitle()+"\n");
						a.addSong(s);
					}
				}
			}
		}
	}

	public static ArrayList<Playlist> delPlaylist(ArrayList<Playlist> playlists){
		Scanner scan = new Scanner(System.in);
		listById("playlists");
		System.out.println("\nWhich one do you want to delete ?");
		System.out.printf("Playlist's ID : ");
		int playlistId = scan.nextInt();
		String trash = scan.nextLine();
		for ( Playlist p : playlists ){
		    if ( playlistId == p.getId() ){
		        int index = playlists.indexOf(p);
			System.out.println("Do you confirm the removal of the following playlist ?");
			System.out.println("Id : "+p.getId()+"\nName : " + p.getName());
			System.out.println("[Y/n]");
			String confirm = scan.nextLine();
			if (confirm.equalsIgnoreCase("Y")){
				System.out.println("Removing...");
				playlists.remove(index);
			} else {
				System.out.println("Aborting...");
				System.out.println("");
			}
			break;
		    }
		}
		return playlists;
	}

	public static void contentOfPlaylist(ArrayList<Playlist> playlists){
		Scanner scan = new Scanner(System.in);
		listById("playlists");
		System.out.println("\nWhich one do you want to see ?");
		System.out.printf("Playlist's ID : ");
		int playlistId = scan.nextInt();
		String trash = scan.nextLine();
		for ( Playlist p : playlists ){
			if ( playlistId == p.getId() ){
				System.out.println("\nSongs : \n");
				p.getSongs();
				System.out.println("\nAudioBooks : \n");
				p.getAudioBooks();
		    }
		}
	}

	public static void contentOfAlbum(ArrayList<Album> albums){
		Scanner scan = new Scanner(System.in);
		listById("albums");
		System.out.println("\nWhich one do you want to see ?");
		System.out.printf("Album's ID : ");
		int albumId = scan.nextInt();
		String trash = scan.nextLine();
		for ( Album a : albums ){
			if ( albumId == a.getId() ){
				System.out.println("\nSongs : \n");
				a.getSongs();
		    }
		}
	}

	public jMusicHub() {

		System.out.println("Welcome to the jMusicHub !\n");

		Scanner scan = new Scanner(System.in);
		String userInput; //Used to get the user's inputs.

		System.out.println("Extraction beginning...\n");
		@SuppressWarnings("unchecked")
		ArrayList<Song> songs = extract("songs");
		@SuppressWarnings("unchecked")
		ArrayList<AudioBook> audiobooks = extract("audiobooks");
		@SuppressWarnings("unchecked")
		ArrayList<Album> albums = extract("albums");
		@SuppressWarnings("unchecked")
		ArrayList<Playlist> playlists = extract("playlists");

		System.out.println("\nExtraction done.");

		do {
			System.out.println("\nWhat do you want to do? [h for help]");
			userInput = scan.nextLine();
			System.out.println("");
			switch(userInput) {

				case "h" : //page help
					System.out.printf("c: add a new song\na: add a new album\n+: add an existing song to an album\nl: add a new audiobook\n\np: create a new playlist from existing songs and audiobooks\n-: delete a playlist\n\ns: save playlists, albums, songs and audiobooks into the concerned files\n\nS: List all your saved songs\nB: List all your saved audiobooks\nA: List all your saved albums\nP: List all your saved playlists\n\nPS: Print playlists sorted by their name\nPC: Print the content of a playlist\nAD: Print albums sorted by their date of release\nAG: Print albums sorted by their genre\nAC: Print the content of an album\n\nh: print this help screen\nq: quit the program\n");
					break;

				case "q" : //quit
					System.out.println("Goodbye !");
					break;

				case "c": //add a new song
					try { //If something goes wrong, abort
						Song newSong=addSong(scan);
						if (newSong != null){
							int songsSize = songs.size();
							newSong.setId(songsSize);
							songs.add(newSong);
							System.out.println("\nActual content of your list (you must save it (s) to do anything else with them) :");
							for (Song iSong : songs){
							   System.out.println(iSong);
							}
							System.out.println("");
						}
					} catch (InputMismatchException | IllegalArgumentException e) {
						System.out.println("You typed something wrong... I'm aborting..");
						System.out.println("");
					}
					break;

				case "a": //add a new album
					try { //If something goes wrong, abort
						Album newAlbum = addAlbum(scan);
						if (newAlbum != null){
							int albumsSize = albums.size();
							newAlbum.setId(albumsSize);
							albums.add(newAlbum);
							System.out.println("\nActual content of your list (you must save it (s) to do anything else with them, like adding songs) :");
							for (Album iAlbum : albums){
							   System.out.println(iAlbum);
							}
							System.out.println("");
						}
					} catch (InputMismatchException | IllegalArgumentException e) {
						System.out.println("You typed something wrong... I'm aborting..");
						System.out.println("");
					}

					break;

				case "+": //add an existing song to an album
					addSongToAlbum(scan, albums, songs);
					break;

				case "l": //add a new audiobook
					try { //If something goes wrong, abort
						AudioBook newAudioBook=addAudioBook(scan);
						if (newAudioBook != null){
							int audiobooksSize = audiobooks.size();
							newAudioBook.setId(audiobooksSize);
							audiobooks.add(newAudioBook);
							System.out.println("\nActual content of your list (you must save it (s) to do anything else with them) :");
							for (AudioBook iAudioBook : audiobooks){
							   System.out.println(iAudioBook);
							}
							System.out.println("");
						}
					} catch (InputMismatchException | IllegalArgumentException e) {
						System.out.println("You typed something wrong... I'm aborting..");
						System.out.println("");
					}
					break;

				case "p": //adding a playlist with songs and audiobooks
					try { //If something goes wrong, abort
						Playlist newPlaylist=addPlaylist(scan, songs, audiobooks);
						if (newPlaylist != null){
							int playlistsSize = playlists.size();
							if ( playlistsSize != 0){
								Playlist lastObject=playlists.get(playlistsSize-1);
								int idOfLastObject = lastObject.getId();
								newPlaylist.setId(idOfLastObject+1);
							} else {
								newPlaylist.setId(playlistsSize);
							}
							playlists.add(newPlaylist);
							System.out.println("\nActual content of your list (you must save it (s) to do anything else with them) :");
							for (Playlist iPlaylist : playlists){
							   System.out.println(iPlaylist);
							}
							System.out.println("");
						}
					} catch (InputMismatchException | IllegalArgumentException e) {
						System.out.println("You typed something wrong... I'm aborting..");
						System.out.println("");
					}
					break;

				case "-":
					try {
						playlists=delPlaylist(playlists);
						save("playlists", playlists);
					} catch (InputMismatchException | IllegalArgumentException e) {
						System.out.println("You typed something wrong... I'm aborting..");
					}
					break;
				case "s": //save songs, audiobooks, playlist and albums
					save("songs", songs);
					save("audiobooks", audiobooks);
					save("albums", albums);
					save("playlists", playlists);
					break;

				case "S": //print songs contained in songs sorted by id
					listById("songs");
					break;

				case "B": //print audiobooks containd in audiobooks sorted by id
					listById("audiobooks");
					break;

				case "A": //print albums sorted by id
					listById("albums");
					break;

				case "P": //print playlists sorted by id
					listById("playlists");
					break;
				case "PS": //print playlists sorted by their name
					listPlaylistsByName();
					break;
				case "PC": //display content of a chosen playlist
					contentOfPlaylist(playlists);
					break;
				case "AD" : // albums sorted by date
					listAlbumsByDate();
					break;
				case "AG" : //albums sorted by genre
					listAlbumsByGenre();
					break;
				case "AC": //display content of a chosen album
					contentOfAlbum(albums);
					break;
				default :
					System.out.println("Unknown command. Type h for help.");
			}
		} while(!userInput.equals("q"));
	}
	public static void main(String[] args) {
		new jMusicHub();
	}
}