@Test public void resolveIntegerOption() { final WritableOptionSet optionSet = new WritableOptionSet(); optionSet.setOptions( Arrays.asList( new WritableOption( "2", "Test X" ), new WritableOption( "1", "Test Y" ), new WritableOption( "3", "Test Z" ) ) ); final List<String> codes = FhirToDhisOptionSetUtils.resolveIntegerOptionCodes( optionSet, null ); Assert.assertThat( codes, Matchers.contains( "1", "2", "3" ) ); }
@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() ); }
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() ); } }
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(); }
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(); @Nullable static String getIntegerOptionCode( @Nullable String code, @Nullable Pattern pattern ); @Nonnull static List<String> resolveIntegerOptionCodes( @Nonnull OptionSet optionSet, @Nullable Pattern pattern ); }
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(); @Nullable static String getIntegerOptionCode( @Nullable String code, @Nullable Pattern pattern ); @Nonnull static List<String> resolveIntegerOptionCodes( @Nonnull OptionSet optionSet, @Nullable Pattern pattern );  }