eclipse / eclipse-collections

Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional and fluent API.

Home Page:http://www.eclipse.org/collections

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interval types do not support reverse ranges for certain helper methods

donraab opened this issue · comments

A few Interval helper methods are missing support for reverse ranges, which are ranges where the from value is greater than the to value, which would require the by value to be negative.

Classes: Interval, IntInterval, LongInterval

The following examples throw exceptions today:

  1. zeroTo
Interval.zeroTo(-10);

// java.lang.IllegalArgumentException: Step by is incorrect for the range

This code should result in: Interval.fromToBy(0, -10, -1)

  1. to
Interval.from(10).to(-10);

// java.lang.IllegalArgumentException: Step by is incorrect for the range

This code should result in: Interval.fromToBy(10, -10, -1)

  1. oneTo
Interval.oneTo(-10); 

// java.lang.IllegalArgumentException: Only positive ranges allowed using oneToBy

This exception looks like it was intentional but I think if we fix the other two, this one should be changed to be consistent. This code should result in: Interval.fromToBy(1, -10, -1)

Failing tests should be written to cover all missing scenarios first. I was not exhaustive in my search, so there may be other helper methods that do not support reverse ranges.

hi @donraab,
may I give this one a try?

Hi @airtyon, yes, thank you! I will assign it to you.