问题描述
我有几个需要一些类来表示和操纵条件(通常在UI中,因此用户通过组合不同的条件类型构建查询,然后代码可以根据要查询的底层系统进行转换,例如lucene和db)。我搜索了一整套可重用的课程,我相信这必须在许多现有的地方(所有表达语言为起始者)使用,但找不到任何容易使用的东西。我最终自己编写了这两个时代,但对不重复使用我确信存在的东西感到很不好。
I have needed in several occasions some classes to represent and manipulate conditions (typically in a UI so the user builds a query by combining different condition types and then the code can transform that depending on the underlying system to be queried, for example lucene and a db). I searched all over for a reusable set of classes, I am sure this has to be used in many existing places (all the expression languages for starters) but could not find anything easily usable. I ended up coding both times myself, but felt bad about not reusing something I am sure exists.
典型需求是:
- 几个运算符:和/或
- 可变数量的操作数
- 组合条件来构建表达式
- 表达式的序列化
- 从/到字符串的解析/格式化表达式
Typical needs are: - several operators: and or etc - variable number of operands - combining conditions to build expressions - serializing of expressions - parsing/formatting of expressions from/to strings
有人找到这样的东西?
推荐答案
看看。例如。 ,,等等在实现是可序列化,但我不知道从字符串解析。不过,我认为这是一个非常好的开始。另外,请查看,基于图书馆。
Take a look at Apache Commons Functor. E.g. UnaryPredicate, UnaryAnd, UnaryOr, etc. The built-in implementations are Serializable, but I don't know about parsing from strings. Still, I think it's a very good start towards what you want. Also, take a look at this IBM tutorial based on the library.
这篇关于可重用条件/表达式类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!