Thursday, April 28, 2011

Does an open-ended interval implementation exist for Java?

I've got a classification of certain values in different intervals. Most have the form [20-30], but some are of the form [30-infinite).

Is the an interval class you know of which can represent:

  • an interval which is not closed on both sides (e.g. (0-5) or [0-5) )
  • an interval which closes (or starts) on infinite
From stackoverflow
  • I know of no library classes, but I recall rather trivially writing such classes.

  • Time&Money project seems to have Interval class that you need.

    See these files in their svn: interval package.

    tpdi : Using that sounds expensive and time consuming.
    boutta : Why do you think it's expensive?
    Sergey : @tpdi these few classes can just be copied if you mean including the whole library. It's under MIT license.
    Hemal Pandya : I think tpdi was punning
  • The Apache-commons-lang project (http://commons.apache.org/lang/) contains classes dealing with ranges (like IntRange - http://commons.apache.org/lang/apidocs/org/apache/commons/lang/math/IntRange.html). I'm not sure it covers all your needs, but it might be worth checking.

    boutta : I've seen the ranges, but since they are type specific they are not so useful as the classes from the Time&Money library.

0 comments:

Post a Comment