< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Sorting.AlbumArtistComparer
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs
Line coverage
16%
Covered lines: 1
Uncovered lines: 5
Coverable lines: 6
Total lines: 42
Line coverage: 16.6%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%11100%
Compare(...)100%210%
GetFirstAlbumArtist(...)0%2040%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs

#LineLine coverage
 1using System;
 2using Jellyfin.Data.Enums;
 3using MediaBrowser.Controller.Entities;
 4using MediaBrowser.Controller.Entities.Audio;
 5using MediaBrowser.Controller.Sorting;
 6using MediaBrowser.Model.Querying;
 7
 8namespace Emby.Server.Implementations.Sorting
 9{
 10    /// <summary>
 11    /// Allows comparing artists of albums. Only the first artist of each album is considered.
 12    /// </summary>
 13    public class AlbumArtistComparer : IBaseItemComparer
 14    {
 15        /// <summary>
 16        /// Gets the item type this comparer compares.
 17        /// </summary>
 118        public ItemSortBy Type => ItemSortBy.AlbumArtist;
 19
 20        /// <summary>
 21        /// Compares the specified arguments on their primary artist.
 22        /// </summary>
 23        /// <param name="x">First item to compare.</param>
 24        /// <param name="y">Second item to compare.</param>
 25        /// <returns>Zero if equal, else negative or positive number to indicate order.</returns>
 26        public int Compare(BaseItem? x, BaseItem? y)
 27        {
 028            return string.Compare(GetFirstAlbumArtist(x), GetFirstAlbumArtist(y), StringComparison.OrdinalIgnoreCase);
 29        }
 30
 31        private static string? GetFirstAlbumArtist(BaseItem? x)
 32        {
 033            if (x is IHasAlbumArtist audio
 034                && audio.AlbumArtists.Count != 0)
 35            {
 036                return audio.AlbumArtists[0];
 37            }
 38
 039            return null;
 40        }
 41    }
 42}