Does an open-ended interval implementation exist for Java?
Asked Answered
P

4

5

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 there 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
Pippin answered 7/4, 2009 at 8:6 Comment(0)
C
1

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

See these files in their svn: interval package.

Cocainism answered 7/4, 2009 at 8:48 Comment(3)
Using that sounds expensive and time consuming.Kenaz
Why do you think it's expensive?Pippin
@Kenaz these few classes can just be copied if you mean including the whole library. It's under MIT license.Cocainism
R
3

The Apache-commons-lang project (http://commons.apache.org/lang/) contains classes dealing with ranges (like IntRange - https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/math/IntRange.html). I'm not sure it covers all your needs, but it might be worth checking.

Rabi answered 7/4, 2009 at 12:42 Comment(2)
I've seen the ranges, but since they are type specific they are not so useful as the classes from the Time&Money library.Pippin
The Apache 3 version of Range uses generics.Damselfish
K
1

I know of no library classes, but I recall rather trivially writing such classes.

Kenaz answered 7/4, 2009 at 8:9 Comment(0)
C
1

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

See these files in their svn: interval package.

Cocainism answered 7/4, 2009 at 8:48 Comment(3)
Using that sounds expensive and time consuming.Kenaz
Why do you think it's expensive?Pippin
@Kenaz these few classes can just be copied if you mean including the whole library. It's under MIT license.Cocainism
U
1

For those who might end up here, you can have a look at Google Ranges which are exactly what was asked here.

Uitlander answered 8/11, 2021 at 11:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.