1 3 package jodd.typeconverter; 4 5 9 public class BooleanConverter implements TypeConverter { 10 11 public static Boolean valueOf(Object value) { 12 if (value == null) { 13 return null; 14 } 15 if (value instanceof Boolean ) { 16 return (Boolean ) value; 17 } 18 String stringValue = value.toString(); 19 if (stringValue.equalsIgnoreCase("yes") || 20 stringValue.equalsIgnoreCase("y") || 21 stringValue.equalsIgnoreCase("true") || 22 stringValue.equalsIgnoreCase("on") || 23 stringValue.equalsIgnoreCase("1")) { 24 return Boolean.TRUE; 25 } 26 if (stringValue.equalsIgnoreCase("no") || 27 stringValue.equalsIgnoreCase("n") || 28 stringValue.equalsIgnoreCase("false") || 29 stringValue.equalsIgnoreCase("off") || 30 stringValue.equalsIgnoreCase("0")) { 31 return Boolean.FALSE; 32 } 33 throw new TypeConversionException(); 34 } 35 36 public Object convert(Object value) { 37 return valueOf(value); 38 } 39 40 } 41 | Popular Tags |