Geeks With Blogs

News
Neat Stuff Read all my hurricane entries While you are here, visit the Geeks With Blogs main feed
Advertising
Links Status of the Navy
Channel 9

.NET Hobbyist Programmer Staying Confused in a Busy World

My previous post talked about the layout for a generic range class I was working on.  I have now settled on the nomenclature and have filled out the properties and methods.  I think I'll post this to CodeProject some day.

[Serializable()]
public class Range<T> : IRange<T> where T : IComparable<T>
{
    [Flags]
    [Serializable]
    public enum RangeCompareResult { ... }

    // Constructors
    public Range()
    public Range(Range<T> range)
    public Range(T Start, T End)

    // Properties
    public T Start
    public T End
    public bool IsValid
    public string Description
    public string Name
    public object Tag

    // Methods
    public bool After(T value)
    public bool After(T Start, T End)
    public bool After(Range<T> range)

    public bool Before(T value)
    public bool Before(T Start, T End)
    public bool Before(Range<T> range)

    public bool Contains(T value)
    public bool Contains(T Start, T End)
    public bool Contains(Range<T> range)

    public bool Excludes(T value)
    public bool Excludes(T Start, T End)
    public bool Excludes(Range<T> range)

    public bool Equals(T Start, T End)
    public bool Equals(Range<T> range)
    public bool Equals(Range<T> Range1, Range<T> Range2)
    public override bool Equals(object obj)

    public bool Subset(T Start, T End)
    public bool Subset(Range<T> range)

    public bool Superset(T Start, T End)
    public bool Superset(Range<T> range)

    public static bool operator ==(Range<T> Range1, Range<T> Range2)
    public static bool operator !=(Range<T> Range1, Range<T> Range2)

    public override int GetHashCode()
    public override string ToString()

    public RangeCompareResult RangeCompare(Range<T> Range1, Range<T> Range2)
}

 

Posted on Sunday, April 23, 2006 8:16 PM Programming | Back to top


Comments on this post: Designing a Generic Range Class: Take 2

# re: Designing a Generic Range Class: Take 2
Requesting Gravatar...
Great class!

What about inclusive and exclusive range endpoints? For example, if Start = 0 exclusive, then 0 is not in the range but 0.0001 is.
If Start = 1 inclusive, then 0 is in the range.

See Interval Notation http://id.mind.net/~zona/mmts/miscellaneousMath/intervalNotation/intervalNotation.html

-- Tim
Left by Tim on Apr 24, 2006 8:49 PM

# re: Designing a Generic Range Class: Take 2
Requesting Gravatar...
I was thinking that the next two obvious additions would be inclusive/exclusive endpoints and unbounded ends where null implies infinity. Right now, I throw in the null case. I needed to get this (and its unit tests) working first. My usage for this project does not need either of those functions that I can see, but I will keep them in mind. I think I may write that CodeProject article sooner rather than later so more people can pound on the code.
Left by Mark on Apr 25, 2006 4:16 AM

Your comment:
 (will show your gravatar)


Copyright © Mark Treadwell | Powered by: GeeksWithBlogs.net