public static Currency toCurrency(Object obj) { if (obj instanceof Currency) { return (Currency) obj; } if (obj instanceof String) { String str = Str.toString(obj); return Currency.getInstance(str); } return null; }
public static Currency toCurrency(Object obj) { if (obj instanceof Currency) { return (Currency) obj; } if (obj instanceof String) { String str = Str.toString(obj); return Currency.getInstance(str); } return null; }
public static <K, V> String idxStr( Map<K, V> map, K k ) { return Str.toString(map.get( k )); }
public static <K, V> String idxStr( Map<K, V> map, K k ) { return Str.toString(map.get( k )); }
/** * Prints a String and then terminates the line. This method behaves as * though it invokes <code>{@link #print(String)}</code> and then * <code>{@link #println()}</code>. * * @param object the <code>String</code> value to be printed */ public void println(Object object) { this.addLine(Str.toString(object)); }
/** * Prints a String and then terminates the line. This method behaves as * though it invokes <code>{@link #print(String)}</code> and then * <code>{@link #println()}</code>. * * @param object the <code>String</code> value to be printed */ public void println(Object object) { this.addLine(Str.toString(object)); }
public static int toInt(Object obj, int defaultValue) { if (obj.getClass() == int.class) { return int.class.cast(obj); } if (obj instanceof Number) { return ((Number) obj).intValue(); } else if (obj instanceof Boolean || obj.getClass() == Boolean.class) { boolean value = toBoolean(obj); return value ? 1 : 0; } else if (obj instanceof CharSequence) { try { return StringScanner.parseInt(Str.toString(obj)); } catch (Exception ex) { return defaultValue; } } return defaultValue; }
public static int toInt(Object obj, int defaultValue) { if (obj.getClass() == int.class) { return int.class.cast(obj); } if (obj instanceof Number) { return ((Number) obj).intValue(); } else if (obj instanceof Boolean || obj.getClass() == Boolean.class) { boolean value = toBoolean(obj); return value ? 1 : 0; } else if (obj instanceof CharSequence) { try { return StringScanner.parseInt(Str.toString(obj)); } catch (Exception ex) { return defaultValue; } } return defaultValue; }
public static float toFloat(Object obj) { if (obj.getClass() == float.class) { return (Float) obj; } try { if (obj instanceof Float) { return (Float) obj; } else if (obj instanceof Number) { return ((Number) obj).floatValue(); } else if (obj instanceof CharSequence) { try { return Float.parseFloat(Str.toString(obj)); } catch (Exception ex) { Exceptions.die(String.format("Unable to convert %s to a float", obj.getClass())); return Float.MIN_VALUE; } } else { } } catch (Exception ex) { log.warning(String.format( "unable to convert to float and there was an exception %s", ex.getMessage())); } Exceptions.die(String.format("Unable to convert %s to a float", obj.getClass())); return Float.MIN_VALUE; }
public static float toFloat(Object obj) { if (obj.getClass() == float.class) { return (Float) obj; } try { if (obj instanceof Float) { return (Float) obj; } else if (obj instanceof Number) { return ((Number) obj).floatValue(); } else if (obj instanceof CharSequence) { try { return Float.parseFloat(Str.toString(obj)); } catch (Exception ex) { Exceptions.die(String.format("Unable to convert %s to a float", obj.getClass())); return Float.MIN_VALUE; } } else { } } catch (Exception ex) { log.warning(String.format( "unable to convert to float and there was an exception %s", ex.getMessage())); } Exceptions.die(String.format("Unable to convert %s to a float", obj.getClass())); return Float.MIN_VALUE; }
public static long toLong(Object obj, final long longDefault) { if (obj instanceof Long) { return (Long) obj; } if (obj instanceof Number) { return ((Number) obj).longValue(); } else if (obj instanceof CharSequence) { String str = Str.toString(obj); if (Dates.isJsonDate(str)) { return Dates.fromJsonDate(str).getTime(); } try { return StringScanner.parseLong(str); } catch (Exception ex) { return longDefault; } } else if (obj instanceof Date) { return ((Date) obj).getTime(); } else { return toInt(obj); } }
public static long toLong(Object obj, final long longDefault) { if (obj instanceof Long) { return (Long) obj; } if (obj instanceof Number) { return ((Number) obj).longValue(); } else if (obj instanceof CharSequence) { String str = Str.toString(obj); if (Dates.isJsonDate(str)) { return Dates.fromJsonDate(str).getTime(); } try { return StringScanner.parseLong(str); } catch (Exception ex) { return longDefault; } } else if (obj instanceof Date) { return ((Date) obj).getTime(); } else { return toInt(obj); } }
public final void serializeMap( Map<Object, Object> smap, CharBuf builder ) { Map map = smap; if ( map.size () == 0 ) { builder.addChars ( EMPTY_MAP_CHARS ); return; } builder.addChar( '{' ); int index=0; final Set<Map.Entry> entrySet = map.entrySet(); for ( Map.Entry entry : entrySet ) { if (entry.getValue ()!=null ) { serializeFieldName ( Str.toString(entry.getKey()), builder ); serializeObject( entry.getValue(), builder ); builder.addChar ( ',' ); index++; } } if (index>0) builder.removeLastChar (); builder.addChar( '}' ); }
public final void serializeMap( Map<Object, Object> smap, CharBuf builder ) { Map map = smap; if ( map.size () == 0 ) { builder.addChars ( EMPTY_MAP_CHARS ); return; } builder.addChar( '{' ); int index=0; final Set<Map.Entry> entrySet = map.entrySet(); for ( Map.Entry entry : entrySet ) { if (entry.getValue ()!=null ) { serializeFieldName ( Str.toString(entry.getKey()), builder ); serializeObject( entry.getValue(), builder ); builder.addChar ( ',' ); index++; } } if (index>0) builder.removeLastChar (); builder.addChar( '}' ); }
public final void serializeMap( Map<Object, Object> smap, CharBuf builder ) { Map map = smap; if ( map.size () == 0 ) { builder.addChars ( EMPTY_MAP_CHARS ); return; } builder.addChar( '{' ); int index=0; final Set<Map.Entry> entrySet = map.entrySet(); for ( Map.Entry entry : entrySet ) { if (entry.getValue ()!=null ) { serializeFieldName ( Str.toString(entry.getKey()), builder ); serializeObject( entry.getValue(), builder ); builder.addChar ( ',' ); index++; } } if (index>0) builder.removeLastChar (); builder.addChar( '}' ); }