public AscOrDescHelper <T> ProcessNextValue(T next) { switch (state) { case SortedState.NoValues: state = SortedState.Undecided; break; case SortedState.Undecided: case SortedState.Ascending: case SortedState.Descending: int cmp = next.CompareTo(lastValue); switch (state) { case SortedState.Undecided: if (cmp > 0) { state = SortedState.Ascending; } else if (cmp < 0) { state = SortedState.Descending; } else { uniqueValues = false; } break; case SortedState.Ascending: if (cmp < 0) { state = SortedState.Mixture; } else if (cmp == 0) { // Not unique uniqueValues = false; } break; case SortedState.Descending: if (cmp > 0) { state = SortedState.Mixture; } else if (cmp == 0) { // Not unique uniqueValues = false; } break; } break; } lastValue = next; return(this); }
public AscOrDescHelper() { state = SortedState.NoValues; uniqueValues = true; // tentative assumption }