kucci / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Predicate factory classes for Comparable types #429

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to see the following factory methods in Predicates:

Predicate<T> largerThan(T reference)
Predicate<T> largerThanOrEqual(T reference)
Predicate<T> smallerThan(T reference)
Predicate<T> smallerThanOrEqual(T reference)

where <T extends Comparable<T>> and all methods use compareTo() internally

sample usage:

Collections2.filter(Arrays.asList(1,2,3,4), Predicates.largerThan(2))
=> [3, 4]

Patch with sample code is attached.

Original issue reported on code.google.com by SeanPFl...@googlemail.com on 21 Sep 2010 at 3:33

Attachments:

GoogleCodeExporter commented 9 years ago
This seems reasonable to me.

Much more low priority, but if we add these methods, I wonder if it's worth 
having corresponding methods that take a reference and a Comparator.  Seems 
like it may be useful for working with library code that you can't modify.

Original comment by boppenh...@google.com on 23 Sep 2010 at 4:16

GoogleCodeExporter commented 9 years ago
I agree, I was going to suggest the same thing.

Original comment by SeanPFl...@googlemail.com on 23 Sep 2010 at 4:50

GoogleCodeExporter commented 9 years ago
The way we'll address the main (Comparable) case is that our Range class will 
implement Predicate.  Ranges will support the four kinds of single-ended Ranges 
you list above, as well as the four kinds of double-ended Ranges and the 
"everything" range!

Original comment by kevinb@google.com on 17 Dec 2010 at 6:31

GoogleCodeExporter commented 9 years ago
nice, thanks for the info!

Original comment by SeanPFl...@googlemail.com on 17 Dec 2010 at 8:33

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 27 Jan 2011 at 6:17

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09