| java.lang.Object org.mmbase.util.Casting
Casting | public class Casting (Code) | | |
Inner Class :public static class ListWrapper extends AbstractList | |
Inner Class :public static class StringWrapper implements CharSequence | |
Inner Class :public static interface Unwrappable | |
Method Summary | |
public static boolean | equals(Object o1, Object o2) | public static boolean | isStringRepresentable(Class type) Whether or not Casting can more or less reliably cast a certain type to String and back. | public static boolean | isType(Class type, Object value) Returns whether the passed object is of the given class.
Unlike Class instanceof this also includes Object Types that
are representative for primitive types (i.e. | public static boolean | toBoolean(Object b) Convert an object to a boolean .
If the value is numeric, this call returns true
if the value is a positive, non-zero, value. | public static byte[] | toByte(Object obj) Convert an object to a byte array. | public static Collection | toCollection(Object o, String delimiter) Transforms an object to a collection. | public static Collection | toCollection(Object o) | public static Date | toDate(Object d) Convert an object to a Date . | public static double | toDouble(Object i, double def) Convert an object to an double . | public static double | toDouble(Object i) Convert an object to an double . | public static float | toFloat(Object i, float def) Convert an object to an float . | public static float | toFloat(Object i) Convert an object to an float . | public static InputStream | toInputStream(Object obj) | public static int | toInt(Object i, int def) Convert an object to an int . | public static int | toInt(Object i) Convert an object to an int . | public static Integer | toInteger(Object i) Convert an object to an Integer. | public static List | toList(Object o) Convert an object to a List. | public static List | toList(Object o, String delimiter) As
Casting.toList(Object) but with one extra argument.
Parameters: delimiter - Regexp to use when splitting up the string if the object is a String. | public static long | toLong(Object i, long def) Convert an object to a long . | public static long | toLong(Object i) Convert an object to a long . | public static Map | toMap(Object o) | public static Node | toNode(Object i, Cloud cloud) Convert an object to an Node. | public static String | toString(Object o) Convert an object to a String. | public static StringBuffer | toStringBuffer(StringBuffer buffer, Object o) Convert an object to a string, using a StringBuffer. | public static StringBuilder | toStringBuilder(StringBuilder buffer, Object o) | public static C | toType(Class<C> type, Object value) Tries to 'cast' an object for use with the provided class. | public static C | toType(Class<C> type, Cloud cloud, Object value) Tries to 'cast' an object for use with the provided class. | public static Writer | toWriter(Writer writer, Object o) Convert an object to a string, using a Writer. | public static Document | toXML(Object o) Convert the value to a Document object. | public static Object | unWrap(Object o) When you want to undo the wrapping, this method can be used. | public static Object | wrap(Object o, CharTransformer escaper) Wraps an object in another object with a toString as we desire. |
ISO_8601_LOOSE | final public static ThreadLocal<DateFormat> ISO_8601_LOOSE(Code) | | A Date formatter that creates a date based on a ISO 8601 date and a ISO 8601 time.
I.e. 2004-12-01 14:30:00.
It is NOT 100% ISO 8601, as opposed to
Casting.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'.
|
ISO_8601_UTC | final public static ThreadLocal<DateFormat> ISO_8601_UTC(Code) | | A Date formatter that creates a ISO 8601 datetime according to UTC/GMT.
I.e. 2004-12-01T14:30:00Z.
This is 100% ISO 8601, as opposed to
Casting.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.
|
isStringRepresentable | public static boolean isStringRepresentable(Class type)(Code) | | Whether or not Casting can more or less reliably cast a certain type to String and back.
For collection types also the entries of the collection must be string representable.
since: MMBase-1.8 |
isType | public static boolean isType(Class type, Object value)(Code) | | Returns whether the passed object is of the given class.
Unlike Class instanceof this also includes Object Types that
are representative for primitive types (i.e. Integer for int).
Parameters: type - the type (class) to check Parameters: value - the value whose type to check true if compatible since: MMBase-1.8 |
toBoolean | public static boolean toBoolean(Object b)(Code) | | Convert an object to a 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.
Parameters: b - the object to convert the converted value as a boolean |
toByte | public static byte[] toByte(Object obj)(Code) | | Convert an object to a byte array.
Parameters: obj - The object to be converted the value as an byte[] (binary/blob field) |
toCollection | public static Collection toCollection(Object o, String delimiter)(Code) | | Transforms an object to a collection. If the object is a collection already, then nothing
happens. If it is a Map, then the 'entry set' is returned. A string is interpreted as a
comma-separated list of strings. Other objects are wrapped in an ArrayList with one element.
since: MMBase-1.8.5 |
toDate | public static Date toDate(Object d)(Code) | | Convert an object to a 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.
Parameters: d - the object to convert the converted value as a Date , never null since: MMBase-1.7 |
toDouble | public static double toDouble(Object i, double def)(Code) | | Convert an object to an 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.
Parameters: i - the object to convert Parameters: def - the default value if conversion is impossible the converted value as a double |
toDouble | public static double toDouble(Object i)(Code) | | Convert an object to an double .
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return -1.
Parameters: i - the object to convert the converted value as a double |
toFloat | public static float toFloat(Object i, float def)(Code) | | Convert an object to an 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.
Parameters: i - the object to convert Parameters: def - the default value if conversion is impossible the converted value as a float |
toFloat | public static float toFloat(Object i)(Code) | | Convert an object to an float .
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return -1.
Parameters: i - the object to convert the converted value as a float |
toInt | public static int toInt(Object i, int def)(Code) | | Convert an object to an 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.
Parameters: i - the object to convert Parameters: def - the default value if conversion is impossible the converted value as an int since: MMBase-1.7 |
toInt | public static int toInt(Object i)(Code) | | Convert an object to an 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.
Parameters: i - the object to convert the converted value as an int |
toInteger | public static Integer toInteger(Object i)(Code) | | Convert an object to an Integer.
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return -1.
Parameters: i - the object to convert the converted value as a Integer |
toList | public static List toList(Object o)(Code) | | Convert an object to a List.
A String is split up (as if it was a comma-separated String).
Individual objects are wrapped and returned as Lists with one item.
null and the empty string are returned as an empty list.
Parameters: o - the object to convert the converted value as a List since: MMBase-1.7 |
toList | public static List toList(Object o, String delimiter)(Code) | | As
Casting.toList(Object) but with one extra argument.
Parameters: 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. since: MMBase-1.8 |
toLong | public static long toLong(Object i, long def)(Code) | | Convert an object to a 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.
Parameters: i - the object to convert Parameters: def - the default value if conversion is impossible the converted value as a long since: MMBase-1.7 |
toLong | public static long toLong(Object i)(Code) | | Convert an object to a long .
Boolean values return 0 for false, 1 for true.
String values are parsed to a number, if possible.
All remaining values return -1.
Parameters: i - the object to convert the converted value as a long since: MMBase-1.7 |
toNode | public static Node toNode(Object i, Cloud cloud)(Code) | | Convert an object to an Node.
If the value is Numeric, the method
tries to obtain the mmbase object with that number.
A Map returns a virtual Node representing the map, (a
MapNode ).
All remaining situations return the node with the alias i.toString() , which can
be null if no node which such an alias.
Parameters: i - the object to convert Parameters: cloud - the Cloud to use for loading a node the value as a Node since: MMBase-1.7 |
toString | public static String toString(Object o)(Code) | | Convert an object to a String.
null is converted to an empty string.
Parameters: o - the object to convert the converted value as a String |
toStringBuffer | public static StringBuffer toStringBuffer(StringBuffer buffer, Object o)(Code) | | Convert an object to a string, using a StringBuffer.
Parameters: buffer - The StringBuffer with which to create the string Parameters: o - the object to convert the StringBuffer used for conversion (same as the buffer parameter) since: MMBase-1.7 |
toStringBuilder | public static StringBuilder toStringBuilder(StringBuilder buffer, Object o)(Code) | | Convert an object to a string, using a StringBuilder
Parameters: buffer - The StringBuilder with which to create the string Parameters: o - the object to convert the StringBuilder used for conversion (same as the buffer parameter) since: MMBase-1.9 |
toType | public static C toType(Class<C> type, Object value)(Code) | | Tries to 'cast' an object for use with the provided class. E.g. if value is a String, but the
type passed is Integer, then the string is act to an Integer.
If the type passed is a primitive type, the object is cast to an Object Types that is representative
for that type (i.e. Integer for int).
Parameters: type - the type (class) Parameters: value - The value to be converted value the converted value since: MMBase-1.8 |
toType | public static C toType(Class<C> type, Cloud cloud, Object value)(Code) | | Tries to 'cast' an object for use with the provided class. E.g. if value is a String, but the
type passed is Integer, then the string is act to an Integer.
If the type passed is a primitive type, the object is cast to an Object Types that is representative
for that type (i.e. Integer for int).
Parameters: type - the type (class) Parameters: cloud - When casting to Node, a cloud may be needed. May be null , for an anonymous cloud to be tried. Parameters: value - The value to be converted value the converted value since: MMBase-1.8 |
toWriter | public static Writer toWriter(Writer writer, Object o) throws java.io.IOException(Code) | | Convert an object to a string, using a Writer.
Parameters: writer - The Writer with which to create (write) the string Parameters: o - the object to convert the Writer used for conversion (same as the writer parameter) since: MMBase-1.7 |
toXML | public static Document toXML(Object o)(Code) | | Convert the value to a 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.
Parameters: o - the object to be converted to an XML document the value as a DOM Element or null throws: IllegalArgumentException - if the value could not be converted since: MMBase-1.6 |
unWrap | public static Object unWrap(Object o)(Code) | | When you want to undo the wrapping, this method can be used.
since: MMBase-1.8 |
wrap | public static Object wrap(Object o, CharTransformer escaper)(Code) | | Wraps an object in another object with a toString as we desire. Casting can now be done with
toString() on the resulting object.
This is used to make JSTL en EL behave similarly as mmbase taglib when writing objects to the
page (taglib calls Casting, but JSTL of course doesn't).
Parameters: o - The object to be wrapped Parameters: escaper - null or a CharTransformer to pipe the strings through since: MMBase-1.8 |
|
|