Replace List<Number> with Range#682
Replace List<Number> with Range#682SamCarlberg wants to merge 2 commits intoWPIRoboticsProjects:masterfrom
Conversation
Current coverage is 54.48% (diff: 42.10%)@@ master #682 diff @@
==========================================
Files 209 210 +1
Lines 6706 6721 +15
Methods 0 0
Messages 0 0
Branches 656 657 +1
==========================================
+ Hits 3659 3662 +3
- Misses 2878 2890 +12
Partials 169 169
|
|
Because it's immutable and I don't want to be generating excessive amounts of short-lived objects |
| * @throws IllegalArgumentException if min > max | ||
| */ | ||
| public Range(double min, double max) { | ||
| checkArgument(min <= max, "Min must be <= max"); |
There was a problem hiding this comment.
Would probably be more usable if, instead of throwing checkArgument exceptions, this just did the intelligent thing and set min and max to the smallest and the largest, respectively.
There was a problem hiding this comment.
I'm not sure if I would agree with that.
|
I agree with @AustinShalit on this one. I think using Guava makes sense. |
|
Sorry, this looks like a dead thread but I found some time to 'walk around GRIP' on Github. I am not so sure about Guava. Looking into it, I think Guava uses Comparable (.compareTo()). Not to say that anything is wrong with this, but if anything is mistyped, this custom Range class will force compilation issues (meaning that it will be easily revisable and noticed faster than letting Travis CI check it). Also, .compareTo() can be added to anything, and has been built in to Strings, Arrays, int, double, char, and plenty of other Objects in the Java library. CompareTo also has a tendency to be one of two comparisons, based on how the Java library is written. Where the object either checks bit values or else the object compares memory addresses which can make code confusing, and/or mismatched. |
Closes #677