From 49196ae84aea338dbc6cd10f4d135e4b717cdd1f Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 28 Jun 2021 23:38:36 +0200 Subject: Latest package, javadoc and jacoco --- .../jacoco/musichub.business/AudioElement.html | 2 +- .../musichub.business/AudioElement.java.html | 162 +++---- target/site/jacoco/musichub.business/MusicHub.html | 2 +- .../jacoco/musichub.business/MusicHub.java.html | 482 +++++++++++---------- .../jacoco/musichub.business/SortByAuthor.html | 2 +- .../site/jacoco/musichub.business/SortByDate.html | 2 +- .../site/jacoco/musichub.business/SortByGenre.html | 2 +- target/site/jacoco/musichub.business/index.html | 2 +- .../jacoco/musichub.business/index.source.html | 2 +- 9 files changed, 350 insertions(+), 308 deletions(-) (limited to 'target/site/jacoco/musichub.business') diff --git a/target/site/jacoco/musichub.business/AudioElement.html b/target/site/jacoco/musichub.business/AudioElement.html index 18f7368..6498736 100644 --- a/target/site/jacoco/musichub.business/AudioElement.html +++ b/target/site/jacoco/musichub.business/AudioElement.html @@ -1 +1 @@ -AudioElement

AudioElement

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total85 of 26668 %9 of 1118 %1116307249
manageAudioElement()680 %70 %66242411
AudioElement(Element)85587 %2250 %2331401
getUUID()30 %n/a111111
getArtist()30 %n/a111111
getTitle()30 %n/a111111
createXMLElement(Document, Element)79100 %n/a0101601
AudioElement(String, String, int, String, String)19100 %n/a010701
AudioElement(String, String, int, String)18100 %n/a010701
toString()10100 %n/a010101
\ No newline at end of file +AudioElement

AudioElement

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total91 of 27266 %8 of 1020 %1015317349
manageAudioElement()740 %60 %55252511
AudioElement(Element)85587 %2250 %2331401
getUUID()30 %n/a111111
getArtist()30 %n/a111111
getTitle()30 %n/a111111
createXMLElement(Document, Element)79100 %n/a0101601
AudioElement(String, String, int, String, String)19100 %n/a010701
AudioElement(String, String, int, String)18100 %n/a010701
toString()10100 %n/a010101
\ No newline at end of file diff --git a/target/site/jacoco/musichub.business/AudioElement.java.html b/target/site/jacoco/musichub.business/AudioElement.java.html index 7863e1a..34bbc3b 100644 --- a/target/site/jacoco/musichub.business/AudioElement.java.html +++ b/target/site/jacoco/musichub.business/AudioElement.java.html @@ -1,19 +1,15 @@ AudioElement.java

AudioElement.java

package musichub.business;
 
+import musichub.util.LogHandler;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import javax.sound.sampled.*;
 import java.io.File;
 import java.io.IOException;
 import java.util.Scanner;
 import java.util.UUID;
 
