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

com.github.mkolisnyk.aerial.expressions.value.StringRegexpValueExpression 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 com.github.mkolisnyk.aerial.document.InputRecord;
import com.github.mkolisnyk.aerial.expressions.ValueExpression;
import com.github.mkolisnyk.aerial.expressions.ValueExpressionType;
import com.mifmif.common.regex.Generex;

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

    /**
     * @param inputValue
     */
    public StringRegexpValueExpression(InputRecord inputValue) {
        super(inputValue);
        // TODO Auto-generated constructor stub
    }

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


    /* (non-Javadoc)
     * @see com.github.mkolisnyk.aerial.expressions.ValueExpression#generate()
     */
    @Override
    public List generate() throws Exception {
        List result = new ArrayList();
        // Generated valid string
        Generex generex = new Generex(this.getInput().getValue());
        String value = "";
        InputRecord testRecord = this.getInput();
        for (int i = 0; i < 2; i++) {
            value = generex.random(1);
            result.add(
                    new InputRecord(
                            testRecord.getName(),
                            testRecord.getType(),
                            value,
                            testRecord.getCondition(),
                            value.matches(testRecord.getValue()))
            );
        }
        // Empty string
        value = "";
        result.add(
                new InputRecord(
                        testRecord.getName(),
                        testRecord.getType(),
                        value,
                        testRecord.getCondition(),
                        value.matches(testRecord.getValue()))
        );
        // Doubled string (repetitive pattern)
        value = generex.random(1);
        value = value.concat(value);
        result.add(
                new InputRecord(
                        testRecord.getName(),
                        testRecord.getType(),
                        value,
                        testRecord.getCondition(),
                        value.matches(testRecord.getValue()))
        );
        // Pattern itself
        result.add(
                new InputRecord(
                    testRecord.getName(),
                    testRecord.getType(),
                    testRecord.getValue(),
                    testRecord.getCondition(),
                    testRecord.getValue().matches(testRecord.getValue()))
                );
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy