Skip to content

Commit

Permalink
Use Find instead of FirstOrDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessToucan committed Jan 5, 2019
1 parent e596d4f commit 4b5fc85
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 19 deletions.
5 changes: 2 additions & 3 deletions osu.Desktop/Updater/SimpleUpdateManager.cs
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using osu.Framework;
Expand Down Expand Up @@ -77,10 +76,10 @@ private string getBestUrl(GitHubRelease release)
switch (RuntimeInfo.OS)
{
case RuntimeInfo.Platform.Windows:
bestAsset = release.Assets?.FirstOrDefault(f => f.Name.EndsWith(".exe"));
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".exe"));
break;
case RuntimeInfo.Platform.MacOsx:
bestAsset = release.Assets?.FirstOrDefault(f => f.Name.EndsWith(".app.zip"));
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".app.zip"));
break;
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Objects/Slider.cs
Expand Up @@ -215,7 +215,7 @@ private void createTicks()
var distanceProgress = d / length;
var timeProgress = reversed ? 1 - distanceProgress : distanceProgress;

var firstSample = Samples.FirstOrDefault(s => s.Name == SampleInfo.HIT_NORMAL)
var firstSample = Samples.Find(s => s.Name == SampleInfo.HIT_NORMAL)
?? Samples.FirstOrDefault(); // TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933)
var sampleList = new List<SampleInfo>();

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs
Expand Up @@ -135,7 +135,7 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)
{
if (userTriggered)
{
var nextTick = ticks.FirstOrDefault(j => !j.IsHit);
var nextTick = ticks.Find(j => !j.IsHit);

nextTick?.TriggerResult(HitResult.Great);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tests/Visual/TestCaseBeatmapCarousel.cs
Expand Up @@ -148,7 +148,7 @@ private void advanceSelection(bool diff, int direction = 1, int count = 1)

private bool selectedBeatmapVisible()
{
var currentlySelected = carousel.Items.FirstOrDefault(s => s.Item is CarouselBeatmap && s.Item.State == CarouselItemState.Selected);
var currentlySelected = carousel.Items.Find(s => s.Item is CarouselBeatmap && s.Item.State == CarouselItemState.Selected);
if (currentlySelected == null)
return true;
return currentlySelected.Item.Visible;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tests/Visual/TestCaseNotificationOverlay.cs
Expand Up @@ -111,7 +111,7 @@ protected override void Update()

if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
{
var p = progressingNotifications.FirstOrDefault(n => n.State == ProgressNotificationState.Queued);
var p = progressingNotifications.Find(n => n.State == ProgressNotificationState.Queued);
if (p != null)
p.State = ProgressNotificationState.Active;
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Beatmaps/BeatmapSetInfo.cs
Expand Up @@ -36,7 +36,7 @@ public class BeatmapSetInfo : IHasPrimaryKey, IHasFiles<BeatmapSetFileInfo>, ISo

public string Hash { get; set; }

public string StoryboardFile => Files?.FirstOrDefault(f => f.Filename.EndsWith(".osb"))?.Filename;
public string StoryboardFile => Files?.Find(f => f.Filename.EndsWith(".osb"))?.Filename;

public List<BeatmapSetFileInfo> Files { get; set; }

Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Configuration/DatabasedConfigManager.cs
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System.Collections.Generic;
using System.Linq;
using osu.Framework.Configuration;
using osu.Game.Rulesets;

Expand Down Expand Up @@ -43,7 +42,7 @@ protected override void AddBindable<TBindable>(T lookup, Bindable<TBindable> bin
{
base.AddBindable(lookup, bindable);

var setting = databasedSettings.FirstOrDefault(s => (int)s.Key == (int)(object)lookup);
var setting = databasedSettings.Find(s => (int)s.Key == (int)(object)lookup);
if (setting != null)
{
bindable.Parse(setting.Value);
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/OsuGame.cs
Expand Up @@ -222,7 +222,7 @@ void setBeatmap()
var databasedSet = BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID);

// Use first beatmap available for current ruleset, else switch ruleset.
var first = databasedSet.Beatmaps.FirstOrDefault(b => b.Ruleset == ruleset.Value) ?? databasedSet.Beatmaps.First();
var first = databasedSet.Beatmaps.Find(b => b.Ruleset == ruleset.Value) ?? databasedSet.Beatmaps.First();

ruleset.Value = first.Ruleset;
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first);
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Edit/EditorClock.cs
Expand Up @@ -57,7 +57,7 @@ public bool SeekSnapped(double position)

// Depending on beatSnapLength, we may snap to a beat that is beyond timingPoint's end time, but we want to instead snap to
// the next timing point's start time
var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time);
var nextTimingPoint = ControlPointInfo.TimingPoints.Find(t => t.Time > timingPoint.Time);
if (position > nextTimingPoint?.Time)
position = nextTimingPoint.Time;

Expand Down Expand Up @@ -123,7 +123,7 @@ private void seek(int direction, bool snapped, double amount = 1)
if (seekTime < timingPoint.Time && timingPoint != ControlPointInfo.TimingPoints.First())
seekTime = timingPoint.Time;

var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time);
var nextTimingPoint = ControlPointInfo.TimingPoints.Find(t => t.Time > timingPoint.Time);
if (seekTime > nextTimingPoint?.Time)
seekTime = nextTimingPoint.Time;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Tournament/Drawings.cs
Expand Up @@ -327,7 +327,7 @@ private void reset(bool loadLastResults = false)
continue;

// ReSharper disable once AccessToModifiedClosure
DrawingsTeam teamToAdd = allTeams.FirstOrDefault(t => t.FullName == line);
DrawingsTeam teamToAdd = allTeams.Find(t => t.FullName == line);

if (teamToAdd == null)
continue;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Skinning/LegacySkin.cs
Expand Up @@ -102,7 +102,7 @@ private string getPathForFile(string filename)

string lastPiece = filename.Split('/').Last();

var file = source.Files.FirstOrDefault(f =>
var file = source.Files.Find(f =>
string.Equals(hasExtension ? f.Filename : Path.ChangeExtension(f.Filename, null), lastPiece, StringComparison.InvariantCultureIgnoreCase));
return file?.FileInfo.StoragePath;
}
Expand Down
Expand Up @@ -6,7 +6,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Textures;
using System.Linq;
using osu.Game.Beatmaps;

namespace osu.Game.Storyboards.Drawables
Expand Down Expand Up @@ -71,7 +70,7 @@ private void load(IBindableBeatmap beatmap, TextureStore textureStore)
{
var framePath = basePath.Replace(".", frame + ".");

var path = beatmap.Value.BeatmapSetInfo.Files.FirstOrDefault(f => f.Filename.ToLowerInvariant() == framePath)?.FileInfo.StoragePath;
var path = beatmap.Value.BeatmapSetInfo.Files.Find(f => f.Filename.ToLowerInvariant() == framePath)?.FileInfo.StoragePath;
if (path == null)
continue;

Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs
Expand Up @@ -6,7 +6,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using System.Linq;
using osu.Game.Beatmaps;

namespace osu.Game.Storyboards.Drawables
Expand Down Expand Up @@ -66,7 +65,7 @@ public DrawableStoryboardSprite(StoryboardSprite sprite)
private void load(IBindableBeatmap beatmap, TextureStore textureStore)
{
var spritePath = Sprite.Path.ToLowerInvariant();
var path = beatmap.Value.BeatmapSetInfo.Files.FirstOrDefault(f => f.Filename.ToLowerInvariant() == spritePath)?.FileInfo.StoragePath;
var path = beatmap.Value.BeatmapSetInfo.Files.Find(f => f.Filename.ToLowerInvariant() == spritePath)?.FileInfo.StoragePath;
if (path == null)
return;

Expand Down

0 comments on commit 4b5fc85

Please sign in to comment.