aboutsummaryrefslogtreecommitdiff
path: root/target/site/jacoco/musichub.business/PlayList.java.html
blob: 6a45004f98d184634a08b3409d6a128657633552 (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
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="fr"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>PlayList.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">spoteezer</a> &gt; <a href="index.source.html" class="el_package">musichub.business</a> &gt; <span class="el_source">PlayList.java</span></div><h1>PlayList.java</h1><pre class="source lang-java linenums">package musichub.business;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.UUID;

public class PlayList {
    private final String title;
    private final UUID uuid;
    private ArrayList&lt;UUID&gt; elementUUIDs;

<span class="nc" id="L16">    public PlayList(String title, String id, ArrayList&lt;UUID&gt; elementUUIDs) {</span>
<span class="nc" id="L17">        this.title = title;</span>
<span class="nc" id="L18">        this.uuid = UUID.fromString(id);</span>
<span class="nc" id="L19">        this.elementUUIDs = elementUUIDs;</span>
<span class="nc" id="L20">    }</span>

<span class="nc" id="L22">    public PlayList(String title) {</span>
<span class="nc" id="L23">        this.title = title;</span>
<span class="nc" id="L24">        this.uuid = UUID.randomUUID();</span>
<span class="nc" id="L25">        this.elementUUIDs = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L26">    }</span>

<span class="nc" id="L28">    public PlayList(Element xmlElement) {</span>
        {
<span class="nc" id="L30">            this.title = xmlElement.getElementsByTagName(&quot;title&quot;).item(0).getTextContent();</span>

<span class="nc" id="L32">            String uuid = null;</span>
            try {
<span class="nc" id="L34">                uuid = xmlElement.getElementsByTagName(&quot;UUID&quot;).item(0).getTextContent();</span>
<span class="nc" id="L35">            } catch (Exception ex) {</span>
<span class="nc" id="L36">                System.out.println(&quot;Empty playlist UUID, will create a new one&quot;);</span>
<span class="nc" id="L37">            }</span>
<span class="nc bnc" id="L38" title="All 4 branches missed.">            if ((uuid == null) || (uuid.isEmpty()))</span>
<span class="nc" id="L39">                this.uuid = UUID.randomUUID();</span>
<span class="nc" id="L40">            else this.uuid = UUID.fromString(uuid);</span>

            //parse list of elements:
<span class="nc" id="L43">            Node elementsElement = xmlElement.getElementsByTagName(&quot;elements&quot;).item(0);</span>
<span class="nc" id="L44">            NodeList elementUUIDNodes = elementsElement.getChildNodes();</span>
<span class="nc bnc" id="L45" title="All 2 branches missed.">            if (elementUUIDNodes == null) return;</span>

<span class="nc" id="L47">            this.elementUUIDs = new ArrayList&lt;&gt;();</span>


<span class="nc bnc" id="L50" title="All 2 branches missed.">            for (int i = 0; i &lt; elementUUIDNodes.getLength(); i++) {</span>
<span class="nc bnc" id="L51" title="All 2 branches missed.">                if (elementUUIDNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {</span>
<span class="nc" id="L52">                    Element elementElement = (Element) elementUUIDNodes.item(i);</span>
<span class="nc bnc" id="L53" title="All 2 branches missed.">                    if (elementElement.getNodeName().equals(&quot;UUID&quot;)) {</span>
                        try {
<span class="nc" id="L55">                            this.addElement(UUID.fromString(elementElement.getTextContent()));</span>
<span class="nc" id="L56">                        } catch (Exception ex) {</span>
<span class="nc" id="L57">                            ex.printStackTrace();</span>
<span class="nc" id="L58">                        }</span>
                    }
                }
            }
        }
<span class="nc" id="L63">    }</span>

    public void addElement(UUID element) {
<span class="nc" id="L66">        elementUUIDs.add(element);</span>
<span class="nc" id="L67">    }</span>

    public ArrayList&lt;UUID&gt; getElements() {
<span class="nc" id="L70">        return elementUUIDs;</span>
    }

    public String getTitle() {
<span class="nc" id="L74">        return title;</span>
    }

    public void createXMLElement(Document document, Element parentElement) {
<span class="nc" id="L78">        Element playlistElement = document.createElement(&quot;playlist&quot;);</span>
<span class="nc" id="L79">        parentElement.appendChild(playlistElement);</span>

<span class="nc" id="L81">        Element nameElement = document.createElement(&quot;title&quot;);</span>
<span class="nc" id="L82">        nameElement.appendChild(document.createTextNode(title));</span>
<span class="nc" id="L83">        playlistElement.appendChild(nameElement);</span>

<span class="nc" id="L85">        Element UUIDElement = document.createElement(&quot;UUID&quot;);</span>
<span class="nc" id="L86">        UUIDElement.appendChild(document.createTextNode(uuid.toString()));</span>
<span class="nc" id="L87">        playlistElement.appendChild(UUIDElement);</span>


<span class="nc" id="L90">        Element elementsElement = document.createElement(&quot;elements&quot;);</span>
<span class="nc bnc" id="L91" title="All 2 branches missed.">        for (UUID currentUUID : this.elementUUIDs) {</span>

<span class="nc" id="L93">            Element elementUUIDElement = document.createElement(&quot;UUID&quot;);</span>
<span class="nc" id="L94">            elementUUIDElement.appendChild(document.createTextNode(currentUUID.toString()));</span>
<span class="nc" id="L95">            elementsElement.appendChild(elementUUIDElement);</span>
<span class="nc" id="L96">        }</span>
<span class="nc" id="L97">        playlistElement.appendChild(elementsElement);</span>
<span class="nc" id="L98">    }</span>

}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>