package io.vrap.rmf.raml.model.values;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * This class provides an interface to a javascript regular expression hosted in a
 * javascript engine context.
 */
public class JavaRegExp implements RegExp {
    private final Pattern compiledPattern;
    private final String pattern;

    private JavaRegExp(final String pattern) {
        this.pattern = pattern;
        try {
            if (!pattern.equals("")) {
                compiledPattern = Pattern.compile(pattern);
            } else {
                compiledPattern = null;
            }
        } catch (PatternSyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }

    public boolean test(final String value) {
        if (compiledPattern == null) {
            return true;
        }
        final Matcher matcher = compiledPattern.matcher(value);
        return matcher.matches();
    }

    public String toString() {
        return pattern;
    }

    public static RegExp of(final String pattern) {
        return new JavaRegExp(pattern);
    }
}

@@ -149,129 +149,8 @@
 n;%0A%0A
-/**%0A * This class provides an interface to a javascript regular expression hosted in a%0A * javascript engine context.%0A */%0A
 publ

update RegEx class docs