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


Java Predicate.matches方法代码示例

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


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

示例1: createAndExpression

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private Expression createAndExpression(final Expression leftExp, final Expression rightExp) {
    return new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> type) {
            Predicate predicate = ExpressionToPredicateAdapter.toPredicate(leftExp);
            predicate = PredicateBuilder.and(predicate, ExpressionToPredicateAdapter.toPredicate(rightExp));

            boolean answer = predicate.matches(exchange);
            return exchange.getContext().getTypeConverter().convertTo(type, answer);
        }

        @Override
        public String toString() {
            return left + " " + token.getText() + " " + right;
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:LogicalExpression.java

示例2: createOrExpression

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private Expression createOrExpression(final Expression leftExp, final Expression rightExp) {
    return new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> type) {
            Predicate predicate = ExpressionToPredicateAdapter.toPredicate(leftExp);
            predicate = PredicateBuilder.or(predicate, ExpressionToPredicateAdapter.toPredicate(rightExp));

            boolean answer = predicate.matches(exchange);
            return exchange.getContext().getTypeConverter().convertTo(type, answer);
        }

        @Override
        public String toString() {
            return left + " " + token.getText() + " " + right;
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:LogicalExpression.java

示例3: createRegexExpression

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private Expression createRegexExpression(final Expression leftExp, final Expression rightExp) {
    return new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> type) {
            // reg ex should use String pattern, so we evaluate the right hand side as a String
            Predicate predicate = PredicateBuilder.regex(leftExp, rightExp.evaluate(exchange, String.class));
            if (operator == BinaryOperatorType.NOT_REGEX) {
                predicate = PredicateBuilder.not(predicate);
            }
            boolean answer = predicate.matches(exchange);
            return exchange.getContext().getTypeConverter().convertTo(type, answer);
        }

        @Override
        public String toString() {
            return left + " " + token.getText() + " " + right;
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:BinaryExpression.java

示例4: toProcessor

import org.apache.camel.Predicate; //导入方法依赖的package包/类
@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);
        }
    };

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

示例5: shouldRedeliver

import org.apache.camel.Predicate; //导入方法依赖的package包/类
/**
 * Returns true if the policy decides that the message exchange should be
 * redelivered.
 *
 * @param exchange  the current exchange
 * @param redeliveryCounter  the current retry counter
 * @param retryWhile  an optional predicate to determine if we should redeliver or not
 * @return true to redeliver, false to stop
 */
