public class Casting extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Casting.ListWrapper |
(package private) static class |
Casting.StringSerializableInputStream
A SerializableInputStream where the toString represents the (escaped) contents of the stream itself.
|
static class |
Casting.StringWrapper
Wraps a String with an 'Escaper'.
|
static interface |
Casting.Unwrappable
Clases implementing this will not be wrapped by
wrap(java.lang.Object, org.mmbase.util.transformers.CharTransformer), even if the e.g. |
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
BOOLEAN_PATTERN |
(package private) static DocumentBuilder |
DOCUMENTBUILDER |
static Pattern |
DOUBLE_PATTERN |
static ThreadLocal<DateFormat> |
ISO_8601_DATE |
static ThreadLocal<DateFormat> |
ISO_8601_LOOSE
A Date formatter that creates a date based on a ISO 8601 date and a ISO 8601 time.
|
static ThreadLocal<DateFormat> |
ISO_8601_TIME |
static ThreadLocal<DateFormat> |
ISO_8601_UTC
A Date formatter that creates a ISO 8601 datetime according to UTC/GMT.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canCast(Class<?> from,
Class<?> to)
This method should report whether
toType(java.lang.Class<C>, java.lang.Object) is implemented for given 2 classes. |
static boolean |
equals(Object o1,
Object o2) |
static String |
escape(CharTransformer escaper,
CharSequence string) |
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 void |
setHelper(Caster h) |
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 Collection |
toCollection(Object o,
String delimiter)
Transforms an object to a collection.
|
static Date |
toDate(Object d)
Convert an object to a
Date. |
static BigDecimal |
toDecimal(Object i) |
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 SerializableInputStream |
toSerializableInputStream(Object obj) |
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 StringBuilder |
toStringBuilder(StringBuilder buffer,
Object o)
Convert an object to a string, using a StringBuilder
|
static <C> C |
toType(Class<C> type,
Object value)
Tries to 'cast' an object for use with the provided class.
|
static <C> C |
toType(Class<C> type,
Object cloud,
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 an object in another object with a toString as we desire.
|
public static final ThreadLocal<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 ThreadLocal<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 ThreadLocal<DateFormat> ISO_8601_DATE
public static final ThreadLocal<DateFormat> ISO_8601_TIME
static DocumentBuilder DOCUMENTBUILDER
public static final Pattern BOOLEAN_PATTERN
public static final Pattern DOUBLE_PATTERN
public static boolean isType(Class type, Object value)
type - the type (class) to checkvalue - the value whose type to checktrue if compatiblepublic static <C> C toType(Class<C> type, Object value)
type - the type (class)value - The value to be convertedpublic static <C> C toType(Class<C> type, Object 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 convertedpublic static boolean canCast(Class<?> from, Class<?> to)
toType(java.lang.Class<C>, java.lang.Object) is implemented for given 2 classes.
It is not yet fully implemented.public static boolean isStringRepresentable(Class<?> type)
public static String toString(Object o)
null is converted to an empty string.o - the object to convertStringpublic static StringBuffer toStringBuffer(StringBuffer buffer, Object o)
buffer - The StringBuffer with which to create the stringo - the object to convertpublic static StringBuilder toStringBuilder(StringBuilder buffer, Object o)
buffer - The StringBuilder with which to create the stringo - the object to convertpublic static Writer toWriter(Writer writer, Object o) throws IOException
writer - The Writer with which to create (write) the stringo - the object to convertIOExceptionpublic static Object wrap(Object o, CharTransformer escaper)
o - The object to be wrappedescaper - null or a CharTransformer to pipe the strings throughpublic static String escape(CharTransformer escaper, CharSequence string)
public 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 convertListpublic 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 Collection toCollection(Object o, String delimiter)
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 documentnullIllegalArgumentException - if the value could not be convertedpublic static byte[] toByte(Object obj)
obj - The object to be convertedbyte[] (binary/blob field)public static InputStream toInputStream(Object obj)
public static SerializableInputStream toSerializableInputStream(Object obj)
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 impossibleintpublic 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 convertintpublic 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 convertbooleanpublic static Integer toInteger(Object i)
i - the object to convertIntegerpublic 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 impossiblelongpublic 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 convertlongpublic 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 impossiblefloatpublic 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 convertfloatpublic 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 impossibledoublepublic 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 convertdoublepublic static BigDecimal toDecimal(Object i)
public 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 convertDate, never nullpublic static void setHelper(Caster h)
MMBase2 Utils 2.0.0 - 2019-08-08T23:20