Hi

I will add a sample to the predicate wiki page
http://camel.apache.org/predicate.html

But there is a hikup with the apache server right now, so here is part
of the source code for an unit test:

import static org.apache.camel.builder.PredicateBuilder.not;

...

    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
                // START SNIPPET: e1
                from("direct:start")
                    .choice()

.when(not(header("username").regex("goofy|pluto"))).to("mock:people")
                        .otherwise().to("mock:animals")
                    .end();
                // END SNIPPET: e1
            }
        };
    }


On Tue, Feb 17, 2009 at 5:01 AM, Trevv <4...@safe-mail.net> wrote:
>
> Most of my uses of .when are like the first snippet below, very easy to read.
>
> But I have a few uses of .when which need to negate the Predicate, and in
> those places I'm using code like the second snippet below.  It works well,
> and there are no compiler warnings, but it is NOT easy to read.  How should
> I make this code easier to read?
>
>    // take the first branch, if the regex DOES match...
>
>    choice().
>      when(header("foo").
>             regex("cheese|whey"))
>
>    ========
>
>    // take the first branch, if the regex DOES NOT match...
>
>    choice().
>      when(PredicateBuilder.
>             not(Builder.
>                   <MinaExchange>header("foo").
>                     regex("cheese|whey")))
> --
> View this message in context: 
> http://www.nabble.com/How-to-negate-a-Predicate--tp22049751s22882p22049751.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Reply via email to