/// <summary> /// Checks if a <paramref name="value"/> is clamped in an exclusive range between <paramref name="min"/> and <paramref name="max"/>. /// </summary> /// <param name="_this">The <see cref="IComparer"/> used for comparisons.</param> /// <param name="value"></param> /// <param name="min">The lower border of the range. Is considered lower than <paramref name="_this"/> if null.</param> /// <param name="max">The upper border of the range. Is considered higher than <paramref name="_this"/> if null.</param> /// <returns>True if <paramref name="value"/> is clamped, false if not.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="_this"/> is null.</exception> /// <example> /// <code> /// Boolean result = new MyComparer().IsClampedExclusive(value, min, max); /// </code> /// </example> public static Boolean IsClampedExclusive(this IComparer _this, Object value, Object min, Object max) { Throw.If.Object.IsNull(_this, nameof(_this)); Throw.If.Object.IsNull(value, nameof(value)); if (min != null && max != null && _this.IsGreaterThan(min, max)) { return(_this.IsClampedExclusive(value, max, min)); } Boolean result = true; result &= min == null || _this.IsGreaterThan(value, min); result &= max == null || _this.IsLessThan(value, max); return(result); }
/// <inheritdoc /> public bool MoveNext() { if (!_started) { _started = true; Current = _includesStart ? _start : _step(_start); } else if (_comparer.IsLessThan(Current, _end)) { Current = _step(Current); } int cmp = _comparer.Compare(Current, _end); return(cmp < 0 || _includesEnd && cmp == 0); }
/// <summary> /// Gets the lower value of two objects. /// </summary> /// <param name="_this">The <see cref="IComparer"/> used for comparisons.</param> /// <param name="x">The first <see cref="Object"/>.</param> /// <param name="y">The second <see cref="Object"/>.</param> /// <returns>The lower value.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="_this"/> is null.</exception> /// <example> /// <code> /// var result = new MyComparer().Min(value1, value2); /// </code> /// </example> public static Object Min(this IComparer _this, Object x, Object y) { Throw.If.Object.IsNull(_this, nameof(_this)); return(_this.IsLessThan(x, y) ? x : y); }
/// <summary> /// Gets the lower value of two objects. /// </summary> /// <typeparam name="T">The type of the objects.</typeparam> /// <param name="_this">The <see cref="IComparer{T}"/> used for comparisons.</param> /// <param name="x">The first object of type <typeparamref name="T"/>.</param> /// <param name="y">The second object of type <typeparamref name="T"/>.</param> /// <returns>The lower value.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="_this"/> is null.</exception> /// <example> /// <code> /// var result = new MyComparer().Min(value1, value2); /// </code> /// </example> public static T Min <T>(this IComparer <T> _this, T x, T y) { Throw.If.Object.IsNull(_this, nameof(_this)); return(_this.IsLessThan(x, y) ? x : y); }