-import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.Clip;
-import javax.sound.sampled.LineUnavailableException;
-import javax.sound.sampled.UnsupportedAudioFileException;
-
 public abstract class AudioElement {
     protected String title;
     protected String artist;
@@ -21,109 +17,113 @@ public abstract class AudioElement {
     protected UUID uuid;
     protected String content;
 
-    public AudioElement(String title, String artist, int lengthInSeconds, String id, String content) {
-        this.title = title;
-        this.artist = artist;
-        this.lengthInSeconds = lengthInSeconds;
-        this.uuid = UUID.fromString(id);
-        this.content = content;
-    }
-
-    public AudioElement(String title, String artist, int lengthInSeconds, String content) {
-        this.title = title;
-        this.artist = artist;
-        this.lengthInSeconds = lengthInSeconds;
-        this.content = content;
-        this.uuid = UUID.randomUUID();
-    }
-
-    public AudioElement(Element xmlElement) {
+    public AudioElement(String title, String artist, int lengthInSeconds, String id, String content) {
+        this.title = title;
+        this.artist = artist;
+        this.lengthInSeconds = lengthInSeconds;
+        this.uuid = UUID.fromString(id);
+        this.content = content;
+    }
+
+    public AudioElement(String title, String artist, int lengthInSeconds, String content) {
+        this.title = title;
+        this.artist = artist;
+        this.lengthInSeconds = lengthInSeconds;
+        this.content = content;
+        this.uuid = UUID.randomUUID();
+    }
+
+    public AudioElement(Element xmlElement) {
         {
-            title = xmlElement.getElementsByTagName("title").item(0).getTextContent();
-            artist = xmlElement.getElementsByTagName("artist").item(0).getTextContent();
-            lengthInSeconds = Integer.parseInt(xmlElement.getElementsByTagName("length").item(0).getTextContent());
-            content = xmlElement.getElementsByTagName("content").item(0).getTextContent();
-            String uuid = null;
+            title = xmlElement.getElementsByTagName("title").item(0).getTextContent();
+            artist = xmlElement.getElementsByTagName("artist").item(0).getTextContent();
+            lengthInSeconds = Integer.parseInt(xmlElement.getElementsByTagName("length").item(0).getTextContent());
+            content = xmlElement.getElementsByTagName("content").item(0).getTextContent();
+            String uuid = null;
             try {
-                uuid = xmlElement.getElementsByTagName("UUID").item(0).getTextContent();
-            } catch (Exception ex) {
-                System.out.println("Empty element UUID, will create a new one");
-            }
-            if ((uuid == null) || (uuid.isEmpty()))
-                this.uuid = UUID.randomUUID();
-            else this.uuid = UUID.fromString(uuid);
+                uuid = xmlElement.getElementsByTagName("UUID").item(0).getTextContent();
+            } catch (Exception ex) {
+                System.out.println("Empty element UUID, will create a new one");
+            }
+            if ((uuid == null) || (uuid.isEmpty()))
+                this.uuid = UUID.randomUUID();
+            else this.uuid = UUID.fromString(uuid);
         }
-    }
+    }
 
     public UUID getUUID() {
-        return this.uuid;
+        return this.uuid;
     }
 
     public String getArtist() {
-        return this.artist;
+        return this.artist;
     }
 
     public String getTitle() {
-        return this.title;
+        return this.title;
     }
 
     public String toString() {
-        return "Title = " + this.title + ", Artist = " + this.artist + ", Length = " + this.lengthInSeconds + ", Content = " + this.content;
+        return "Title = " + this.title + ", Artist = " + this.artist + ", Length = " + this.lengthInSeconds + ", Content = " + this.content;
     }
 
     public void createXMLElement(Document document, Element parentElement) {
-        Element nameElement = document.createElement("title");
-        nameElement.appendChild(document.createTextNode(title));
-        parentElement.appendChild(nameElement);
+        Element nameElement = document.createElement("title");
+        nameElement.appendChild(document.createTextNode(title));
+        parentElement.appendChild(nameElement);
 
-        Element artistElement = document.createElement("artist");
-        artistElement.appendChild(document.createTextNode(artist));
-        parentElement.appendChild(artistElement);
+        Element artistElement = document.createElement("artist");
+        artistElement.appendChild(document.createTextNode(artist));
+        parentElement.appendChild(artistElement);
 
-        Element lengthElement = document.createElement("length");
-        lengthElement.appendChild(document.createTextNode(Integer.valueOf(lengthInSeconds).toString()));
-        parentElement.appendChild(lengthElement);
+        Element lengthElement = document.createElement("length");
+        lengthElement.appendChild(document.createTextNode(Integer.valueOf(lengthInSeconds).toString()));
+        parentElement.appendChild(lengthElement);
 
-        Element UUIDElement = document.createElement("UUID");
-        UUIDElement.appendChild(document.createTextNode(uuid.toString()));
-        parentElement.appendChild(UUIDElement);
+        Element UUIDElement = document.createElement("UUID");
+        UUIDElement.appendChild(document.createTextNode(uuid.toString()));
+        parentElement.appendChild(UUIDElement);
 
-        Element contentElement = document.createElement("content");
-        contentElement.appendChild(document.createTextNode(content));
-        parentElement.appendChild(contentElement);
+        Element contentElement = document.createElement("content");
+        contentElement.appendChild(document.createTextNode(content));
+        parentElement.appendChild(contentElement);
 
-    }
+    }
     
     public void manageAudioElement() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
     	
-    	Scanner scanner = new Scanner(System.in); 
+    	Scanner scanner = new Scanner(System.in); 
     	
-    	File file = new File(this.content);
-    	AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
-    	Clip clip = AudioSystem.getClip();
-    	clip.open(audioStream);
+    	File file = new File(this.content);
+    	AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
+    	Clip clip = AudioSystem.getClip();
+    	clip.open(audioStream);
     	
-    	String action = "";
+    	String action = "";
     			
-    	while(!action.equals("Q")) {
-    		System.out.println("P = Play \b S = Stop \b R = Reset \b Q = Quit");
-    		System.out.println("Enter your choice");
-    		action = scanner.next();
-        	action = action.toUpperCase();
-        	
-        	switch(action) {
-        		case "S" : clip.stop();
-        		break;
-        		case "P" : clip.start();
-        		break;
-        		case "R" : clip.setMicrosecondPosition(0);
-        		break;
-        		case "Q" : clip.stop();
-        		break;
-        		default : System.out.println("try again");
-        	}
-        	System.out.println("You stoped the Audio element");
-    	}
+    	while(!action.equals("Q")) {
+            System.out.println("P = Play \b S = Stop \b R = Reset \b Q = Quit");
+            System.out.println("Enter your choice");
+            action = scanner.next();
+            action = action.toUpperCase();
+
+            switch (action) {
+                case "S", "Q" -> {
+                    clip.stop();
+                    LogHandler.write("Music stopped", "INFO");
+                }
+                case "P" -> {
+                    clip.start();
+                    LogHandler.write("Music started", "INFO");
+                }
+                case "R" -> {
+                    clip.setMicrosecondPosition(0);
+                    LogHandler.write("Music reseted", "INFO");
+                }
+                default -> System.out.println("try again");
+            }
+            System.out.println("You stopped the Audio element");
+        }
     	
     	clip.close();
     