public boolean shouldRedeliver(Exchange exchange, int redeliveryCounter, Predicate retryWhile) {
    // predicate is always used if provided
    if (retryWhile != null) {
        return retryWhile.matches(exchange);
    }

    if (getMaximumRedeliveries() < 0) {
        // retry forever if negative value
        return true;
    }
    // redeliver until we hit the max
    return redeliveryCounter <= getMaximumRedeliveries();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:RedeliveryPolicy.java

示例6: doAssertMatches

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private static void doAssertMatches(Predicate predicate, String text, Exchange exchange) {
    if (!predicate.matches(exchange)) {
        if (text == null) {
            throw new AssertionError(predicate + " on " + exchange);
        } else {
            throw new AssertionError(text + predicate + " on " + exchange);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:PredicateAssertHelper.java

示例7: createIsExpression

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private Expression createIsExpression(final String expression, final Expression leftExp, final Expression rightExp) {
    return new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> type) {
            Predicate predicate;
            String name = rightExp.evaluate(exchange, String.class);
            if (name == null || "null".equals(name)) {
                throw new SimpleIllegalSyntaxException(expression, right.getToken().getIndex(), operator + " operator cannot accept null. A class type must be provided.");
            }
            Class<?> rightType = exchange.getContext().getClassResolver().resolveClass(name);
            if (rightType == null) {
                throw new SimpleIllegalSyntaxException(expression, right.getToken().getIndex(), operator + " operator cannot find class with name: " + name);
            }

            predicate = PredicateBuilder.isInstanceOf(leftExp, rightType);
            if (operator == BinaryOperatorType.NOT_IS) {
                predicate = PredicateBuilder.not(predicate);
            }
            boolean answer = predicate.matches(exchange);

            return exchange.getContext().getTypeConverter().convertTo(type, answer);
        }

        @Override
        public String toString() {
            return left + " " + token.getText() + " " + right;
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:30,代码来源:BinaryExpression.java

示例8: createInExpression

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private Expression createInExpression(final Expression leftExp, final Expression rightExp) {
    return new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> type) {
            // okay the in operator is a bit more complex as we need to build a list of values
            // from the right hand side expression.
            // each element on the right hand side must be separated by comma (default for create iterator)
            Iterator<Object> it = ObjectHelper.createIterator(rightExp.evaluate(exchange, Object.class));
            List<Object> values = new ArrayList<Object>();
            while (it.hasNext()) {
                values.add(it.next());
            }
            // then reuse value builder to create the in predicate with the list of values
            ValueBuilder vb = new ValueBuilder(leftExp);
            Predicate predicate = vb.in(values.toArray());
            if (operator == BinaryOperatorType.NOT_IN) {
                predicate = PredicateBuilder.not(predicate);
            }
            boolean answer = predicate.matches(exchange);
            return exchange.getContext().getTypeConverter().convertTo(type, answer);
        }

        @Override
        public String toString() {
            return left + " " + token.getText() + " " + right;
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:BinaryExpression.java

示例9: createRangeExpression

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private Expression createRangeExpression(final String expression, final Expression leftExp, final Expression rightExp) {
    return new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> type) {
            Predicate predicate;

            String range = rightExp.evaluate(exchange, String.class);
            Matcher matcher = RANGE_PATTERN.matcher(range);
            if (matcher.matches()) {
                // wrap as constant expression for the from and to values
                Expression from = ExpressionBuilder.constantExpression(matcher.group(1));
                Expression to = ExpressionBuilder.constantExpression(matcher.group(3));

                // build a compound predicate for the range
                predicate = PredicateBuilder.isGreaterThanOrEqualTo(leftExp, from);
                predicate = PredicateBuilder.and(predicate, PredicateBuilder.isLessThanOrEqualTo(leftExp, to));
            } else {
                throw new SimpleIllegalSyntaxException(expression, right.getToken().getIndex(), operator + " operator is not valid. Valid syntax:'from..to' (where from and to are numbers).");
            }
            if (operator == BinaryOperatorType.NOT_RANGE) {
                predicate = PredicateBuilder.not(predicate);
            }

            boolean answer = predicate.matches(exchange);
            return exchange.getContext().getTypeConverter().convertTo(type, answer);
        }

        @Override
        public String toString() {
            return left + " " + token.getText() + " " + right;
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:BinaryExpression.java

示例10: createExpression

import org.apache.camel.Predicate; //导入方法依赖的package包/类
private Expression createExpression(final Expression left, final Expression right, final Predicate predicate) {
    return new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> type) {
            boolean answer = predicate.matches(exchange);
            return exchange.getContext().getTypeConverter().convertTo(type, answer);
        }

        @Override
        public String toString() {
            return left + " " + token.getText() + " " + right;
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:BinaryExpression.java

示例11: not

import org.apache.camel.Predicate; //导入方法依赖的package包/类
/**
 * A helper method to return the logical not of the given predicate
 */
public static Predicate not(final Predicate predicate) {
    notNull(predicate, "predicate");
    return new Predicate() {
        public boolean matches(Exchange exchange) {
            return !predicate.matches(exchange);
        }

        @Override
        public String toString() {
            return "not (" + predicate + ")";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:PredicateBuilder.java

示例12: and

import org.apache.camel.Predicate; //导入方法依赖的package包/类
/**
 * A helper method to combine multiple predicates by a logical AND
 */
public static Predicate and(final Predicate left, final Predicate right) {
    notNull(left, "left");
    notNull(right, "right");
    return new Predicate() {
        public boolean matches(Exchange exchange) {
            return left.matches(exchange) && right.matches(exchange);
        }

        @Override
        public String toString() {
            return "(" + left + ") and (" + right + ")";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:PredicateBuilder.java

示例13: or

import org.apache.camel.Predicate; //导入方法依赖的package包/类
/**
 * A helper method to combine two predicates by a logical OR.
 * If you want to combine multiple predicates see {@link #in(Predicate...)}
 */
public static Predicate or(final Predicate left, final Predicate right) {
    notNull(left, "left");
    notNull(right, "right");
    return new Predicate() {
        public boolean matches(Exchange exchange) {
            return left.matches(exchange) || right.matches(exchange);
        }

        @Override
        public String toString() {
            return "(" + left + ") or (" + right + ")";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:PredicateBuilder.java

示例14: assertPredicate

import org.apache.camel.Predicate; //导入方法依赖的package包/类
/**
 * Asserts that the predicate returns the expected value on the exchange
 */
public static boolean assertPredicate(final Predicate predicate, Exchange exchange, boolean expected) {
    if (expected) {
        PredicateAssertHelper.assertMatches(predicate, "Predicate failed: ", exchange);
    }
    boolean value = predicate.matches(exchange);

    LOG.debug("Evaluated predicate: " + predicate + " on exchange: " + exchange + " result: " + value);

    assertEquals("Predicate: " + predicate + " on Exchange: " + exchange, expected, value);
    return value;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:TestSupport.java

示例15: assertPredicate

import org.apache.camel.Predicate; //导入方法依赖的package包/类
/**
 * Asserts that the predicate returns the expected value on the exchange
 */
public static boolean assertPredicate(final Predicate predicate, Exchange exchange, boolean expected) {
    if (expected) {
        PredicateAssertHelper.assertMatches(predicate, "Predicate failed: ", exchange);
    }
    boolean value = predicate.matches(exchange);

    LOG.debug("Evaluated predicate: " + predicate + " on exchange: " + exchange + " result: " + value);

    assertEquals(value, expected, "Predicate: " + predicate + " on Exchange: " + exchange);
    return value;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:TestSupport.java


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