| | | 1 | | using System; |
| | | 2 | | using Jellyfin.Data.Enums; |
| | | 3 | | using MediaBrowser.Controller.Entities; |
| | | 4 | | using MediaBrowser.Controller.Sorting; |
| | | 5 | | using MediaBrowser.Model.Querying; |
| | | 6 | | |
| | | 7 | | namespace Emby.Server.Implementations.Sorting |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Class IndexNumberComparer. |
| | | 11 | | /// </summary> |
| | | 12 | | public class IndexNumberComparer : IBaseItemComparer |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets the name. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <value>The name.</value> |
| | 1 | 18 | | public ItemSortBy Type => ItemSortBy.IndexNumber; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Compares the specified x. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <param name="x">The x.</param> |
| | | 24 | | /// <param name="y">The y.</param> |
| | | 25 | | /// <returns>System.Int32.</returns> |
| | | 26 | | public int Compare(BaseItem? x, BaseItem? y) |
| | | 27 | | { |
| | 14 | 28 | | ArgumentNullException.ThrowIfNull(x); |
| | | 29 | | |
| | 13 | 30 | | ArgumentNullException.ThrowIfNull(y); |
| | | 31 | | |
| | 12 | 32 | | if (!x.IndexNumber.HasValue && !y.IndexNumber.HasValue) |
| | | 33 | | { |
| | 2 | 34 | | return 0; |
| | | 35 | | } |
| | | 36 | | |
| | 10 | 37 | | if (!x.IndexNumber.HasValue) |
| | | 38 | | { |
| | 2 | 39 | | return -1; |
| | | 40 | | } |
| | | 41 | | |
| | 8 | 42 | | if (!y.IndexNumber.HasValue) |
| | | 43 | | { |
| | 2 | 44 | | return 1; |
| | | 45 | | } |
| | | 46 | | |
| | 6 | 47 | | return x.IndexNumber.Value.CompareTo(y.IndexNumber.Value); |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | } |