1

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?

oschrenk
  • 4,080
  • 4
  • 22
  • 25

3 Answers3

3

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.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
1

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.

Tomas Narros
  • 13,390
  • 2
  • 40
  • 56
  • 1
    Seems that way. `Predicates` uses the `private static class Predicates.AndPredicate` which offers no access to the internal components. – oschrenk Jan 03 '12 at 10:26
1

As the class Javadoc states, andPredicate is already serializable:

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

Jared Levy
  • 1,986
  • 13
  • 12
  • 3
    I wasn't clear on what I meant with serializing. I need to create a JsonObject out of the predicate, for that I need access to its members. – oschrenk Jan 03 '12 at 13:22