/// <summary> /// Sort the list by strategy year and week. /// </summary> public void Sort() { // don't bother with less than two items if (Values.Count < 2) { return; } const double ALN2I = 1.442695022; const float TINY = 1.0e-5F; // sort via a shell sort (good enough for the expected number of items in this list) // see Press et. al p.245 int nn, m, j, i, lognb2; cStrategy Temp; lognb2 = Convert.ToInt32(Math.Log((double)Values.Count) * ALN2I + TINY); m = Values.Count; for (nn = 1; nn <= lognb2; nn++) { m >>= 1; for (j = m + 1; j <= Values.Count; j++) { i = j - m; Temp = Values[j - 1]; while (i >= 1 && Temp.CompareTo(Values[i - 1]) == -1) { Values[i + m - 1] = Values[i - 1]; i -= m; } Values[i + m - 1] = Temp; } } }
public int CompareTo(object obj) { try { PIDSet p = ( PIDSet )obj; return(Temp.CompareTo(p.Temp)); } catch { return(-1); } }
public static void NewMethod2() { Temp templ = Temp.Value1; Temp temp2 = Temp.Value2; Console.WriteLine(templ == temp2); Console.WriteLine(templ.Equals(temp2)); Console.WriteLine(templ.CompareTo(temp2)); Console.WriteLine(templ == Temp.Value1); Console.WriteLine(templ == Temp.Value2); }
private static void NewMethod2() { Temp temp1 = Temp.Value1; Temp temp2 = Temp.Value2; Console.WriteLine(temp1 == temp2); Console.WriteLine(temp1.Equals(temp2)); Console.WriteLine(temp1.CompareTo(temp2)); Console.WriteLine(temp1 == Temp.Value1); Console.WriteLine(temp1 == Temp.Value2); }
// Column specific sort public int CompareTo(RecordWrapper a2, RecordComparer.ComparisonType comparisonMethod, RecordComparer.Order sortOrder) { int result = 0; switch (comparisonMethod) { case RecordComparer.ComparisonType.Distance: if (ActualDistance != a2.ActualDistance) { result = ActualDistance.CompareTo(a2.ActualDistance); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.StartDistance: if (StartDistance != a2.StartDistance) { result = StartDistance.CompareTo(a2.StartDistance); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.EndDistance: if (EndDistance != a2.EndDistance) { result = EndDistance.CompareTo(a2.EndDistance); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Location: if (Location != a2.Location) { result = Location.CompareTo(a2.Location); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.ElevationChange: if (ElevationChange != a2.ElevationChange) { result = ElevationChange.CompareTo(a2.ElevationChange); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.TotalAscend: if (TotalAscend != a2.TotalAscend) { result = TotalAscend.CompareTo(a2.TotalAscend); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.TotalDescend: if (TotalDescend != a2.TotalDescend) { result = TotalDescend.CompareTo(a2.TotalDescend); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Temp: if (Temp != a2.Temp) { result = Temp.CompareTo(a2.Temp); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Rank: if (Rank != a2.Rank) { result = Rank.CompareTo(a2.Rank); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.AvgPace: if (AvgPace != a2.AvgPace) { result = AvgPace.CompareTo(a2.AvgPace); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.AvgSpeed: if (Speed != a2.Speed) { result = Speed.CompareTo(a2.Speed); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.AvgHR: if (AvgHR != a2.AvgHR) { result = AvgHR.CompareTo(a2.AvgHR); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MaxHR: if (MaxHR != a2.MaxHR) { result = MaxHR.CompareTo(a2.MaxHR); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.StartDateTime: default: result = StartDateTime.CompareTo(a2.StartDateTime); break; } if (sortOrder == RecordComparer.Order.Descending) { return(result * -1); } else { return(result); } }
// Column specific sort public int CompareTo(Record a2, RecordComparer.ComparisonType comparisonMethod, RecordComparer.Order sortOrder) { int result = 0; switch (comparisonMethod) { // Define all different sort methods case RecordComparer.ComparisonType.AvgPower: if (AvgPower != a2.AvgPower) { result = AvgPower.CompareTo(a2.AvgPower); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MaxPower: if (MaxPower != a2.MaxPower) { result = MaxPower.CompareTo(a2.MaxPower); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Category: if (CategoryName != a2.CategoryName) { result = CategoryName.CompareTo(a2.CategoryName); } else { // TODO: WTF is this? switch (Category.Type) { case RecordCategory.RecordType.DistancePace: result = AvgPace.CompareTo(a2.AvgPace); break; case RecordCategory.RecordType.MaxTemperature: result = Temp.CompareTo(a2.Temp); break; } } break; case RecordComparer.ComparisonType.Distance: if (ActualDistance != a2.ActualDistance) { result = ActualDistance.CompareTo(a2.ActualDistance); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.StartDistance: if (StartDistance != a2.StartDistance) { result = StartDistance.CompareTo(a2.StartDistance); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.EndDistance: if (EndDistance != a2.EndDistance) { result = EndDistance.CompareTo(a2.EndDistance); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Location: if (Location != a2.Location) { result = Location.CompareTo(a2.Location); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.ActivityCategory: if (ActivityCategory != a2.ActivityCategory) { result = ActivityCategory.CompareTo(a2.ActivityCategory); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Name: if (Name != a2.Name) { result = Name.CompareTo(a2.Name); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.TotalTime: if (TotalTime != a2.TotalTime) { result = TotalTime.CompareTo(a2.TotalTime); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.ElevationChange: if (ElevationChange != a2.ElevationChange) { result = ElevationChange.CompareTo(a2.ElevationChange); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.TotalAscend: if (TotalAscend != a2.TotalAscend) { result = TotalAscend.CompareTo(a2.TotalAscend); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.TotalDescend: if (TotalDescend != a2.TotalDescend) { result = TotalDescend.CompareTo(a2.TotalDescend); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Temp: if (Temp != a2.Temp) { result = Temp.CompareTo(a2.Temp); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Rank: if (Rank != a2.Rank) { result = Rank.CompareTo(a2.Rank); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.AvgPace: if (AvgPace != a2.AvgPace) { result = AvgPace.CompareTo(a2.AvgPace); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.Speed: if (Speed != a2.Speed) { result = Speed.CompareTo(a2.Speed); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.AvgHR: if (AvgHR != a2.AvgHR) { result = AvgHR.CompareTo(a2.AvgHR); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.TotalCalories: if (TotalCalories != a2.TotalCalories) { result = TotalCalories.CompareTo(a2.TotalCalories); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.AvgCadence: if (AvgCadence != a2.AvgCadence) { result = AvgCadence.CompareTo(a2.AvgCadence); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MaxSpeed: if (MaxSpeed != a2.MaxSpeed) { result = MaxSpeed.CompareTo(a2.MaxSpeed); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MaxHR: if (MaxHR != a2.MaxHR) { result = MaxHR.CompareTo(a2.MaxHR); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MaxElevation: if (MaxElevation != a2.MaxElevation) { result = MaxElevation.CompareTo(a2.MaxElevation); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MinElevation: if (MinElevation != a2.MinElevation) { result = MinElevation.CompareTo(a2.MinElevation); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MaxCadence: if (MaxCadence != a2.MaxCadence) { result = MaxCadence.CompareTo(a2.MaxCadence); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MaxGrade: if (MaxGrade != a2.MaxGrade) { result = MaxGrade.CompareTo(a2.MaxGrade); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.MinGrade: if (MinGrade != a2.MinGrade) { result = MinGrade.CompareTo(a2.MinGrade); } else { result = StartDateTime.CompareTo(a2.StartDateTime); } break; case RecordComparer.ComparisonType.StartDateTime: default: result = StartDateTime.CompareTo(a2.StartDateTime); break; } if (sortOrder == RecordComparer.Order.Descending) { return(result * -1); } else { return(result); } }