@Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Integer.class)).build(); IntegerConverter converter = new IntegerConverter(); converter.convert("", context); assertThat(context.getSupportedFormats()).contains("<int> (IntegerConverter)", "MIN_VALUE (IntegerConverter)", "MAX_VALUE (IntegerConverter)"); }
@Override public Integer convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<int>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX"); if(value==null){ return null; } String trimmed = value.trim(); switch(trimmed.toUpperCase(Locale.ENGLISH)){ case "MIN_VALUE": case "MIN": return Integer.MIN_VALUE; case "MAX_VALUE": case "MAX": return Integer.MAX_VALUE; default: try { return Integer.decode(trimmed); } catch(Exception e) { LOG.finest("Unparseable Integer createValue: " + trimmed); return null; } } }
IntegerConverter implements PropertyConverter<Integer> { @Override public Integer convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<int>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX"); if(value==null){ return null; } String trimmed = value.trim(); switch(trimmed.toUpperCase(Locale.ENGLISH)){ case "MIN_VALUE": case "MIN": return Integer.MIN_VALUE; case "MAX_VALUE": case "MAX": return Integer.MAX_VALUE; default: try { return Integer.decode(trimmed); } catch(Exception e) { LOG.finest("Unparseable Integer createValue: " + trimmed); return null; } } } }
IntegerConverter implements PropertyConverter<Integer> { @Override public Integer convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<int>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX"); if(value==null){ return null; } String trimmed = value.trim(); switch(trimmed.toUpperCase(Locale.ENGLISH)){ case "MIN_VALUE": case "MIN": return Integer.MIN_VALUE; case "MAX_VALUE": case "MAX": return Integer.MAX_VALUE; default: try { return Integer.decode(trimmed); } catch(Exception e) { LOG.finest("Unparseable Integer createValue: " + trimmed); return null; } } }  }
IntegerConverter implements PropertyConverter<Integer> { @Override public Integer convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<int>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX"); if(value==null){ return null; } String trimmed = value.trim(); switch(trimmed.toUpperCase(Locale.ENGLISH)){ case "MIN_VALUE": case "MIN": return Integer.MIN_VALUE; case "MAX_VALUE": case "MAX": return Integer.MAX_VALUE; default: try { return Integer.decode(trimmed); } catch(Exception e) { LOG.finest("Unparseable Integer createValue: " + trimmed); return null; } } }  @Override Integer convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode(); }
IntegerConverter implements PropertyConverter<Integer> { @Override public Integer convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<int>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX"); if(value==null){ return null; } String trimmed = value.trim(); switch(trimmed.toUpperCase(Locale.ENGLISH)){ case "MIN_VALUE": case "MIN": return Integer.MIN_VALUE; case "MAX_VALUE": case "MAX": return Integer.MAX_VALUE; default: try { return Integer.decode(trimmed); } catch(Exception e) { LOG.finest("Unparseable Integer createValue: " + trimmed); return null; } } }  @Override Integer convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }