class FhirToDhisOptionSetUtils {

    @Nonnull
    public static List<String> resolveIntegerOptionCodes( @Nonnull OptionSet optionSet, @Nullable Pattern pattern ) throws TransformerScriptException
    {
        final Pattern resultingPattern = (pattern == null) ? ALL : pattern;
        final SortedMap<Integer, String> options = new TreeMap<>();
        for ( final Option option : optionSet.getOptions() )
        {
            final String code, value;
            if ( pattern == null )
            {
                code = value = option.getCode();
            }
            else
            {
                code = option.getCode();
                value = getIntegerOptionCode( code, resultingPattern );
            }
            if ( value != null )
            {
                try
                {
                    if ( options.put( Integer.parseInt( value ), code ) != null )
                    {
                        throw new TransformerScriptException( "Pattern to resolveRule integer options results in duplicate integer value " + value + ": " + resultingPattern.pattern() );
                    }
                }
                catch ( NumberFormatException e )
                {
                    throw new TransformerScriptException( "Pattern to resolveRule integer options results in non-integer value \"" + value + "\": " + resultingPattern.pattern() );
                }
            }
        }

        validateAscendingIntegerOptions( options, resultingPattern );
        return new ArrayList<>( options.values() );
    }

    private  FhirToDhisOptionSetUtils();

}