All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jscl.text.MinusParser Maven / Gradle / Ivy

package jscl.text;

import jscl.math.Generic;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * User: serso
 * Date: 10/27/11
 * Time: 2:44 PM
 */
class MinusParser implements Parser {

    public static final Parser parser = new MinusParser();

    private MinusParser() {
    }

    @NotNull
    public Result parse(@NotNull Parameters p, @Nullable Generic previousSumElement) {
        final boolean result;

        int pos0 = p.getPosition().intValue();

        ParserUtils.skipWhitespaces(p);

        if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '-') {
            result = true;
            p.getPosition().increment();
        } else {
            result = false;
            p.getPosition().setValue(pos0);
        }

        return new Result(result);
    }

    public static class Result {
        private final boolean sign;

        public Result(boolean sign) {
            this.sign = sign;
        }

        public boolean isSign() {
            return sign;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy