Pergunta

I'm using

andPredicate = Predicates.and(firstPredicate, secondPredicate);

Now I have to serialize the andPredicate (as a JsonObject) and need to access the internal list of the used predicates to gain access to the members of each single predicate.

Is there a way to access these?

Foi útil?

Solução

If you need behavior like this, the answer is to whip up your own version of Predicates.and(), which isn't too hard at all. Guava's internal implementation for Predicates.and is (correctly) an implementation detail, rather than something exposed to the user.

Outras dicas

I think there is no direct way to get this.

Anyway, as a workaround, you could use the toString() method of the andPredicate object. The implementation for this method (listed here ) will return a value like this:

And(<firstPredicate.toString()>, <secondPredicate.toString()>)

Where you can get the parenthesis content, and analyze each entry.

As every entry could also be an and, or, or another compose predicate, be careful on handling the commas and parenthesis.

As the class Javadoc states, andPredicate is already serializable:

All methods returns serializable predicates as long as they're given serializable parameters.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top