AK.F1.Timing.Model.Session.SpeedCapturesModel.UpdateCollection C# (CSharp) 메소드

UpdateCollection() 개인적인 메소드

private UpdateCollection ( SpeedCaptureLocation location, int driverId, int speed ) : void
location SpeedCaptureLocation
driverId int
speed int
리턴 void
        private void UpdateCollection(SpeedCaptureLocation location, int driverId, int speed)
        {
            var collection = GetInnerCollection(location);
            var existing = collection.Where(x => x.Driver.Id == driverId).FirstOrDefault();
            if(existing != null)
            {
                if(speed <= existing.Speed)
                {
                    return;
                }
                collection.Remove(existing);
            }
            if(collection.Count < MaxCollectionSize)
            {
                int insertIndex = collection.Count;
                for(int i = 0; i < collection.Count; ++i)
                {
                    if(speed > collection[i].Speed)
                    {
                        insertIndex = i;
                        break;
                    }
                }
                collection.Insert(insertIndex, CreateSpeedCaptureModel(location, driverId, speed));
            }
            else if(speed > collection.Last().Speed)
            {
                for(int i = 0; i < collection.Count; ++i)
                {
                    if(speed > collection[i].Speed)
                    {
                        var previous = collection[i];
                        for(int j = i + 1; j < collection.Count; ++j)
                        {
                            var temp = collection[j];
                            collection[j] = previous;
                            previous = temp;
                        }
                        collection[i] = CreateSpeedCaptureModel(location, driverId, speed);
                        break;
                    }
                }
            }
            NotifyIsEmptyChanged();
        }