diff --git a/target/site/jacoco/musichub.business/MusicHub.html b/target/site/jacoco/musichub.business/MusicHub.html
index 4ed5db0..43c8490 100644
--- a/target/site/jacoco/musichub.business/MusicHub.html
+++ b/target/site/jacoco/musichub.business/MusicHub.html
@@ -1 +1 @@
-MusicHub

MusicHub

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total874 of 8740 %124 of 1240 %85852092092323
addElementToAlbum(String, String)820 %120 %77202011
addElementToPlayList(String, String)820 %120 %77202011
getAlbumSongsSortedByGenre(String)790 %140 %88161611
getAlbumSongs(String)730 %140 %88151511
searchAudioElement()710 %100 %66141411
loadElements()640 %100 %66181811
getAudiobooksTitlesSortedByAuthor()530 %60 %449911
saveElements()470 %80 %55121211
loadAlbums()440 %80 %55111111
loadPlaylists()440 %80 %55111111
deletePlayList(String)400 %80 %55111111
saveAlbums()360 %40 %33101011
savePlayLists()360 %40 %33101011
getAlbumsTitlesSortedByDate()320 %20 %225511
MusicHub()290 %n/a119911
getAudioElement(List, String)190 %40 %335511
static {...}130 %n/a114411
addElement(AudioElement)60 %n/a112211
addAlbum(Album)60 %n/a112211
addPlaylist(PlayList)60 %n/a112211
albums()40 %n/a111111
playlists()40 %n/a111111
elements()40 %n/a111111
\ No newline at end of file +MusicHub

