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

com.github.mkolisnyk.aerial.expressions.value.SingleNumericValueExpression Maven / Gradle / Ivy

There is a newer version: 0.0.6.1
Show newest version
/**
 * .
 */
package com.github.mkolisnyk.aerial.expressions.value;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;

import com.github.mkolisnyk.aerial.document.InputRecord;
import com.github.mkolisnyk.aerial.expressions.ValueExpression;
import com.github.mkolisnyk.aerial.expressions.ValueExpressionType;

/**
 * @author Myk Kolisnyk
 *
 */
public class SingleNumericValueExpression extends ValueExpression {

    /**
     * @param inputValue
     */
    public SingleNumericValueExpression(InputRecord inputValue) {
        super(inputValue);
    }

    /* (non-Javadoc)
     * @see com.github.mkolisnyk.aerial.expressions.ValueExpression#generate()
     */
    @Override
    public List generate() throws Exception {
        List result = new ArrayList();
        InputRecord testRecord = (InputRecord) this.getInput().clone();
        this.validate();
        // Value is set explicitly
        result.add(testRecord);
        result.add(nonCurrentValue(this.getInput()));
        return result;
    }

    private InputRecord nonCurrentValue(InputRecord input) {
        InputRecord testRecord;
        Integer intValue = new Integer(input.getValue());
        String updatedValue = "";
        if (intValue == 0) {
            updatedValue = "-1";
        } else {
            updatedValue = "0";
        }
        testRecord = new InputRecord(
                input.getName(),
                input.getType(),
                updatedValue,
                input.getCondition(),
                false);
        return testRecord;
    }

    /* (non-Javadoc)
     * @see com.github.mkolisnyk.aerial.expressions.ValueExpression#getValueType()
     */
    @Override
    public ValueExpressionType getValueType() {
        return ValueExpressionType.INTEGER;
    }

    /* (non-Javadoc)
     * @see com.github.mkolisnyk.aerial.expressions.ValueExpression#getMatchPattern()
     */
    @Override
    public String getMatchPattern() {
        return "(([-0-9])(\\d*))";
    }

    /* (non-Javadoc)
     * @see com.github.mkolisnyk.aerial.expressions.ValueExpression#validate()
     */
    @Override
    public void validate() throws Exception {
        super.validate();
        Assert.assertFalse("Unique attribute isn't applicable for fixed value",
                this.getInput().isUnique());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy