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