简体   繁体   English

在哪里可以找到比大番茄更好的基本谓词?

[英]Where to find basic Predicates like greaterThan for Guava?

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? 还有其他地方我应该寻找像这样的基本谓词,还是我注定要创建我自己的功能支持jar包含这样的东西,并将其导入我的所有项目? 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)? 有没有理由他们不会包含这个,但会花时间去做一堆其他的谓词(在Predicates类中)?

Range and Ranges (update: the static methods on Ranges have been folded into Range as of Guava 14.0) have now been added for r10. 范围范围 (更新:在静态方法Ranges已被折叠成Range为番石榴14.0的)现在已经被添加为R10。 You'll be able to just do: 你可以做到:

Iterable<Integer> positive = Iterables.filter(numbers, Range.greaterThan(0));

Range s have a lot of other powerful functionality, including the ability to view a Range as a contiguous ImmutableSortedSet over a discrete domain: Range具有许多其他强大的功能,包括在一个离散域上查看Range作为连续的ImmutableSortedSet的能力:

ContiguousSet<Integer> oneToOneHundred = ContiguousSet.create(
    Range.closed(1, 100), DiscreteDomains.integers());

I just showed Integer s here, but the Range stuff works for any Comparable . 我刚刚在这里展示了Integer ,但Range东西适用于任何Comparable ContiguousSet requires a DiscreteDomain for the type... Guava provides DiscreteDomain.integers() , .longs() and .bigIntegers() at the moment. ContiguousSet需要一个DiscreteDomain类型... Guava目前提供DiscreteDomain.integers() .longs().bigIntegers()

With the Predicate interface and the various utility methods to filter collections with a Predicate, Guava provides a core you can build upon. 使用Predicate接口和各种实用程序方法来过滤使用Predicate的集合,Guava提供了一个可以构建的核心。

The Predicates class lets you create some commonly used predicates. 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. 我猜你可以按照迈克的建议在问题跟踪器上做一个增强请求,但是我不确定他们是否会添加它,因为Guava正在努力实现高功率重量比。

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. 如果他们要添加“greaterThan”谓词,他们还需要添加“greaterOrEqualThan”,“lessserThan”,“lesserOrEqualThan”......这将是有用的,但这对于谓词来说是很多“API膨胀”只需要一行来实现。 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. 一个更好的解决方案可能是拥有一个开源项目,扩展Guava,具有Guava本身无法提供的所有“好用”功能。 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). 我们可以把它称为“guava-leftovers”或其他东西;)或者可能要求Biscotti项目添加这样的实用程序方法(它们已经有一些“很好的”功能,而不是Guava)。

I have previously requested this functionality and been referred to this issue . 我之前已经请求过这个功能并且已经引用了这个问题 Apparently this functionality will be implemented through Ranges, which will implement Predicate . 显然,这个功能将通过Ranges实现,Ranges将实现Predicate

Predicates collects some common predicates but not a greater than one. Predicates收集一些常见谓词但不大于一个。 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 您可以尝试在番石榴项目网站上提交错误/功能请求: http//code.google.com/p/guava-libraries/issues/list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 矛盾地转换番石榴谓词 - Contravariantly converting Guava Predicates Google Guava Predicates.or()或Predicates.and()类型 - Google Guava Predicates.or() or Predicates.and() type Criteria query combine and predicates and or 谓词在 where 方法中 - Criteria query combine and predicates and or predicates in where method 如何在java 8 stream api中使用guava Predicates作为过滤器 - How to use guava Predicates as filter in the java 8 stream api 从嵌套结构中删除谓词(Google番石榴谓词) - Remove predicate from nested structure (google guava predicates) Guava 是否为身份相等提供 Predicates.is(T) (a la Predicates.equalTo(T t))? - Does Guava provide a Predicates.is(T) (a la Predicates.equalTo(T t)) for identity equality? Scala中的“ +”,“ *”,“ /”(算术运算符)之类的基本方法在哪里实现? - Where is implementation of basic methods like '+', '*', '/' (Arithmetic operators) in Scala? JavaFX:是否有一个允许空值的整数属性并提供像GreaterThan和lessThan这样的方法? - JavaFX: Is there an integer property allowing null values and providing methods like greaterThan and lessThan? 使用番石榴装饰地图以使其像Set一样 - Decorate a Map to behave like a Set using Guava 需要选择类似番石榴缓存功能的更新 - Need a select for update like functionality with guava cache
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM