oschrenk
oschrenk

Reputation: 4209

Predicates#and: any way to access the internal predicates?

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?

Upvotes: 1

Views: 368

Answers (3)

Louis Wasserman
Louis Wasserman

Reputation: 198073

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.

Upvotes: 3

Jared Levy
Jared Levy

Reputation: 2026

As the class Javadoc states, andPredicate is already serializable:

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

Upvotes: 1

Tomas Narros
Tomas Narros

Reputation: 13468

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.

Upvotes: 1

Related Questions