Hi,
I am using guava Range extensively to compute min/max pairs of lists of doubles.
List<Double> list = queryMeasurementValues(..);
Range<Double> range = computeBounds(list);
allInclusiveRange = range.span(<all-other-ranges>)
In case that the list is empty I currently return "null" which is not that great, because I need to explicitly test for "null" all the time
See also http://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained
It would be nice to have an explicit "neutral" range element that has the following properties:
Range range = Ranges.invalid/empty/neutral/none/etc..
range.contains(val) == false
range.span(range, x) == x (this would be super helpful for me)
range.intersection(range, x) == range instead of IllegalArgException
range.isEmpty() == true
Wouldn't that be a) possible and b) helpful ?
cheers!
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
Hi,
I am using guava Range extensively to compute min/max pairs of lists of doubles.
List<Double> list = queryMeasurementValues(..);
Range<Double> range = computeBounds(list);
allInclusiveRange = range.span(<all-other-ranges>)
In case that the list is empty I currently return "null" which is not that great, because I need to explicitly test for "null" all the time
See also http://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained
It would be nice to have an explicit "neutral" range element that has the following properties:
Range range = Ranges.invalid/empty/neutral/none/etc..
range.contains(val) == false
range.span(range, x) == x (this would be super helpful for me)
range.intersection(range, x) == range instead of IllegalArgException
range.isEmpty() == true
Wouldn't that be a) possible and b) helpful ?
cheers!
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
| public interface RangeSet<C extends Comparable> { |
| |
| // Query methods |
| /** |
| * Determines whether any of this
range set's member ranges contains {@code value}. |
| */ |
| boolean contains(C value); |
Thank you all for your feedback.
@kevinb I see your point that it can hardly be defined as a valid pair of Cut<C> instances.
Still, being a corner case, I think that Ranges.none() could have equal right for existance as Ranges().all() does.
What do you think of the following simple implementation?
/** Returns a range that contains no value of type {@code C}. */
public static <C extends Comparable<?>> Range<C> none() {
return create(Cut.<C>aboveAll(), Cut.<C>belowAll());
}