/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.converter;

import org.apache.camel.Converter;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Message;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;

/**
 * Some useful converters for Camel APIs such as to convert a {@link Predicate} or {@link Expression}
 * to a {@link Processor}
 */
@Converter(loader = true)
public final class CamelConverter {

    /**
     * Utility classes should not have a public constructor.
     */
    private CamelConverter() {
    }

    @Converter
    public static Processor toProcessor(final Predicate predicate) {
        return new Processor() {
            public void process(Exchange exchange) throws Exception {
                boolean answer = predicate.matches(exchange);
                Message out = exchange.getOut();
                out.copyFrom(exchange.getIn());
                out.setBody(answer);
            }
        };

    }

    @Converter
    public static Processor toProcessor(final Expression expression) {
        return new Processor() {
            public void process(Exchange exchange) throws Exception {
                Object answer = expression.evaluate(exchange, Object.class);
                Message out = exchange.getOut();
                out.copyFrom(exchange.getIn());
                out.setBody(answer);
            }
        };
    }

}

@@ -872,42 +872,8 @@
 er;%0A
-import org.apache.camel.Exchange;%0A
 impo
@@ -1425,99 +1425,22 @@
 urn 
-new Processor() %7B%0A            public void process(Exchange exchange) throws Exception %7B%0A   
+exchange -%3E %7B%0A
     
@@ -1447,17 +1447,16 @@
         
- 
 boolean 
@@ -1497,36 +1497,32 @@
 e);%0A            
-    
 Message out = ex
@@ -1542,36 +1542,32 @@
 ();%0A            
-  
-  
 out.copyFrom(exc
@@ -1586,36 +1586,32 @@
 ));%0A            
-    
 out.setBody(answ
@@ -1611,38 +1611,24 @@
 dy(answer);%0A
-            %7D%0A
         %7D;%0A%0A
@@ -1739,99 +1739,22 @@
 urn 
-new Processor() %7B%0A            public void process(Exchange exchange) throws Exception %7B%0A   
+exchange -%3E %7B%0A
     
@@ -1761,17 +1761,16 @@
         
- 
 Object a
@@ -1826,36 +1826,32 @@
 s);%0A            
-    
 Message out = ex
@@ -1871,36 +1871,32 @@
 ();%0A            
-  
-  
 out.copyFrom(exc
@@ -1915,36 +1915,32 @@
 ));%0A            
-    
 out.setBody(answ
@@ -1948,22 +1948,8 @@
 r);%0A
-            %7D%0A
     

Use lambda expressions