Content of file MediaItemComparator.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>MediaItemComparator.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 :: Media Scanner</a> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-bluemarine2-model</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.bluemarine2.model.impl</a> &gt; <span class="el_source">MediaItemComparator.java</span></div><h1>MediaItemComparator.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.model.impl;

import javax.annotation.Nonnull;
import java.util.Comparator;
import java.util.List;
import it.tidalwave.util.As;
import it.tidalwave.util.AsException;
import it.tidalwave.util.Finder.InMemorySortCriterion;
import it.tidalwave.util.Finder.SortDirection;
import it.tidalwave.role.ui.Displayable;
import it.tidalwave.bluemarine2.model.MediaItem;
import static it.tidalwave.role.ui.Displayable._Displayable_;
import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.*;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="fc" id="L46">public class MediaItemComparator implements InMemorySortCriterion&lt;As&gt;</span>
  {
    private static final long serialVersionUID = 3413093735254009245L;

<span class="fc" id="L50">    private static final Comparator&lt;As&gt; COMPARATOR = (o1, o2) -&gt;</span>
      {
        try
          {
            // FIXME: use comparators chaining for lambdas
use comparators chaining for lambdas
<span class="fc" id="L55"> final MediaItem mi1 = o1.as(MediaItem.class);</span> <span class="fc" id="L56"> final MediaItem mi2 = o2.as(MediaItem.class);</span> <span class="fc" id="L57"> final MediaItem.Metadata m1 = mi1.getMetadata();</span> <span class="fc" id="L58"> final MediaItem.Metadata m2 = mi2.getMetadata();</span> <span class="fc" id="L59"> final int d1 = m1.get(DISK_NUMBER).orElse(1);</span> <span class="fc" id="L60"> final int d2 = m2.get(DISK_NUMBER).orElse(1);</span> <span class="fc" id="L61"> final int t1 = m1.get(TRACK_NUMBER).orElse(0);</span> <span class="fc" id="L62"> final int t2 = m2.get(TRACK_NUMBER).orElse(0);</span> <span class="fc bfc" id="L64" title="All 2 branches covered."> if (d1 != d2)</span> { <span class="fc" id="L66"> return d1 - d2;</span> } <span class="pc bpc" id="L69" title="1 of 2 branches missed."> if (t1 != t2)</span> { <span class="fc" id="L71"> return t1 - t2;</span> } } <span class="fc" id="L74"> catch (AsException e) // FIXME: useless?</span> { <span class="nc" id="L76"> }</span> <span class="fc" id="L78"> return displayNameOf(o1).compareTo(displayNameOf(o2));</span> }; <span class="fc" id="L81"> private static final InMemorySortCriterion&lt;As&gt; DELEGATE = InMemorySortCriterion.of(COMPARATOR);</span> @Nonnull private static String displayNameOf (@Nonnull final As object) { <span class="fc" id="L86"> return object.maybeAs(_Displayable_).map(Displayable::getDisplayName).orElse(&quot;???&quot;);</span> } @Override public void sort (@Nonnull List&lt;? extends As&gt; results, @Nonnull SortDirection sortDirection) { <span class="fc" id="L92"> DELEGATE.sort(results, sortDirection);</span> <span class="fc" id="L93"> }</span> @Override @Nonnull public String toString() { <span class="nc" id="L98"> return &quot;MediaItemComparator&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>