|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mmbase.util.Casting
| Nested Class Summary | |
static class |
Casting.ListWrapper
|
static class |
Casting.StringWrapper
Wraps a String with an 'Escaper'. |
| Field Summary | |
static DateFormat |
ISO_8601_DATE
|
static DateFormat |
ISO_8601_LOOSE
A Date formatter that creates a date based on a ISO 8601 date and a ISO 8601 time. |
static DateFormat |
ISO_8601_TIME
|
static DateFormat |
ISO_8601_UTC
A Date formatter that creates a ISO 8601 datetime according to UTC/GMT. |
| Constructor Summary | |
Casting()
|
|
| Method Summary | |
static boolean |
isStringRepresentable(Class type)
Whether or not Casting can more or less reliably cast a certain type to String and back. |
static boolean |
isType(Class type,
Object value)
Returns whether the passed object is of the given class. |
static boolean |
toBoolean(Object b)
Convert an object to a boolean. |
static byte[] |
toByte(Object obj)
Convert an object to a byte array. |
static Collection |
toCollection(Object o)
|
static Date |
toDate(Object d)
Convert an object to a Date. |
static double |
toDouble(Object i)
Convert an object to an double. |
static double |
toDouble(Object i,
double def)
Convert an object to an double. |
static float |
toFloat(Object i)
Convert an object to an float. |
static float |
toFloat(Object i,
float def)
Convert an object to an float. |
static InputStream |
toInputStream(Object obj)
|
static int |
toInt(Object i)
Convert an object to an int. |
static int |
toInt(Object i,
int def)
Convert an object to an int. |
static Integer |
toInteger(Object i)
Convert an object to an Integer. |
static List |
toList(Object o)
Convert an object to a List. |
static List |
toList(Object o,
String delimiter)
As toList(Object) but with one extra argument. |
static long |
toLong(Object i)
Convert an object to a long. |
static long |
toLong(Object i,
long def)
Convert an object to a long. |
static Map |
toMap(Object o)
|
static Node |
toNode(Object i,
Cloud cloud)
Convert an object to an Node. |
static String |
toString(Object o)
Convert an object to a String. |
static StringBuffer |
toStringBuffer(StringBuffer buffer,
Object o)
Convert an object to a string, using a StringBuffer. |
static Object |
toType(Class type,
Cloud cloud,
Object value)
Tries to 'cast' an object for use with the provided class. |
static Object |
toType(Class type,
Object value)
Tries to 'cast' an object for use with the provided class. |
static Writer |
toWriter(Writer writer,
Object o)
Convert an object to a string, using a Writer. |
static Document |
toXML(Object o)
Convert the value to a Document object. |
static Object |
unWrap(Object o)
When you want to undo the wrapping, this method can be used. |
static Object |
wrap(Object o,
CharTransformer escaper)
Wraps it in an object with a toString as we desire. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final DateFormat ISO_8601_LOOSE
ISO_8601_UTC, as the standard actually requires
a 'T' to be placed between the date and the time.
The date given is the date for the local (server) time. Use this formatter if you want to display
user-friendly dates in local time.
XXX: According to http://en.wikipedia.org/wiki/ISO_8601, the standard allows ' ' in stead of
'T' if no misunderstanding arises, which is the case here. So I don't think this is 'loose'.
public static final DateFormat ISO_8601_UTC
ISO_8601_LOOSE.
Use this formatter if you want to export dates.
XXX: Hmm, we parse with UTC now, while we don't store them as such.
public static final DateFormat ISO_8601_DATE
public static final DateFormat ISO_8601_TIME
| Constructor Detail |
public Casting()
| Method Detail |
public static boolean isType(Class type,
Object value)
type - the type (class) to checkvalue - the value whose type to check
true if compatible
public static Object toType(Class type,
Object value)
type - the type (class)value - The value to be converted
public static Object toType(Class type,
Cloud cloud,
Object value)
type - the type (class)cloud - When casting to Node, a cloud may be needed. May be null, for an anonymous cloud to be tried.value - The value to be converted
public static boolean isStringRepresentable(Class type)
public static String toString(Object o)
o - the object to convert
String
public static StringBuffer toStringBuffer(StringBuffer buffer,
Object o)
buffer - The StringBuffer with which to create the stringo - the object to convert
public static Writer toWriter(Writer writer,
Object o)
throws IOException
writer - The Writer with which to create (write) the stringo - the object to convert
IOException
public static Object wrap(Object o,
CharTransformer escaper)
o - The object to be wrappedescaper - null or a CharTransformer to pipe the strings throughpublic static Object unWrap(Object o)
public static List toList(Object o)
null and the empty string are returned as an empty list.
o - the object to convert
List
public static List toList(Object o,
String delimiter)
toList(Object) but with one extra argument.
delimiter - Regexp to use when splitting up the string if the object is a String. null or the empty string mean the default, which is a comma.public static Map toMap(Object o)
public static Collection toCollection(Object o)
public static Document toXML(Object o)
Document object.
If the value is not itself a Document, the method attempts to
attempts to convert the String value into an XML.
A null value is returned as null.
If the value cannot be converted, this method throws an IllegalArgumentException.
o - the object to be converted to an XML document
null
IllegalArgumentException - if the value could not be convertedpublic static byte[] toByte(Object obj)
obj - The object to be converted
byte[] (binary/blob field)public static InputStream toInputStream(Object obj)
public static Node toNode(Object i,
Cloud cloud)
null.
i - the object to convertcloud - the Cloud to use for loading a node
Node
public static int toInt(Object i,
int def)
int.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
If a value is an Node, it's number field is returned.
All remaining values return the provided default value.
i - the object to convertdef - the default value if conversion is impossible
intpublic static int toInt(Object i)
int.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
If a value is a Node, it's number field is returned.
All remaining values return -1.
i - the object to convert
intpublic static boolean toBoolean(Object b)
boolean.
If the value is numeric, this call returns true
if the value is a positive, non-zero, value. In other words, values '0'
and '-1' are considered false.
If the value is a string, this call returns true if
the value is "true" or "yes" (case-insensitive).
In all other cases (including calling byte fields), false
is returned.
b - the object to convert
booleanpublic static Integer toInteger(Object i)
i - the object to convert
Integer
public static long toLong(Object i,
long def)
long.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return the provided default value.
i - the object to convertdef - the default value if conversion is impossible
longpublic static long toLong(Object i)
long.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return -1.
i - the object to convert
long
public static float toFloat(Object i,
float def)
float.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return the default value.
i - the object to convertdef - the default value if conversion is impossible
floatpublic static float toFloat(Object i)
float.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return -1.
i - the object to convert
float
public static double toDouble(Object i,
double def)
double.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return the default value.
i - the object to convertdef - the default value if conversion is impossible
doublepublic static double toDouble(Object i)
double.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return -1.
i - the object to convert
doublepublic static Date toDate(Object d)
Date.
String values are parsed to a date, if possible.
Numeric values are assumed to represent number of seconds since 1970.
All remaining values return 1969-12-31 23:59 GMT.
d - the object to convert
Date, never null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||