MusicHub

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total973 of 9730 %140 of 1400 %95952282282525
addElementToAlbum(String, String)820 %120 %77202011
addElementToPlayList(String, String)820 %120 %77202011
getAlbumSongsSortedByGenre(String)790 %140 %88161611
getAlbumSongs(String)730 %140 %88151511
getPlayListSongs(String)730 %140 %88151511
searchAudioElement()710 %100 %66141411
loadElements()640 %100 %66181811
getAudiobooksTitlesSortedByAuthor()530 %60 %449911
saveElements()470 %80 %55121211
loadAlbums()440 %80 %55111111
loadPlaylists()440 %80 %55111111
deletePlayList(String)400 %80 %55111111
saveAlbums()360 %40 %33101011
savePlayLists()360 %40 %33101011
getAlbumsTitlesSortedByDate()320 %20 %225511
MusicHub()290 %n/a119911
getPlayListsTitles()260 %20 %224411
getAudioElement(List, String)190 %40 %335511
static {...}130 %n/a114411
addElement(AudioElement)60 %n/a112211
addAlbum(Album)60 %n/a112211
addPlaylist(PlayList)60 %n/a112211
albums()40 %n/a111111
playlists()40 %n/a111111
elements()40 %n/a111111
\ No newline at end of file diff --git a/target/site/jacoco/musichub.business/MusicHub.java.html b/target/site/jacoco/musichub.business/MusicHub.java.html index ec5e661..deb88a0 100644 --- a/target/site/jacoco/musichub.business/MusicHub.java.html +++ b/target/site/jacoco/musichub.business/MusicHub.java.html @@ -6,359 +6,401 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.io.IOException; -import java.util.*; - import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; +import java.io.IOException; +import java.util.*; -class SortByDate implements Comparator<Album> { +class SortByDate implements Comparator<Album> { public int compare(Album a1, Album a2) { - return a1.getDate().compareTo(a2.getDate()); + return a1.getDate().compareTo(a2.getDate()); } } -class SortByGenre implements Comparator<Song> { +class SortByGenre implements Comparator<Song> { public int compare(Song s1, Song s2) { - return s1.getGenre().compareTo(s2.getGenre()); + return s1.getGenre().compareTo(s2.getGenre()); } } -class SortByAuthor implements Comparator<AudioElement> { +class SortByAuthor implements Comparator<AudioElement> { public int compare(AudioElement e1, AudioElement e2) { - return e1.getArtist().compareTo(e2.getArtist()); + return e1.getArtist().compareTo(e2.getArtist()); } } public class MusicHub { - public static final String DIR = System.getProperty("user.dir"); - public static final String ALBUMS_FILE_PATH = DIR + "/files/albums.xml"; - public static final String PLAYLISTS_FILE_PATH = DIR + "/files/playlists.xml"; - public static final String ELEMENTS_FILE_PATH = DIR + "/files/elements.xml"; + public static final String DIR = System.getProperty("user.dir"); + public static final String ALBUMS_FILE_PATH = DIR + "/files/albums.xml"; + public static final String PLAYLISTS_FILE_PATH = DIR + "/files/playlists.xml"; + public static final String ELEMENTS_FILE_PATH = DIR + "/files/elements.xml"; private final List<Album> albums; private final List<PlayList> playlists; private final List<AudioElement> elements; - private final XMLHandler xmlHandler = new XMLHandler(); + private final XMLHandler xmlHandler = new XMLHandler(); - public MusicHub() { - albums = new LinkedList<>(); - playlists = new LinkedList<>(); - elements = new LinkedList<>(); - this.loadElements(); - this.loadAlbums(); - this.loadPlaylists(); - } + public MusicHub() { + albums = new LinkedList<>(); + playlists = new LinkedList<>(); + elements = new LinkedList<>(); + this.loadElements(); + this.loadAlbums(); + this.loadPlaylists(); + } public void addElement(AudioElement element) { - elements.add(element); - } + elements.add(element); + } public void addAlbum(Album album) { - albums.add(album); - } + albums.add(album); + } public void addPlaylist(PlayList playlist) { - playlists.add(playlist); - } + playlists.add(playlist); + } public void deletePlayList(String playListTitle) throws NoPlayListFoundException { - PlayList thePlayList = null; - boolean result = false; - for (PlayList pl : playlists) { - if (pl.getTitle().equalsIgnoreCase(playListTitle)) { - thePlayList = pl; - break; + PlayList thePlayList = null; + boolean result = false; + for (PlayList pl : playlists) { + if (pl.getTitle().equalsIgnoreCase(playListTitle)) { + thePlayList = pl; + break; } - } + } - if (thePlayList != null) - result = playlists.remove(thePlayList); - if (!result) throw new NoPlayListFoundException("Playlist " + playListTitle + " not found!"); - } + if (thePlayList != null) + result = playlists.remove(thePlayList); + if (!result) throw new NoPlayListFoundException("Playlist " + playListTitle + " not found!"); + } public Iterator<Album> albums() { - return albums.listIterator(); + return albums.listIterator(); } public Iterator<PlayList> playlists() { - return playlists.listIterator(); + return playlists.listIterator(); } public Iterator<AudioElement> elements() { - return elements.listIterator(); + return elements.listIterator(); } public String getAlbumsTitlesSortedByDate() { - StringBuilder titleList = new StringBuilder(); - albums.sort(new SortByDate()); - for (Album al : albums) - titleList.append(al.getTitle()).append("\n"); - return titleList.toString(); + StringBuilder titleList = new StringBuilder(); + albums.sort(new SortByDate()); + for (Album al : albums) + titleList.append(al.getTitle()).append("\n"); + return titleList.toString(); } public String getAudiobooksTitlesSortedByAuthor() { - StringBuilder titleList = new StringBuilder(); - List<AudioElement> audioBookList = new ArrayList<>(); - for (AudioElement ae : elements) - if (ae instanceof AudioBook) - audioBookList.add(ae); - audioBookList.sort(new SortByAuthor()); - for (AudioElement ab : audioBookList) - titleList.append(ab.getArtist()).append("\n"); - return titleList.toString(); + StringBuilder titleList = new StringBuilder(); + List<AudioElement> audioBookList = new ArrayList<>(); + for (AudioElement ae : elements) + if (ae instanceof AudioBook) + audioBookList.add(ae); + audioBookList.sort(new SortByAuthor()); + for (AudioElement ab : audioBookList) + titleList.append(ab.getArtist()).append("\n"); + return titleList.toString(); } public List<AudioElement> getAlbumSongs(String albumTitle) throws NoAlbumFoundException { - Album theAlbum = null; - ArrayList<AudioElement> songsInAlbum = new ArrayList<>(); - for (Album al : albums) { - if (al.getTitle().equalsIgnoreCase(albumTitle)) { - theAlbum = al; - break; + Album theAlbum = null; + ArrayList<AudioElement> songsInAlbum = new ArrayList<>(); + for (Album al : albums) { + if (al.getTitle().equalsIgnoreCase(albumTitle)) { + theAlbum = al; + break; } - } - if (theAlbum == null) throw new NoAlbumFoundException("No album with this title in the MusicHub!"); - - List<UUID> songIDs = theAlbum.getSongs(); - for (UUID id : songIDs) - for (AudioElement el : elements) { - if (el instanceof Song) { - if (el.getUUID().equals(id)) songsInAlbum.add(el); + } + if (theAlbum == null) throw new NoAlbumFoundException("No album with this title in the MusicHub!"); + + List<UUID> songIDs = theAlbum.getSongs(); + for (UUID id : songIDs) + for (AudioElement el : elements) { + if (el instanceof Song) { + if (el.getUUID().equals(id)) songsInAlbum.add(el); } - } - return songsInAlbum; + } + return songsInAlbum; } public List<Song> getAlbumSongsSortedByGenre(String albumTitle) throws NoAlbumFoundException { - Album theAlbum = null; - ArrayList<Song> songsInAlbum = new ArrayList<>(); - for (Album al : albums) { - if (al.getTitle().equalsIgnoreCase(albumTitle)) { - theAlbum = al; - break; + Album theAlbum = null; + ArrayList<Song> songsInAlbum = new ArrayList<>(); + for (Album al : albums) { + if (al.getTitle().equalsIgnoreCase(albumTitle)) { + theAlbum = al; + break; } - } - if (theAlbum == null) throw new NoAlbumFoundException("No album with this title in the MusicHub!"); - - List<UUID> songIDs = theAlbum.getSongs(); - for (UUID id : songIDs) - for (AudioElement el : elements) { - if (el instanceof Song) { - if (el.getUUID().equals(id)) songsInAlbum.add((Song) el); + } + if (theAlbum == null) throw new NoAlbumFoundException("No album with this title in the MusicHub!"); + + List<UUID> songIDs = theAlbum.getSongs(); + for (UUID id : songIDs) + for (AudioElement el : elements) { + if (el instanceof Song) { + if (el.getUUID().equals(id)) songsInAlbum.add((Song) el); } - } - songsInAlbum.sort(new SortByGenre()); - return songsInAlbum; + } + songsInAlbum.sort(new SortByGenre()); + return songsInAlbum; } public void addElementToAlbum(String elementTitle, String albumTitle) throws NoAlbumFoundException, NoElementFoundException { - Album theAlbum = null; + Album theAlbum = null; int i; - boolean found = false; - for (i = 0; i < albums.size(); i++) { - if (albums.get(i).getTitle().equalsIgnoreCase(albumTitle)) { - theAlbum = albums.get(i); - found = true; - break; + boolean found = false; + for (i = 0; i < albums.size(); i++) { + if (albums.get(i).getTitle().equalsIgnoreCase(albumTitle)) { + theAlbum = albums.get(i); + found = true; + break; } } - if (found) { - AudioElement theElement = null; - for (AudioElement ae : elements) { - if (ae.getTitle().equalsIgnoreCase(elementTitle)) { - theElement = ae; - break; + if (found) { + AudioElement theElement = null; + for (AudioElement ae : elements) { + if (ae.getTitle().equalsIgnoreCase(elementTitle)) { + theElement = ae; + break; } - } - if (theElement != null) { - theAlbum.addSong(theElement.getUUID()); + } + if (theElement != null) { + theAlbum.addSong(theElement.getUUID()); //replace the album in the list - albums.set(i, theAlbum); - } else throw new NoElementFoundException("Element " + elementTitle + " not found!"); - } else throw new NoAlbumFoundException("Album " + albumTitle + " not found!"); + albums.set(i, theAlbum); + } else throw new NoElementFoundException("Element " + elementTitle + " not found!"); + } else throw new NoAlbumFoundException("Album " + albumTitle + " not found!"); - } + } public void addElementToPlayList(String elementTitle, String playListTitle) throws NoPlayListFoundException, NoElementFoundException { - PlayList thePlaylist = null; + PlayList thePlaylist = null; int i; - boolean found = false; + boolean found = false; - for (i = 0; i < playlists.size(); i++) { - if (playlists.get(i).getTitle().equalsIgnoreCase(playListTitle)) { - thePlaylist = playlists.get(i); - found = true; - break; + for (i = 0; i < playlists.size(); i++) { + if (playlists.get(i).getTitle().equalsIgnoreCase(playListTitle)) { + thePlaylist = playlists.get(i); + found = true; + break; } } - if (found) { - AudioElement theElement = null; - for (AudioElement ae : elements) { - if (ae.getTitle().equalsIgnoreCase(elementTitle)) { - theElement = ae; - break; + if (found) { + AudioElement theElement = null; + for (AudioElement ae : elements) { + if (ae.getTitle().equalsIgnoreCase(elementTitle)) { + theElement = ae; + break; } - } - if (theElement != null) { - thePlaylist.addElement(theElement.getUUID()); + } + if (theElement != null) { + thePlaylist.addElement(theElement.getUUID()); //replace the album in the list - playlists.set(i, thePlaylist); - } else throw new NoElementFoundException("Element " + elementTitle + " not found!"); + playlists.set(i, thePlaylist); + } else throw new NoElementFoundException("Element " + elementTitle + " not found!"); - } else throw new NoPlayListFoundException("Playlist " + playListTitle + " not found!"); + } else throw new NoPlayListFoundException("Playlist " + playListTitle + " not found!"); - } + } private void loadAlbums() { - NodeList albumNodes = xmlHandler.parseXMLFile(ALBUMS_FILE_PATH); - if (albumNodes == null) return; + NodeList albumNodes = xmlHandler.parseXMLFile(ALBUMS_FILE_PATH); + if (albumNodes == null) return; - for (int i = 0; i < albumNodes.getLength(); i++) { - if (albumNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element albumElement = (Element) albumNodes.item(i); - if (albumElement.getNodeName().equals("album")) { + for (int i = 0; i < albumNodes.getLength(); i++) { + if (albumNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { + Element albumElement = (Element) albumNodes.item(i); + if (albumElement.getNodeName().equals("album")) { try { - this.addAlbum(new Album(albumElement)); - } catch (Exception ex) { - System.out.println("Something is wrong with the XML album element"); - } + this.addAlbum(new Album(albumElement)); + } catch (Exception ex) { + System.out.println("Something is wrong with the XML album element"); + } } } } - } + } private void loadPlaylists() { - NodeList playlistNodes = xmlHandler.parseXMLFile(PLAYLISTS_FILE_PATH); - if (playlistNodes == null) return; + NodeList playlistNodes = xmlHandler.parseXMLFile(PLAYLISTS_FILE_PATH); + if (playlistNodes == null) return; - for (int i = 0; i < playlistNodes.getLength(); i++) { - if (playlistNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element playlistElement = (Element) playlistNodes.item(i); - if (playlistElement.getNodeName().equals("playlist")) { + for (int i = 0; i < playlistNodes.getLength(); i++) { + if (playlistNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { + Element playlistElement = (Element) playlistNodes.item(i); + if (playlistElement.getNodeName().equals("playlist")) { try { - this.addPlaylist(new PlayList(playlistElement)); - } catch (Exception ex) { - System.out.println("Something is wrong with the XML playlist element"); - } + this.addPlaylist(new PlayList(playlistElement)); + } catch (Exception ex) { + System.out.println("Something is wrong with the XML playlist element"); + } } } } - } + } private void loadElements() { - NodeList audioelementsNodes = xmlHandler.parseXMLFile(ELEMENTS_FILE_PATH); - if (audioelementsNodes == null) return; + NodeList audioelementsNodes = xmlHandler.parseXMLFile(ELEMENTS_FILE_PATH); + if (audioelementsNodes == null) return; - for (int i = 0; i < audioelementsNodes.getLength(); i++) { - if (audioelementsNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element audioElement = (Element) audioelementsNodes.item(i); - if (audioElement.getNodeName().equals("song")) { + for (int i = 0; i < audioelementsNodes.getLength(); i++) { + if (audioelementsNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { + Element audioElement = (Element) audioelementsNodes.item(i); + if (audioElement.getNodeName().equals("song")) { try { - AudioElement newSong = new Song(audioElement); - this.addElement(newSong); - } catch (Exception ex) { - System.out.println("Something is wrong with the XML song element"); - } + AudioElement newSong = new Song(audioElement); + this.addElement(newSong); + } catch (Exception ex) { + System.out.println("Something is wrong with the XML song element"); + } } - if (audioElement.getNodeName().equals("audiobook")) { + if (audioElement.getNodeName().equals("audiobook")) { try { - AudioElement newAudioBook = new AudioBook(audioElement); - this.addElement(newAudioBook); - } catch (Exception ex) { - System.out.println("Something is wrong with the XML audiobook element"); - } + AudioElement newAudioBook = new AudioBook(audioElement); + this.addElement(newAudioBook); + } catch (Exception ex) { + System.out.println("Something is wrong with the XML audiobook element"); + } } } } - } + } public void saveAlbums() { - Document document = xmlHandler.createXMLDocument(); - if (document == null) return; + Document document = xmlHandler.createXMLDocument(); + if (document == null) return; // root element - Element root = document.createElement("albums"); - document.appendChild(root); + Element root = document.createElement("albums"); + document.appendChild(root); //save all albums - for (Iterator<Album> albumsIter = this.albums(); albumsIter.hasNext(); ) { - Album currentAlbum = albumsIter.next(); - currentAlbum.createXMLElement(document, root); - } - xmlHandler.createXMLFile(document, ALBUMS_FILE_PATH); - } + for (Iterator<Album> albumsIter = this.albums(); albumsIter.hasNext(); ) { + Album currentAlbum = albumsIter.next(); + currentAlbum.createXMLElement(document, root); + } + xmlHandler.createXMLFile(document, ALBUMS_FILE_PATH); + } public void savePlayLists() { - Document document = xmlHandler.createXMLDocument(); - if (document == null) return; + Document document = xmlHandler.createXMLDocument(); + if (document == null) return; // root element - Element root = document.createElement("playlists"); - document.appendChild(root); + Element root = document.createElement("playlists"); + document.appendChild(root); //save all playlists - for (Iterator<PlayList> playlistsIter = this.playlists(); playlistsIter.hasNext(); ) { - PlayList currentPlayList = playlistsIter.next(); - currentPlayList.createXMLElement(document, root); - } - xmlHandler.createXMLFile(document, PLAYLISTS_FILE_PATH); - } + for (Iterator<PlayList> playlistsIter = this.playlists(); playlistsIter.hasNext(); ) { + PlayList currentPlayList = playlistsIter.next(); + currentPlayList.createXMLElement(document, root); + } + xmlHandler.createXMLFile(document, PLAYLISTS_FILE_PATH); + } public void saveElements() { - Document document = xmlHandler.createXMLDocument(); - if (document == null) return; + Document document = xmlHandler.createXMLDocument(); + if (document == null) return; // root element - Element root = document.createElement("elements"); - document.appendChild(root); + Element root = document.createElement("elements"); + document.appendChild(root); //save all AudioElements - for (AudioElement currentElement : elements) { + for (AudioElement currentElement : elements) { - if (currentElement instanceof Song) { - currentElement.createXMLElement(document, root); + if (currentElement instanceof Song) { + currentElement.createXMLElement(document, root); } - if (currentElement instanceof AudioBook) { - currentElement.createXMLElement(document, root); + if (currentElement instanceof AudioBook) { + currentElement.createXMLElement(document, root); } - } - xmlHandler.createXMLFile(document, ELEMENTS_FILE_PATH); - } + } + xmlHandler.createXMLFile(document, ELEMENTS_FILE_PATH); + } public void getAudioElement(List<AudioElement> audios, String elementTitle) throws NoAlbumFoundException, UnsupportedAudioFileException, IOException, LineUnavailableException { - for (AudioElement el : audios) { - if (el.getTitle().equalsIgnoreCase(elementTitle)) { - el.manageAudioElement(); + for (AudioElement el : audios) { + if (el.getTitle().equalsIgnoreCase(elementTitle)) { + el.manageAudioElement(); } - } + } - } + } public void searchAudioElement() throws UnsupportedAudioFileException, NoAlbumFoundException, LineUnavailableException, IOException, NoElementFoundException { - Scanner scanner = new Scanner(System.in); - System.out.println("Entrez le titre ou l'artiste de la musique que vous souhaitez chercher dans la base de données"); - String word = scanner.next().toLowerCase(Locale.ROOT); - List<AudioElement> searchResult = new ArrayList<>(); - for(AudioElement el : elements){ - if(el.getTitle().toLowerCase(Locale.ROOT).contains(word) || el.getArtist().toLowerCase(Locale.ROOT).contains(word)){ - searchResult.add(el); - System.out.println(el); + Scanner scanner = new Scanner(System.in); + System.out.println("Entrez le titre ou l'artiste de la musique que vous souhaitez chercher dans la base de données"); + String word = scanner.next().toLowerCase(Locale.ROOT); + List<AudioElement> searchResult = new ArrayList<>(); + for(AudioElement el : elements){ + if(el.getTitle().toLowerCase(Locale.ROOT).contains(word) || el.getArtist().toLowerCase(Locale.ROOT).contains(word)){ + searchResult.add(el); + System.out.println(el); } - } + } - if(searchResult.isEmpty()){ - throw new NoElementFoundException("Any result for your search"); + if (searchResult.isEmpty()) { + throw new NoElementFoundException("Any result for your search"); } - if (searchResult.size()==1){ - this.getAudioElement(searchResult, searchResult.get(0).getTitle()); + if (searchResult.size() == 1) { + this.getAudioElement(searchResult, searchResult.get(0).getTitle()); } - } + } + + /** + * Method getting a list of playlists + * + * @return a list of playlist titles + * @author Anthony BOULANT + */ + public String getPlayListsTitles() { + StringBuilder titleList = new StringBuilder(); + + for (PlayList pl : playlists) + titleList.append(pl.getTitle()).append("\n"); + return titleList.toString(); + } + /** + * Method checking the songs contained in a chosen playlist and returning them if found. + * + * @param playListTitle the title of a (chosen) playlist + * @return a list of songs from a playlist + * @throws NoPlayListFoundException if the chosen playlist doesn't exist + * @author Anthony BOULANT + */ + public List<AudioElement> getPlayListSongs(String playListTitle) throws NoPlayListFoundException { + PlayList thePlayList = null; + ArrayList<AudioElement> songsInPlayList = new ArrayList<>(); + for (PlayList pl : playlists) { + if (pl.getTitle().equalsIgnoreCase(playListTitle)) { + thePlayList = pl; + break; + } + } + if (thePlayList == null) throw new NoPlayListFoundException("No playlist with this title in the MusicHub!"); + + List<UUID> songIDs = thePlayList.getElements(); + for (UUID id : songIDs) + for (AudioElement el : elements) { + if (el instanceof Song) { + if (el.getUUID().equals(id)) songsInPlayList.add(el); + } + } + return songsInPlayList; + + } }
\ No newline at end of file diff --git a/target/site/jacoco/musichub.business/SortByAuthor.html b/target/site/jacoco/musichub.business/SortByAuthor.html index 851cdce..b762715 100644 --- a/target/site/jacoco/musichub.business/SortByAuthor.html +++ b/target/site/jacoco/musichub.business/SortByAuthor.html @@ -1 +1 @@ -SortByAuthor

SortByAuthor

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total9 of 90 %0 of 0n/a222222
compare(AudioElement, AudioElement)60 %n/a111111
SortByAuthor()30 %n/a111111
\ No newline at end of file +SortByAuthor

SortByAuthor

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total9 of 90 %0 of 0n/a222222
compare(AudioElement, AudioElement)60 %n/a111111
SortByAuthor()30 %n/a111111
\ No newline at end of file diff --git a/target/site/jacoco/musichub.business/SortByDate.html b/target/site/jacoco/musichub.business/SortByDate.html index 8f4b2f7..6f9a099 100644 --- a/target/site/jacoco/musichub.business/SortByDate.html +++ b/target/site/jacoco/musichub.business/SortByDate.html @@ -1 +1 @@ -SortByDate

SortByDate

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total9 of 90 %0 of 0n/a222222
compare(Album, Album)60 %n/a111111
SortByDate()30 %n/a111111
\ No newline at end of file +SortByDate

SortByDate

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total9 of 90 %0 of 0n/a222222
compare(Album, Album)60 %n/a111111
SortByDate()30 %n/a111111
\ No newline at end of file diff --git a/target/site/jacoco/musichub.business/SortByGenre.html b/target/site/jacoco/musichub.business/SortByGenre.html index 6dd6e7d..d89caea 100644 --- a/target/site/jacoco/musichub.business/SortByGenre.html +++ b/target/site/jacoco/musichub.business/SortByGenre.html @@ -1 +1 @@ -SortByGenre

SortByGenre

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total9 of 90 %0 of 0n/a222222
compare(Song, Song)60 %n/a111111
SortByGenre()30 %n/a111111
\ No newline at end of file +SortByGenre

SortByGenre

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total9 of 90 %0 of 0n/a222222
compare(Song, Song)60 %n/a111111
SortByGenre()30 %n/a111111
\ No newline at end of file diff --git a/target/site/jacoco/musichub.business/index.html b/target/site/jacoco/musichub.business/index.html index f7cd669..2f40e82 100644 --- a/target/site/jacoco/musichub.business/index.html +++ b/target/site/jacoco/musichub.business/index.html @@ -1 +1 @@ -musichub.business

musichub.business

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total1 483 of 2 13430 %160 of 17910 %1401783735135182815
MusicHub8740 %1240 %8585209209232311
Album3300 %140 %161684849911
AudioBook1174728 %8220 %121727394901
AudioElement8518168 %9218 %111630724901
PlayList3217084 %5964 %5149530701
SortByAuthor90 %n/a22222211
SortByDate90 %n/a22222211
SortByGenre90 %n/a22222211
NoAlbumFoundException0 %n/a11221111
NoPlayListFoundException0 %n/a11221111
NoElementFoundException0 %n/a11221111
Language4693 %n/a13161301
Category4693 %n/a13161301
Song105100 %6100 %0120260701
Genre56100 %n/a03060301
\ No newline at end of file +musichub.business

musichub.business

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total1 588 of 2 23929 %175 of 1949 %1491873935335384815
MusicHub9730 %1400 %9595228228252511
Album3300 %140 %161684849911
AudioBook1174728 %8220 %121727394901
AudioElement9118166 %8220 %101531734901
PlayList3217084 %5964 %5149530701
SortByAuthor90 %n/a22222211
SortByDate90 %n/a22222211
SortByGenre90 %n/a22222211
NoAlbumFoundException0 %n/a11221111
NoPlayListFoundException0 %n/a11221111
NoElementFoundException0 %n/a11221111
Language4693 %n/a13161301
Category4693 %n/a13161301
Song105100 %6100 %0120260701
Genre56100 %n/a03060301
\ No newline at end of file diff --git a/target/site/jacoco/musichub.business/index.source.html b/target/site/jacoco/musichub.business/index.source.html index 15d2893..8bc89c8 100644 --- a/target/site/jacoco/musichub.business/index.source.html +++ b/target/site/jacoco/musichub.business/index.source.html @@ -1 +1 @@ -musichub.business

musichub.business

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total1 483 of 2 13430 %160 of 17910 %1401783735135182815
MusicHub.java9010 %1240 %9191215215292944
Album.java3300 %140 %161684849911
AudioBook.java1174728 %8220 %121727394901
AudioElement.java8518168 %9218 %111630724901
PlayList.java3217084 %5964 %5149530701
NoAlbumFoundException.java0 %n/a11221111
NoPlayListFoundException.java0 %n/a11221111
NoElementFoundException.java0 %n/a11221111
Language.java4693 %n/a13161301
Category.java4693 %n/a13161301
Song.java105100 %6100 %0120260701
Genre.java56100 %n/a03060301
\ No newline at end of file +musichub.business

musichub.business

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissedClasses
Total1 588 of 2 23929 %175 of 1949 %1491873935335384815
MusicHub.java1 0000 %1400 %101101234234313144
Album.java3300 %140 %161684849911
AudioBook.java1174728 %8220 %121727394901
AudioElement.java9118166 %8220 %101531734901
PlayList.java3217084 %5964 %5149530701
NoAlbumFoundException.java0 %n/a11221111
NoPlayListFoundException.java0 %n/a11221111
NoElementFoundException.java0 %n/a11221111
Language.java4693 %n/a13161301
Category.java4693 %n/a13161301
Song.java105100 %6100 %0120260701
Genre.java56100 %n/a03060301
\ No newline at end of file -- cgit v1.2.3