在哪里可以找到 Guava 的基本谓词(例如,大于)?
我正在使用 guava 库,并注意到一个非常有用的 谓词< /a> 未定义 - “大于”。我是否应该在另一个地方寻找像这样的基本谓词,或者我注定要创建自己的功能支持 jar,其中包含这样的东西,并将其导入到我的所有项目中?他们是否有理由不包含此内容,但会花时间做一堆其他谓词(在谓词类中)?
I am using the guava library and have noticed that a very useful Predicate is not defined - "greater than". Is there another place I should be looking for basic predicates like this, or am I doomed to create my own functional support jar that includes things like this, and import it into all of my projects? Is there a reason they wouldn't include this,but would take the time to do a bunch of other predicates (In the Predicates class)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
范围 和
Ranges(更新:从 Guava 14.0 开始,Ranges
上的静态方法已合并到Range
中)现已为 r10 添加。您将能够执行以下操作:Range
具有许多其他强大的功能,包括将Range
查看为连续的ImmutableSortedSet
的能力> 在离散域上:我刚刚在这里展示了
Integer
,但是Range
内容适用于任何Comparable
。ContigeousSet
需要 DiscreteDomain 类型... Guava 提供了DiscreteDomain.integers()
、.longs()
和目前.bigIntegers()
。Range and
Ranges(update: the static methods onRanges
have been folded intoRange
as of Guava 14.0) have now been added for r10. You'll be able to just do:Range
s have a lot of other powerful functionality, including the ability to view aRange
as a contiguousImmutableSortedSet
over a discrete domain:I just showed
Integer
s here, but theRange
stuff works for anyComparable
.ContiguousSet
requires a DiscreteDomain for the type... Guava providesDiscreteDomain.integers()
,.longs()
and.bigIntegers()
at the moment.借助
Predicate
接口和使用谓词过滤集合的各种实用方法,Guava 提供了您可以构建的核心。Predicates
类允许您创建一些常用的谓词。我想您可以按照 Mike 的建议在问题跟踪器中提出增强请求,但我不确定他们会添加它,因为 Guava 力求高功率重量比。如果他们要添加“greaterThan”谓词,他们还需要添加“greaterOrEqualThan”、“lesserThan”、“lesserOrEqualThan”...这会很有用,但是对于这样的谓词来说,这是很多“API 膨胀”只需一行即可实现。不过值得一试。
更好的解决方案可能是拥有一个开源项目,该项目可以使用 Guava 本身不提供的所有“不错的”功能来扩展 Guava。我们可以将其称为“guava-leftovers”或其他名称;)或者可以要求 Biscotti 项目添加这样的实用方法(它们已经具有一些 Guava 中没有的“不错的”功能)。
With the
Predicate
interface and the various utility methods to filter collections with a Predicate, Guava provides a core you can build upon.The
Predicates
class lets you create some commonly used predicates. I guess you could do a request for enhancement in the issue tracker, as suggested by Mike, but I'm not sure they would add it, since Guava strives for a high power-to-weight ratio.If they were to add the "greaterThan" predicate, they would also need to add "greaterOrEqualThan", "lesserThan", "lesserOrEqualThan"... This would be useful, but this is a lot of "API bloat" for a Predicate that only takes one line to implement. Worth a try, though.
A better solution might be to have an open-source project that extends Guava with all the "nice-to-have" functionality that is not available in Guava proper. We could call it "guava-leftovers" or something ;) Or maybe ask the Biscotti project to add such utility methods (they already have some "nice-to-have" functionality that's not in Guava).
我之前请求过此功能并被提及此问题。显然,这个功能将通过 Ranges 来实现,Range 将实现 Predicate。
I have previously requested this functionality and been referred to this issue. Apparently this functionality will be implemented through Ranges, which will implement
Predicate
.谓词
< /a> 收集一些常见谓词,但不大于 1。我不认为番石榴提供这样的东西。您可以尝试在 guava 项目网站提交错误/功能请求:http:// code.google.com/p/guava-libraries/issues/listPredicates
collects some common predicates but not a greater than one. I don't think guava provides such a thing. You can try filing a bug/feature request at the guava project site : http://code.google.com/p/guava-libraries/issues/list