Content of file CddbAlbum.java.html

<?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="en"><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>CddbAlbum.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">blueMarine II :: MusicBrainz</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.bluemarine2.metadata.cddb</a> &gt; <span class="el_source">CddbAlbum.java</span></div><h1>CddbAlbum.java</h1><pre class="source lang-java linenums">/*
 * *********************************************************************************************************************
 *
 * blueMarine II: Semantic Media Centre
 * http://tidalwave.it/projects/bluemarine2
 *
 * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
 *
 * *********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * *********************************************************************************************************************
 *
 * git clone https://bitbucket.org/tidalwave/bluemarine2-src
 * git clone https://github.com/tidalwave-it/bluemarine2-src
 *
 * *********************************************************************************************************************
 */
package it.tidalwave.bluemarine2.metadata.cddb;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import it.tidalwave.bluemarine2.model.MediaItem.Metadata.*;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import static java.util.stream.Collectors.*;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="pc bnc" id="L50" title="All 22 branches missed.">@Immutable @Getter @EqualsAndHashCode @ToString @Builder</span>
public class CddbAlbum
  {
<span class="fc" id="L53">    private static final Pattern PATTERN_DISC_LENGTH = Pattern.compile(&quot;# *Disc length: ([0-9]+) *seconds&quot;);</span>

<span class="fc" id="L55">    private static final Pattern PATTERN_TRACK_FRAME_OFFSETS = Pattern.compile(&quot;#\\s*[0-9]+&quot;);</span>

    @Nonnull
<span class="nc" id="L58">    private final Map&lt;String, String&gt; properties;</span>

    @Nonnull
<span class="fc" id="L61">    private final Cddb cddb;</span>

    @Nonnull
    public static CddbAlbum of (@Nonnull final String stringResponse)
      {
<span class="fc" id="L66">        final String[] split = stringResponse.split(&quot;\n&quot;);</span>

<span class="fc" id="L68">        final Cddb cddb = Cddb.builder()</span>
<span class="fc" id="L69">                            .discId(&quot;&quot;) // FIXME</span>
<span class="fc" id="L70"> .trackFrameOffsets(</span> <span class="fc" id="L71"> Stream.of(split)</span> <span class="fc" id="L72"> .skip(2)</span> <span class="fc" id="L73"> .filter(string -&gt; PATTERN_TRACK_FRAME_OFFSETS.matcher(string).matches())</span> <span class="fc" id="L74"> .mapToInt(s -&gt; Integer.parseInt(s.substring(1).trim()))</span> <span class="fc" id="L75"> .toArray())</span> <span class="fc" id="L76"> .discLength(</span> <span class="fc" id="L77"> Stream.of(split)</span> <span class="fc" id="L78"> .skip(2)</span> <span class="fc" id="L79"> .map(PATTERN_DISC_LENGTH::matcher)</span> <span class="fc" id="L80"> .filter(Matcher::matches)</span> <span class="fc" id="L81"> .map(matcher -&gt; Integer.parseInt(matcher.group(1)))</span> <span class="fc" id="L82"> .findFirst()</span> <span class="fc" id="L83"> .get())</span> <span class="fc" id="L84"> .build();</span> <span class="fc" id="L86"> return builder().cddb(cddb)</span> <span class="fc" id="L87"> .properties(</span> <span class="fc" id="L88"> Stream.of(split)</span> <span class="fc" id="L89"> .skip(2)</span> <span class="fc bfc" id="L90" title="All 4 branches covered."> .filter(string -&gt; !string.trim().isEmpty() &amp;&amp; !string.startsWith(&quot;#&quot;))</span> <span class="fc" id="L91"> .map(string -&gt; string.split(&quot;=&quot;))</span> <span class="fc bfc" id="L92" title="All 2 branches covered."> .filter(strings -&gt; strings.length == 2)</span> <span class="fc" id="L93"> .collect(toMap(strings -&gt; strings[0].trim(),</span> <span class="fc" id="L94"> strings -&gt; strings[1].trim(),</span> <span class="nc" id="L95"> (u, v) -&gt; u,</span> TreeMap::new))) <span class="fc" id="L97"> .build();</span> } @Nonnull public Optional&lt;String&gt; getProperty (@Nonnull final String key) { <span class="fc" id="L103"> return Optional.ofNullable(properties.get(key));</span> } @Nonnull public String toDumpString() { <span class="fc" id="L109"> return &quot;CddbAlbum\n&quot;</span> <span class="fc" id="L110"> + &quot;trackFrameOffsets: &quot; + Arrays.stream(cddb.getTrackFrameOffsets())</span> <span class="fc" id="L111"> .mapToObj(String::valueOf)</span> <span class="fc" id="L112"> .collect(joining(&quot; &quot;)) + &quot;\n&quot;</span> <span class="fc" id="L113"> + &quot;discLenght: &quot; + cddb.getDiscLength() + &quot;\n&quot;</span> <span class="fc" id="L114"> + properties.entrySet().stream()</span> <span class="fc" id="L115"> .map(e -&gt; String.format(&quot;%s: %s&quot;, e.getKey(), e.getValue()))</span> <span class="fc" id="L116"> .collect(joining(&quot;\n&quot;));</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>