Package com.asakusafw.testdriver.excel.ExcelRuleExtractor

Examples of com.asakusafw.testdriver.excel.ExcelRuleExtractor.FormatException


            return new DecimalCompare(operator);
        case DATE:
        case DATETIME:
            return new CalendarCompare(operator);
        default:
            throw new FormatException(MessageFormat.format(
                    "Property does not support compare(\"{0}\") expression: {1}",
                    operator.getSymbol(),
                    name));
        }
    }
View Full Code Here


        if (expression.trim().startsWith(TRIGGER) == false) {
            return null;
        }
        Matcher matcher = PATTERN.matcher(expression);
        if (matcher.matches() == false) {
            throw new FormatException(MessageFormat.format(
                    "Invalid approx(~) expression: {0}",
                    name));
        }
        String sign = matcher.group(1);
        boolean plus = sign == null || sign.equals(SIGN_PLUS);
        boolean minus = sign == null || sign.equals(SIGN_MINUS);
        String magnitude = matcher.group(2).trim();

        switch (type) {
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
            try {
                long value = Long.parseLong(magnitude);
                return Predicates.integerRange(minus ? -value : 0, plus ? +value : 0);
            } catch (NumberFormatException e) {
                throw new FormatException(MessageFormat.format(
                        "Invalid approx(~) error \"{1}\": {0}",
                        name,
                        magnitude), e);
            }
        case FLOAT:
        case DOUBLE:
            try {
                double value = Double.parseDouble(magnitude);
                return Predicates.floatRange(minus ? -value : 0, plus ? +value : 0);
            } catch (NumberFormatException e) {
                throw new FormatException(MessageFormat.format(
                        "Invalid approx(~) value \"{1}\": {0}",
                        name,
                        magnitude), e);
            }
        case DECIMAL:
            try {
                BigDecimal value = new BigDecimal(magnitude);
                return Predicates.decimalRange(
                        minus ? value.negate() : BigDecimal.ZERO,
                        plus ? value : BigDecimal.ZERO);
            } catch (NumberFormatException e) {
                throw new FormatException(MessageFormat.format(
                        "Invalid approx(~) error \"{1}\": {0}",
                        name,
                        magnitude), e);
            }
        case DATE:
        case DATETIME:
            try {
                int value = Integer.parseInt(magnitude);
                if (type == PropertyType.DATE) {
                    return Predicates.dateRange(minus ? -value : 0, plus ? +value : 0);
                } else {
                    return Predicates.timeRange(minus ? -value : 0, plus ? +value : 0);
                }
            } catch (NumberFormatException e) {
                throw new FormatException(MessageFormat.format(
                        "Invalid approx(~) error \"{1}\": {0}",
                        name,
                        magnitude), e);
            }
        default:
            throw new FormatException(MessageFormat.format(
                    "Property does not support approx(~) expression: {0}",
                    name));
        }
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.testdriver.excel.ExcelRuleExtractor.FormatException

Copyright © 2018 www.massapicom. 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.