Examples of LiteralFunction


Examples of org.springmodules.validation.valang.functions.LiteralFunction

        } else if (getOperator() instanceof Operator.InOperator) {
            Collection predicates = new ArrayList();
            for (Iterator iter = getIterator(rightValue); iter.hasNext();) {
                Object o = iter.next();
                if (o instanceof Function) {
                    predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR, (Function) o, getLine(), getColumn()));
                } else {
                    predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR, new LiteralFunction(o), getLine(), getColumn()));
                }
            }
            if (predicates.isEmpty()) {
                throw new IllegalStateException("IN expression contains no elements!");
            } else if (predicates.size() == 1) {
                predicates.add(FalsePredicate.getInstance());
            }
            return AnyPredicate.getInstance(predicates).evaluate(target);
        } else if (getOperator() instanceof Operator.NotInOperator) {
            Collection predicates = new ArrayList();
            for (Iterator iter = getIterator(rightValue); iter.hasNext();) {
                Object o = iter.next();
                if (o instanceof Function) {
                    predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR, (Function) o, getLine(), getColumn()));
                } else {
                    predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR, new LiteralFunction(o), getLine(), getColumn()));
                }
            }
            if (predicates.isEmpty()) {
                throw new IllegalStateException("NOT IN expression contains no elements!");
            } else if (predicates.size() == 1) {
                predicates.add(FalsePredicate.getInstance());
            }
            return !AnyPredicate.getInstance(predicates).evaluate(target);
        } else if (getOperator() instanceof Operator.BetweenOperator) {
            Object[] array = getArray(rightValue);
            Predicate predicate1 = getPredicate(new LiteralFunction(leftValue), OperatorConstants.MORE_THAN_OR_EQUAL_OPERATOR, (Function) array[0], getLine(), getColumn());
            Predicate predicate2 = getPredicate(new LiteralFunction(leftValue), OperatorConstants.LESS_THAN_OR_EQUAL_OPERATOR, (Function) array[1], getLine(), getColumn());
            return AndPredicate.getInstance(predicate1, predicate2).evaluate(target);
        } else if (getOperator() instanceof Operator.NotBetweenOperator) {
            Object[] array = getArray(rightValue);
            Predicate predicate1 = getPredicate(new LiteralFunction(leftValue), OperatorConstants.MORE_THAN_OR_EQUAL_OPERATOR, (Function) array[0], getLine(), getColumn());
            Predicate predicate2 = getPredicate(new LiteralFunction(leftValue), OperatorConstants.LESS_THAN_OR_EQUAL_OPERATOR, (Function) array[1], getLine(), getColumn());
            return !AndPredicate.getInstance(predicate1, predicate2).evaluate(target);
        } else if (getOperator() instanceof Operator.HasLengthOperator) {
            return StringUtils.hasLength(leftValue != null ? leftValue.toString() : null);
        } else if (getOperator() instanceof Operator.HasNoLengthOperator) {
            return !StringUtils.hasLength(leftValue != null ? leftValue.toString() : null);
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

        assertFalse(5, OperatorConstants.MORE_THAN_OR_EQUAL_OPERATOR, 6);
    }

    public void testStringInNotInOperatorSuccess() {
        Collection coll = new ArrayList();
        coll.add(new LiteralFunction(new BigDecimal("1")));
        coll.add(new LiteralFunction(new BigDecimal("2")));
        coll.add(new LiteralFunction(new BigDecimal("3")));
        coll.add(new LiteralFunction(new BigDecimal("4")));
        coll.add(new LiteralFunction(new BigDecimal("5")));

        assertTrue(5, OperatorConstants.IN_OPERATOR, coll);
        assertFalse(6, OperatorConstants.IN_OPERATOR, coll);
        assertTrue(5, OperatorConstants.IN_OPERATOR, coll.iterator());
        assertFalse(6, OperatorConstants.IN_OPERATOR, coll.iterator());
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

        assertFalse(5, OperatorConstants.NOT_IN_OPERATOR, coll.toArray());
    }

    public void testBetweenNotBetweenOperatorSuccess() {
        Collection coll = new ArrayList();
        coll.add(new LiteralFunction(new BigDecimal("1")));
        coll.add(new LiteralFunction(new BigDecimal("5")));

        assertTrue(5, OperatorConstants.BETWEEN_OPERATOR, coll);
        assertFalse(6, OperatorConstants.BETWEEN_OPERATOR, coll);
        assertTrue(5, OperatorConstants.BETWEEN_OPERATOR, coll.iterator());
        assertFalse(6, OperatorConstants.BETWEEN_OPERATOR, coll.iterator());
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

        }
    }

    public void testInNotInOperatorSuccess() {
        Collection coll = new ArrayList();
        coll.add(new LiteralFunction("one"));
        coll.add(new LiteralFunction("two"));
        coll.add(new LiteralFunction("three"));
        coll.add(new LiteralFunction("four"));
        coll.add(new LiteralFunction("five"));

        assertTrue("five", OperatorConstants.IN_OPERATOR, coll);
        assertFalse("six", OperatorConstants.IN_OPERATOR, coll);

        assertTrue("six", OperatorConstants.NOT_IN_OPERATOR, coll);
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

            return this.value;
        }
    }

    private boolean runTest(Object leftValue, Operator operator, Object rightValue) {
        return new GenericTestPredicate(new BeanPropertyFunction("value"), operator, new LiteralFunction(rightValue), 0, 0).evaluate(new GenericContainer(leftValue));
    }
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

        assertFalse(5, Operator.GREATER_THAN_OR_EQUAL, 6);
    }

    public void testStringInNotInOperatorSuccess() {
        Collection coll = new ArrayList();
        coll.add(new LiteralFunction(new BigDecimal("1")));
        coll.add(new LiteralFunction(new BigDecimal("2")));
        coll.add(new LiteralFunction(new BigDecimal("3")));
        coll.add(new LiteralFunction(new BigDecimal("4")));
        coll.add(new LiteralFunction(new BigDecimal("5")));

        assertTrue(5, Operator.IN, coll);
        assertFalse(6, Operator.IN, coll);
        assertTrue(5, Operator.IN, coll.iterator());
        assertFalse(6, Operator.IN, coll.iterator());
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

        assertFalse(5, Operator.NOT_IN, coll.toArray());
    }

    public void testBetweenNotBetweenOperatorSuccess() {
        Collection coll = new ArrayList();
        coll.add(new LiteralFunction(new BigDecimal("1")));
        coll.add(new LiteralFunction(new BigDecimal("5")));

        assertTrue(5, Operator.BETWEEN, coll);
        assertFalse(6, Operator.BETWEEN, coll);
        assertTrue(5, Operator.BETWEEN, coll.iterator());
        assertFalse(6, Operator.BETWEEN, coll.iterator());
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

        }
    }

    public void testInNotInOperatorSuccess() {
        Collection coll = new ArrayList();
        coll.add(new LiteralFunction("one"));
        coll.add(new LiteralFunction("two"));
        coll.add(new LiteralFunction("three"));
        coll.add(new LiteralFunction("four"));
        coll.add(new LiteralFunction("five"));

        assertTrue("five", Operator.IN, coll);
        assertFalse("six", Operator.IN, coll);

        assertTrue("six", Operator.NOT_IN, coll);
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

            return this.value;
        }
    }

    private boolean runTest(Object leftValue, Operator operator, Object rightValue) {
        return new GenericTestPredicate(new BeanPropertyFunction("value"), operator, new LiteralFunction(rightValue), 0, 0).evaluate(new GenericContainer(leftValue));
    }
View Full Code Here

Examples of org.springmodules.validation.valang.functions.LiteralFunction

        Object leftValue = getLeftFunction().getResult(target);
        Object rightValue = (getRightFunction() != null ? getRightFunction().getResult(target) : null);

        Object[] array = getArray(rightValue);
       
        Predicate predicate1 = new GreaterThanOrEqualTestPredicate(new LiteralFunction(leftValue), Operator.GREATER_THAN_OR_EQUAL, (Function) array[0], getLine(), getColumn());
        Predicate predicate2 = new LessThanOrEqualTestPredicate(new LiteralFunction(leftValue), Operator.LESS_THAN_OR_EQUAL, (Function) array[1], getLine(), getColumn());

        return AndPredicate.getInstance(predicate1, predicate2).evaluate(target);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.