1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 12:17:46 +08:00

Replace manual comparer implementation

Replace manually-implemented CriteriaComparer with a call to
Comparer<T>.Create() to decrease verbosity.
This commit is contained in:
Bartłomiej Dach 2019-10-28 15:07:36 +01:00
parent c8d3dd0e5a
commit c181edaedf

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -85,7 +84,8 @@ namespace osu.Game.Screens.Select.Carousel
InternalChildren.ForEach(c => c.Filter(criteria)); InternalChildren.ForEach(c => c.Filter(criteria));
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability // IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
InternalChildren = InternalChildren.OrderBy(c => c, new CriteriaComparer(criteria)).ToList(); var criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
InternalChildren = InternalChildren.OrderBy(c => c, criteriaComparer).ToList();
} }
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value) protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
@ -103,23 +103,5 @@ namespace osu.Game.Screens.Select.Carousel
State.Value = CarouselItemState.Selected; State.Value = CarouselItemState.Selected;
} }
} }
private class CriteriaComparer : IComparer<CarouselItem>
{
private readonly FilterCriteria criteria;
public CriteriaComparer(FilterCriteria criteria)
{
this.criteria = criteria;
}
public int Compare(CarouselItem x, CarouselItem y)
{
if (x != null && y != null)
return x.CompareTo(criteria, y);
throw new ArgumentNullException();
}
}
} }
} }