当前位置: 首页>>代码示例>>Java>>正文


Java Predicate类代码示例

本文整理汇总了Java中org.apache.camel.Predicate的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Predicate类属于org.apache.camel包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startsWith

import org.apache.camel.Predicate; //导入依赖的package包/类
public static Predicate startsWith(final Expression left, final Expression right) {
    return new BinaryPredicateSupport(left, right) {

        protected boolean matches(Exchange exchange, Object leftValue, Object rightValue) {
            if (leftValue == null && rightValue == null) {
                // they are equal
                return true;
            } else if (leftValue == null || rightValue == null) {
                // only one of them is null so they are not equal
                return false;
            }
            String leftStr = exchange.getContext().getTypeConverter().convertTo(String.class, leftValue);
            String rightStr = exchange.getContext().getTypeConverter().convertTo(String.class, rightValue);
            if (leftStr != null && rightStr != null) {
                return leftStr.startsWith(rightStr);
            } else {
                return false;
            }
        }

        protected String getOperationText() {
            return "startsWith";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:PredicateBuilder.java

示例2: handle

import org.apache.camel.Predicate; //导入依赖的package包/类
@Override
public Optional<ProcessorDefinition> handle(Choice step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) {
    final CamelContext context = routeBuilder.getContext();
    final ChoiceDefinition choice = route.choice();

    List<Filter> filters = ObjectHelper.supplyIfEmpty(step.getFilters(), Collections::<Filter>emptyList);
    for (Filter filter : filters) {
        Predicate predicate = JsonSimpleHelpers.getMandatorySimplePredicate(context, filter, filter.getExpression());
        ChoiceDefinition when = choice.when(predicate);

        routeBuilder.addSteps(when, filter.getSteps());
    }

    Otherwise otherwiseStep = step.getOtherwise();
    if (otherwiseStep != null) {
        List<Step> otherwiseSteps = ObjectHelper.supplyIfEmpty(otherwiseStep.getSteps(), Collections::<Step>emptyList);
        if (!otherwiseSteps.isEmpty()) {
            routeBuilder.addSteps(choice.otherwise(), otherwiseSteps);
        }
    }

    return Optional.empty();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:24,代码来源:ChoiceHandler.java

示例3: handle

import org.apache.camel.Predicate; //导入依赖的package包/类
@Override
public ProcessorDefinition handle(Choice step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) {
    final CamelContext context = routeBuilder.getContext();
    final ChoiceDefinition choice = route.choice();

    List<Filter> filters = ObjectHelper.supplyIfEmpty(step.getFilters(), Collections::emptyList);
    for (Filter filter : filters) {
        Predicate predicate = JsonSimpleHelpers.getMandatorySimplePredicate(context, filter, filter.getExpression());
        ChoiceDefinition when = choice.when(predicate);

        route = routeBuilder.addSteps(when, filter.getSteps());
    }

    Otherwise otherwiseStep = step.getOtherwise();
    if (otherwiseStep != null) {
        List<Step> otherwiseSteps = ObjectHelper.supplyIfEmpty(otherwiseStep.getSteps(), Collections::emptyList);
        if (!otherwiseSteps.isEmpty()) {
            route = routeBuilder.addSteps(choice.otherwise(), otherwiseSteps);
        }
    }

    return route;
}
 
开发者ID:syndesisio,项目名称:syndesis-integration-runtime,代码行数:24,代码来源:ChoiceHandler.java

示例4: configure

import org.apache.camel.Predicate; //导入依赖的package包/类
@Override
public void configure() throws Exception {
    // you can define the endpoints and predicates here
    // it is more common to inline the endpoints and predicates in the route
    // as shown in the CreateOrderRoute

    Endpoint newOrder = endpoint("activemq:queue:newOrder");
    Predicate isWidget = xpath("/order/product = 'widget'");
    Endpoint widget = endpoint("activemq:queue:widget");
    Endpoint gadget = endpoint("activemq:queue:gadget");

    from(newOrder)
        .choice()
            .when(isWidget)
                .to("log:widget") // add a log so we can see this happening in the shell
                .to(widget)
            .otherwise()
                .to("log:gadget") // add a log so we can see this happening in the shell
                .to(gadget);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:WidgetGadgetRoute.java

示例5: testSimpleExpressionOrPredicate

import org.apache.camel.Predicate; //导入依赖的package包/类
public void testSimpleExpressionOrPredicate() throws Exception {
    Predicate predicate = SimpleLanguage.predicate("${header.bar} == 123");
    assertTrue(predicate.matches(exchange));

    predicate = SimpleLanguage.predicate("${header.bar} == 124");
    assertFalse(predicate.matches(exchange));

    Expression expression = SimpleLanguage.expression("${body}");
    assertEquals("<hello id='m123'>world!</hello>", expression.evaluate(exchange, String.class));

    expression = SimpleLanguage.simple("${body}");
    assertEquals("<hello id='m123'>world!</hello>", expression.evaluate(exchange, String.class));
    expression = SimpleLanguage.simple("${body}", String.class);
    assertEquals("<hello id='m123'>world!</hello>", expression.evaluate(exchange, String.class));

    expression = SimpleLanguage.simple("${header.bar} == 123", boolean.class);
    assertEquals(Boolean.TRUE, expression.evaluate(exchange, Object.class));
    expression = SimpleLanguage.simple("${header.bar} == 124", boolean.class);
    assertEquals(Boolean.FALSE, expression.evaluate(exchange, Object.class));
    expression = SimpleLanguage.simple("${header.bar} == 123", Boolean.class);
    assertEquals(Boolean.TRUE, expression.evaluate(exchange, Object.class));
    expression = SimpleLanguage.simple("${header.bar} == 124", Boolean.class);
    assertEquals(Boolean.FALSE, expression.evaluate(exchange, Object.class));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SimpleTest.java

示例6: contains

import org.apache.camel.Predicate; //导入依赖的package包/类
public static Predicate contains(final Expression left, final Expression right) {
    return new BinaryPredicateSupport(left, right) {

        protected boolean matches(Exchange exchange, Object leftValue, Object rightValue) {
            if (leftValue == null && rightValue == null) {
                // they are equal
                return true;
            } else if (leftValue == null || rightValue == null) {
                // only one of them is null so they are not equal
                return false;
            }

            return ObjectHelper.contains(leftValue, rightValue);
        }

        protected String getOperationText() {
            return "contains";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:PredicateBuilder.java

示例7: testOrSignatures

import org.apache.camel.Predicate; //导入依赖的package包/类
public void testOrSignatures() throws Exception {
    Predicate p1 = header("name").isEqualTo(constant("does-not-apply"));
    Predicate p2 = header("size").isGreaterThanOrEqualTo(constant(10));
    Predicate p3 = header("location").contains(constant("does-not-apply"));

    // check method signature with two parameters
    assertMatches(PredicateBuilder.or(p1, p2));
    assertMatches(PredicateBuilder.or(p2, p3));

    // check method signature with varargs
    assertMatches(PredicateBuilder.in(p1, p2, p3));
    assertMatches(PredicateBuilder.or(p1, p2, p3));

    // maybe a list of predicates?
    assertMatches(PredicateBuilder.in(Arrays.asList(p1, p2, p3)));
    assertMatches(PredicateBuilder.or(Arrays.asList(p1, p2, p3)));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:PredicateBuilderTest.java

示例8: isEqualToIgnoreCase

import org.apache.camel.Predicate; //导入依赖的package包/类
public static Predicate isEqualToIgnoreCase(final Expression left, final Expression right) {
    return new BinaryPredicateSupport(left, right) {

        protected boolean matches(Exchange exchange, Object leftValue, Object rightValue) {
            if (leftValue == null && rightValue == null) {
                // they are equal
                return true;
            } else if (leftValue == null || rightValue == null) {
                // only one of them is null so they are not equal
                return false;
            }

            return ObjectHelper.typeCoerceEquals(exchange.getContext().getTypeConverter(), leftValue, rightValue, true);
        }

        protected String getOperationText() {
            return "=~";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:PredicateBuilder.java

示例9: createRouteBuilder

import org.apache.camel.Predicate; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            Predicate goodWord = body().contains("World");

            from("direct:start")
                .to("mock:before")
                .filter(goodWord)
                    .to("mock:good")
                .end()
                .split(body().tokenize(" "), new MyAggregationStrategy())
                    .to("mock:split")
                .end()
                .to("mock:result");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:FilterBeforeSplitTest.java

示例10: testDNSWithNameHeaderAndType

import org.apache.camel.Predicate; //导入依赖的package包/类
@Test
@Ignore("Testing behind nat produces timeouts")
public void testDNSWithNameHeaderAndType() throws Exception {
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        public boolean matches(Exchange exchange) {
            Record[] record = (Record[]) exchange.getIn().getBody();
            return record[0].getName().toString().equals("www.example.com.");
        }
    });
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("dns.name", "www.example.com");
    headers.put("dns.type", "A");
    template.sendBodyAndHeaders("hello", headers);
    resultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:DnsLookupEndpointTest.java

示例11: createRouteBuilder

import org.apache.camel.Predicate; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            Predicate goodWord = body().contains("World");

            from("direct:start")
                .filter(goodWord)
                    .to("mock:filtered")
                    .aggregate(header("id"), new MyAggregationStrategy()).completionTimeout(1000)
                        .to("mock:result")
                    .end()
                .end();

        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:AggregateShouldSkipFilteredExchangesTest.java

示例12: handle

import org.apache.camel.Predicate; //导入依赖的package包/类
@Override
public Optional<ProcessorDefinition> handle(Filter step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) {
    CamelContext context = routeBuilder.getContext();
    Predicate predicate = JsonSimpleHelpers.getMandatorySimplePredicate(context, step, step.getExpression());
    FilterDefinition filter = route.filter(predicate);

    routeBuilder.addSteps(filter, step.getSteps());

    return Optional.empty();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:FilterHandler.java

示例13: handle

import org.apache.camel.Predicate; //导入依赖的package包/类
@Override
public ProcessorDefinition handle(Filter step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) {
  CamelContext context = routeBuilder.getContext();
  Predicate predicate = JsonSimpleHelpers.getMandatorySimplePredicate(context, step, step.getExpression());
  FilterDefinition filter = route.filter(predicate);
  return routeBuilder.addSteps(filter, step.getSteps());
}
 
开发者ID:syndesisio,项目名称:syndesis-integration-runtime,代码行数:8,代码来源:FilterHandler.java

示例14: testDNSWithNameHeader

import org.apache.camel.Predicate; //导入依赖的package包/类
@Test
@Ignore("Testing behind nat produces timeouts")
public void testDNSWithNameHeader() throws Exception {
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        public boolean matches(Exchange exchange) {
            Record[] record = (Record[]) exchange.getIn().getBody();
            return record[0].getName().toString().equals("www.example.com.");
        }
    });
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("dns.name", "www.example.com");
    template.sendBodyAndHeaders("hello", headers);
    resultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:DnsLookupEndpointTest.java

示例15: testSimpleEqFunctionFunction

import org.apache.camel.Predicate; //导入依赖的package包/类
public void testSimpleEqFunctionFunction() throws Exception {
    exchange.getIn().setBody(122);
    exchange.getIn().setHeader("val", 122);

    SimplePredicateParser parser = new SimplePredicateParser("${body} == ${header.val}", true);
    Predicate pre = parser.parsePredicate();

    assertTrue("Should match", pre.matches(exchange));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:SimpleParserPredicateTest.java


注:本文中的org.apache.camel.Predicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。