@Test public void shouldCovertToBoolean() { a(Convert.toBoolean(null)).shouldBeFalse(); a(Convert.toBoolean("true")).shouldBeTrue(); a(Convert.toBoolean("false")).shouldBeFalse(); a(Convert.toBoolean("TRUE")).shouldBeTrue(); a(Convert.toBoolean("FALSE")).shouldBeFalse(); a(Convert.toBoolean("True")).shouldBeTrue(); a(Convert.toBoolean("False")).shouldBeFalse(); a(Convert.toBoolean("yes")).shouldBeTrue(); a(Convert.toBoolean("no")).shouldBeFalse(); a(Convert.toBoolean("YES")).shouldBeTrue(); a(Convert.toBoolean("NO")).shouldBeFalse(); a(Convert.toBoolean("Yes")).shouldBeTrue(); a(Convert.toBoolean("No")).shouldBeFalse(); a(Convert.toBoolean("t")).shouldBeTrue(); a(Convert.toBoolean("f")).shouldBeFalse(); a(Convert.toBoolean("T")).shouldBeTrue(); a(Convert.toBoolean("F")).shouldBeFalse(); a(Convert.toBoolean("y")).shouldBeTrue(); a(Convert.toBoolean("n")).shouldBeFalse(); a(Convert.toBoolean("Y")).shouldBeTrue(); a(Convert.toBoolean("N")).shouldBeFalse(); a(Convert.toBoolean("1")).shouldBeTrue(); a(Convert.toBoolean("0")).shouldBeFalse(); a(Convert.toBoolean('t')).shouldBeTrue(); a(Convert.toBoolean('f')).shouldBeFalse(); a(Convert.toBoolean('T')).shouldBeTrue(); a(Convert.toBoolean('F')).shouldBeFalse(); a(Convert.toBoolean('y')).shouldBeTrue(); a(Convert.toBoolean('n')).shouldBeFalse(); a(Convert.toBoolean('Y')).shouldBeTrue(); a(Convert.toBoolean('N')).shouldBeFalse(); a(Convert.toBoolean('1')).shouldBeTrue(); a(Convert.toBoolean('0')).shouldBeFalse(); a(Convert.toBoolean(1)).shouldBeTrue(); a(Convert.toBoolean(0)).shouldBeFalse(); a(Convert.toBoolean(1L)).shouldBeTrue(); a(Convert.toBoolean(0L)).shouldBeFalse(); a(Convert.toBoolean(1f)).shouldBeTrue(); a(Convert.toBoolean(0f)).shouldBeFalse(); a(Convert.toBoolean(1d)).shouldBeTrue(); a(Convert.toBoolean(0d)).shouldBeFalse(); short t = (short)1; short f = (short)0; a(Convert.toBoolean(t)).shouldBeTrue(); a(Convert.toBoolean(f)).shouldBeFalse(); }
public static Boolean toBoolean(Object value) { if (value == null) { return false; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof BigDecimal) { return value.equals(BigDecimal.ONE); } else if (value instanceof Number) { return ((Number) value).intValue() == 1; } else if (value instanceof Character) { char c = (Character) value; return c == 't' || c == 'T' || c == 'y' || c == 'Y' || c == '1'; } else { String str = value.toString(); return str.equalsIgnoreCase("true") || str.equalsIgnoreCase("t") || str.equalsIgnoreCase("yes") || str.equalsIgnoreCase("y") || str.equals("1") || Boolean.parseBoolean(str); } }
Convert { public static Boolean toBoolean(Object value) { if (value == null) { return false; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof BigDecimal) { return value.equals(BigDecimal.ONE); } else if (value instanceof Number) { return ((Number) value).intValue() == 1; } else if (value instanceof Character) { char c = (Character) value; return c == 't' || c == 'T' || c == 'y' || c == 'Y' || c == '1'; } else { String str = value.toString(); return str.equalsIgnoreCase("true") || str.equalsIgnoreCase("t") || str.equalsIgnoreCase("yes") || str.equalsIgnoreCase("y") || str.equals("1") || Boolean.parseBoolean(str); } } }
Convert { public static Boolean toBoolean(Object value) { if (value == null) { return false; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof BigDecimal) { return value.equals(BigDecimal.ONE); } else if (value instanceof Number) { return ((Number) value).intValue() == 1; } else if (value instanceof Character) { char c = (Character) value; return c == 't' || c == 'T' || c == 'y' || c == 'Y' || c == '1'; } else { String str = value.toString(); return str.equalsIgnoreCase("true") || str.equalsIgnoreCase("t") || str.equalsIgnoreCase("yes") || str.equalsIgnoreCase("y") || str.equals("1") || Boolean.parseBoolean(str); } } private  Convert(); }
Convert { public static Boolean toBoolean(Object value) { if (value == null) { return false; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof BigDecimal) { return value.equals(BigDecimal.ONE); } else if (value instanceof Number) { return ((Number) value).intValue() == 1; } else if (value instanceof Character) { char c = (Character) value; return c == 't' || c == 'T' || c == 'y' || c == 'Y' || c == '1'; } else { String str = value.toString(); return str.equalsIgnoreCase("true") || str.equalsIgnoreCase("t") || str.equalsIgnoreCase("yes") || str.equalsIgnoreCase("y") || str.equals("1") || Boolean.parseBoolean(str); } } private  Convert(); static String toString(Object value); static Boolean toBoolean(Object value); static java.sql.Date toSqlDate(Object value); static java.sql.Date truncateToSqlDate(Object value); static java.sql.Date truncateToSqlDate(long time); static String toIsoString(java.util.Date date); static Double toDouble(Object value); static java.sql.Time toTime(Object value); static java.sql.Timestamp toTimestamp(Object value); static Float toFloat(Object value); static Long toLong(Object value); static Integer toInteger(Object value); static BigDecimal toBigDecimal(Object value); static byte[] toBytes(Object value); static byte[] toBytes(Blob blob); static Short toShort(Object value); }
Convert { public static Boolean toBoolean(Object value) { if (value == null) { return false; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof BigDecimal) { return value.equals(BigDecimal.ONE); } else if (value instanceof Number) { return ((Number) value).intValue() == 1; } else if (value instanceof Character) { char c = (Character) value; return c == 't' || c == 'T' || c == 'y' || c == 'Y' || c == '1'; } else { String str = value.toString(); return str.equalsIgnoreCase("true") || str.equalsIgnoreCase("t") || str.equalsIgnoreCase("yes") || str.equalsIgnoreCase("y") || str.equals("1") || Boolean.parseBoolean(str); } } private  Convert(); static String toString(Object value); static Boolean toBoolean(Object value); static java.sql.Date toSqlDate(Object value); static java.sql.Date truncateToSqlDate(Object value); static java.sql.Date truncateToSqlDate(long time); static String toIsoString(java.util.Date date); static Double toDouble(Object value); static java.sql.Time toTime(Object value); static java.sql.Timestamp toTimestamp(Object value); static Float toFloat(Object value); static Long toLong(Object value); static Integer toInteger(Object value); static BigDecimal toBigDecimal(Object value); static byte[] toBytes(Object value); static byte[] toBytes(Blob blob); static Short toShort(Object value);  }