package com.cron.utils.parser.field;

import org.apache.commons.lang3.StringUtils;

/*
 * Copyright 2014 jmrozanec
 * Licensed 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.
 */
/**
 * Parses a field from a cron expression.
 */
class FieldParser {
    private final char[] specialCharsMinusStar = new char[]{'/', '-', ','};

    private FieldConstraints constraints;

    FieldParser() {
        constraints = FieldConstraints.nullConstraints();
    }

    CronFieldExpression parse(String expression) {
        if (!StringUtils.containsAny(expression, specialCharsMinusStar)) {
            if ("*".equals(expression)) {
                return new Always(constraints);
            } else {
                return new On(constraints, expression);
            }
        } else {
            String[] array = expression.split(",");
            if (array.length > 1) {
                And and = new And();
                for (String exp : array) {
                    and.and(parse(exp));
                }
                return and;
            } else {
                array = expression.split("-");
                if (array.length > 1) {
                    if (array[1].contains("/")) {
                        String[] every = array[1].split("/");
                        return new Between(constraints, array[0], every[0], every[1]);
                    } else {
                        return new Between(constraints, array[0], array[1]);
                    }
                } else {
                    return new Every(constraints, expression.split("/")[1]);
                }
            }
        }
    }


    FieldParser withConstraints(FieldConstraints constraints) {
        this.constraints = constraints;
        return this;
    }
}

@@ -802,16 +802,39 @@
 ', ','%7D;
+//universally supported
 %0A%0A    pr
@@ -878,88 +878,378 @@
     
-FieldParser() %7B%0A        constraints = FieldConstraints.nullConstraints();%0A    %7D%0A
+/**%0A     * Default constructor.%0A     * Default FieldConstraints are initialized.%0A     */%0A    FieldParser() %7B%0A        constraints = FieldConstraints.nullConstraints();%0A    %7D%0A%0A    /**%0A     * Parse given expression for a single cron field%0A     * @param expression - String%0A     * @return CronFieldExpression object that with interpretation of given String parameter%0A     */
 %0A   
@@ -1408,24 +1408,52 @@
 pression)) %7B
+//all crons support asterisk
 %0A           
@@ -2438,16 +2438,274 @@
 %0A    %7D%0A%0A
+    /**%0A     * Add field constraints for parser.%0A     * This enables to check if values are supported as well%0A     * as if specified numbers are in expected range%0A     * @param constraints - FieldConstraints%0A     * @return FieldParser - this instance%0A     */
 %0A    Fie

Add FieldParser comments