using System;
namespace Umbraco.Core.Models
{
// The Range class. Adapted from http://stackoverflow.com/questions/5343006/is-there-a-c-sharp-type-for-representing-an-integer-range
/// Generic parameter.
public class Range where T : IComparable
{
/// Minimum value of the range.
public T Minimum { get; set; }
/// Maximum value of the range.
public T Maximum { get; set; }
/// Presents the Range in readable format.
/// String representation of the Range
public override string ToString()
{
return string.Format("{0},{1}", this.Minimum, this.Maximum);
}
/// Determines if the range is valid.
/// True if range is valid, else false
public bool IsValid()
{
return this.Minimum.CompareTo(this.Maximum) <= 0;
}
/// Determines if the provided value is inside the range.
/// The value to test
/// True if the value is inside Range, else false
public bool ContainsValue(T value)
{
return (this.Minimum.CompareTo(value) <= 0) && (value.CompareTo(this.Maximum) <= 0);
}
/// Determines if this Range is inside the bounds of another range.
/// The parent range to test on
/// True if range is inclusive, else false
public bool IsInsideRange(Range range)
{
return this.IsValid() && range.IsValid() && range.ContainsValue(this.Minimum) && range.ContainsValue(this.Maximum);
}
/// Determines if another range is inside the bounds of this range.
/// The child range to test
/// True if range is inside, else false
public bool ContainsRange(Range range)
{
return this.IsValid() && range.IsValid() && this.ContainsValue(range.Minimum) && this.ContainsValue(range.Maximum);
}
}
}