6

How can I create a Apache Commons Lang 3.1 Range<Inreger> object?

The JavaDocs say:

"An immutable range of objects from a minimum to maximum point inclusive."

"The objects need to either be implementations of Comparable or you need to supply a Comparator."

But when I try:

Range<Integer> range = new Range<Integer>(100, 200);

I get an error in my IDE that says required arguments are Integer, Integer, comparator.

Even though Integer implements the Comparable interface and thus I shouldn't need a extra comparator.

Can someone give me an example of how to construct the above described Range<Integer> object?

informatik01
  • 16,038
  • 10
  • 74
  • 104
WillamS
  • 2,457
  • 6
  • 24
  • 23

2 Answers2

11

The constructor of Range appears to be private so a static method may be the preferred way of constructing the object.

For example, it looks like you could use the static method between to construct a Range:

Range.between(100, 200);

However there are other static methods, it just depends what you need.

Jonathan
  • 20,053
  • 6
  • 63
  • 70
0

Range is an abstract class. Use IntRange range = new IntRange(100, 200) instead.

looper
  • 1,929
  • 23
  • 42
  • 1
    IntRange is the Range object in the old apache commons versions (before 3). I need to get intersects of ranges and this is not yet available in the old IntRange object. – WillamS Nov 29 '12 at 13:25
  • @WillamS: Oh, then I have an old version lying around. – looper Nov 29 '12 at 13:31