@Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Boolean.class)).build(); BooleanConverter converter = new BooleanConverter(); converter.convert("", context); assertThat(context.getSupportedFormats()).contains("true (ignore case) (BooleanConverter)", "false (ignore case) (BooleanConverter)"); }
@Override public Boolean convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "yes (ignore case)", "y (ignore case)", "true (ignore case)", "t (ignore case)", "1", "no (ignore case)", "n (ignore case)", "false (ignore case)", "f (ignore case)", "0"); if(value==null){ return null; } String ignoreCaseValue = value.trim() .toLowerCase(Locale.ENGLISH); switch(ignoreCaseValue) { case "1": case "yes": case "y": case "true": case "t": case "on": return Boolean.TRUE; case "no": case "n": case "false": case "f": case "0": case "off": return Boolean.FALSE; default: LOG.finest("Unknown boolean createValue encountered: " + value); } return null; }
BooleanConverter implements PropertyConverter<Boolean> { @Override public Boolean convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "yes (ignore case)", "y (ignore case)", "true (ignore case)", "t (ignore case)", "1", "no (ignore case)", "n (ignore case)", "false (ignore case)", "f (ignore case)", "0"); if(value==null){ return null; } String ignoreCaseValue = value.trim() .toLowerCase(Locale.ENGLISH); switch(ignoreCaseValue) { case "1": case "yes": case "y": case "true": case "t": case "on": return Boolean.TRUE; case "no": case "n": case "false": case "f": case "0": case "off": return Boolean.FALSE; default: LOG.finest("Unknown boolean createValue encountered: " + value); } return null; } }
BooleanConverter implements PropertyConverter<Boolean> { @Override public Boolean convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "yes (ignore case)", "y (ignore case)", "true (ignore case)", "t (ignore case)", "1", "no (ignore case)", "n (ignore case)", "false (ignore case)", "f (ignore case)", "0"); if(value==null){ return null; } String ignoreCaseValue = value.trim() .toLowerCase(Locale.ENGLISH); switch(ignoreCaseValue) { case "1": case "yes": case "y": case "true": case "t": case "on": return Boolean.TRUE; case "no": case "n": case "false": case "f": case "0": case "off": return Boolean.FALSE; default: LOG.finest("Unknown boolean createValue encountered: " + value); } return null; }  }
BooleanConverter implements PropertyConverter<Boolean> { @Override public Boolean convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "yes (ignore case)", "y (ignore case)", "true (ignore case)", "t (ignore case)", "1", "no (ignore case)", "n (ignore case)", "false (ignore case)", "f (ignore case)", "0"); if(value==null){ return null; } String ignoreCaseValue = value.trim() .toLowerCase(Locale.ENGLISH); switch(ignoreCaseValue) { case "1": case "yes": case "y": case "true": case "t": case "on": return Boolean.TRUE; case "no": case "n": case "false": case "f": case "0": case "off": return Boolean.FALSE; default: LOG.finest("Unknown boolean createValue encountered: " + value); } return null; }  @Override Boolean convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode(); }
BooleanConverter implements PropertyConverter<Boolean> { @Override public Boolean convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "yes (ignore case)", "y (ignore case)", "true (ignore case)", "t (ignore case)", "1", "no (ignore case)", "n (ignore case)", "false (ignore case)", "f (ignore case)", "0"); if(value==null){ return null; } String ignoreCaseValue = value.trim() .toLowerCase(Locale.ENGLISH); switch(ignoreCaseValue) { case "1": case "yes": case "y": case "true": case "t": case "on": return Boolean.TRUE; case "no": case "n": case "false": case "f": case "0": case "off": return Boolean.FALSE; default: LOG.finest("Unknown boolean createValue encountered: " + value); } return null; }  @Override Boolean convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }