class TextPatternValidationUtils {

    public static boolean validateTextPatternValue( TextPattern textPattern, String value )
    {
        StringBuilder builder = new StringBuilder();

        builder.append( "^" );

        textPattern.getSegments().forEach(
            ( segment ) -> builder.append( segment.getMethod().getType().getValueRegex( segment.getParameter() ) ) );

        builder.append( "$" );

        return Pattern.compile( builder.toString() ).matcher( value ).matches();
    }

}