Closed GoogleCodeExporter closed 9 years ago
- Release 10 will have a Range class with a contains(e) method to handle your
inRange use case.
- Range doesn't have a bounded(e) method, but when we look at converting some
of our internal code to use Range, we'll see whether this comes up often.
- We're not sure what's going to happen with additional Preconditions methods,
but if we expand our offerings there, we'll consider this one.
Original comment by cpov...@google.com
on 22 Jun 2011 at 6:17
AFAIR, the new Range class doesn't even provide a convenient way to create
(primitive) number ranges at all. Am I mistaken/did that change?
Original comment by j...@nwsnet.de
on 22 Jun 2011 at 10:48
That's right, you use the wrapper types.
Original comment by kevinb@google.com
on 27 Jun 2011 at 2:28
Original requester: while we won't have specific support for *primitives*, your
ideas may be sensible for Ranges of any kind; would you kindly file them
separately for us, then close this?
Original comment by kevinb@google.com
on 13 Jul 2011 at 6:46
Original comment by kevinb@google.com
on 13 Jul 2011 at 7:00
Original comment by fry@google.com
on 10 Dec 2011 at 4:11
This issue now basically becomes:
1) range.bounded(x) // returns the closest value in the range, to the specified
input. Probably requires a DiscreteDomain.
2) and 3) are answered by Preconditions.checkArgument(Ranges.closed(0,
100).contains(argument)).
Original comment by wasserman.louis
on 25 Dec 2011 at 4:44
Original comment by wasserman.louis
on 10 Jan 2012 at 4:18
Original comment by fry@google.com
on 16 Feb 2012 at 7:17
Original comment by kevinb@google.com
on 30 May 2012 at 7:43
Original comment by kevinb@google.com
on 22 Jun 2012 at 6:16
My team also has needed this, like 3 times the last couple of weeks. But for
doubles :-/
Original comment by andr...@google.com
on 2 Jan 2013 at 10:49
ah; this is the clamp problem: Math.max(minValue, Math.min(a, maxValue))
class Ordering {
// rearranges cmpr to fit order, origin <= limit
public static <A> Comparator<A> rearrange(Comparator<? super A> cmpr, A origin, A limit) {
return rearrange(cmpr,cmpr.compare(origin,limit));
}
// rearranges cmpr to fit order with respect to compare value
public static <A> Comparator<A> rearrange(Comparator<? super A> cmpr, int cmp) {
return (Comparator<A>)(cmp <= 0 ? cmpr : reverseRder(cmpr));
}
public static <A> A clamp(A origin, A limit, A value, Comparator<? super A> cmpr) {
final Comparator<? super A> rearranged = rearrange(cmpr, origin, limit);
// cmpr is fit to order, origin <= limit
return rearranged.compare(origin, value) >= 0 ? origin :
rearranged.compare(limit,value) <= 0 ? limit : value;
}
}
Original comment by jysjys1...@gmail.com
on 9 Feb 2014 at 1:25
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:18
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
evoh...@gmail.com
on 10 Jun 2011 at 6:17