Interval Math

I've had fun getting back in touch with my old math orientation (it was my major) and digging into the definitions and rules surrounding intervals. It is not necessary to read this in order to use the timelanguage. It is, however, important that the designer of the library did read up. Hitching the design of key elements to established formalisms, and then carefully adhering to their rules and definitions, ensures that the result will be logically consistent and will have the conceptual power that goes with that body of math. Often, a programmer uses an idea from math or another field as a metaphore for what they are doing. This can be a useful communication device, but does not have the same value as using the concept itself. That is what I'm doing here. So, users of the library can have the confidence that the logic they are relying on isn't just something I cooked up, but rests on a solid foundation.

That said, read on if you find this stuff as interesting as I do. And please do point out any mistakes or any improvements I could make.

Why Comparable

An interval is a subset of a set with total order (also called linear order). The Java abstraction that is intended to denote this property is Comparable. Sun's documentation says "This interface imposes a total ordering on the objects of each class that implements it." This is the intent of Comparable, and it is usually the case, but there is no way a Java interface can inforce the rules of total order. For example, I could create objects such that a < b and b < a were both true. Still, in practice, most classes that implement Comparable have total order, and it is the standard way of denoting this property.

Therefore, the parameters of the Interval class are typed "Comparable", and it resides in the "basic" package. The intention is to take care of interval logic in one place for every such case — and there are lots of them, including two kinds of time intervals.

Open and Closed Intervals

A closed interval includes its end points, while an open interval does not. An interval can also be "half-open", containing only one end point. The standard notation for this (used in the toString method) is:

So, for example, the intersection of [a, b] and [b, c] would be [b, b], while (a, b) and (b, c) do not intersect. The Interval class specifies whether each end point is included, and all methods follow the implications of those limit points.