class DefaultTextPatternService implements TextPatternService {

    @Override
    public String resolvePattern( TextPattern pattern, Map<String, String> values )
        throws TextPatternGenerationException
    {
        StringBuilder resolvedPattern = new StringBuilder();

        for ( TextPatternSegment segment : pattern.getSegments() )
        {
            if ( isRequired( segment ) )
            {
                resolvedPattern.append( handleRequiredValue( segment, getSegmentValue( segment, values ) ) );
            }
            else if ( isOptional( segment ) )
            {
                resolvedPattern.append( handleOptionalValue( segment, getSegmentValue( segment, values ) ) );
            }
            else
            {
                resolvedPattern.append( handleFixedValues( segment ) );
            }
        }

        return resolvedPattern.toString();
    }

}