|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mmbase.util.Casting
public class Casting
Collects MMBase specific 'cast' information, as static to... functions. This is used (and used to be implemented) in MMObjectNode. But this functionality is more generic to MMbase.
| Nested Class Summary | |
|---|---|
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. |
| Field Summary | |
|---|---|
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. |
| Method Summary | ||
|---|---|---|
static boolean |
canCast(Class<? extends Object> from,
Class<? extends Object> to)
This method should report whether toType(java.lang.Class is implemented for given 2 classes. |
|
static boolean |
equals(Object o1,
Object o2)
|
|
(package private) 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
|
toType(Class<C> type,
Object value)
Tries to 'cast' an object for use with the provided class. |
|
static
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
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
| 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 <C> C toType(Class<C> type,
Object value)
type - the type (class)value - The value to be converted
public 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 converted
public static boolean canCast(Class<? extends Object> from,
Class<? extends Object> to)
toType(java.lang.Class, 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 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 StringBuilder toStringBuilder(StringBuilder buffer,
Object o)
buffer - The StringBuilder 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 through
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 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,
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 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 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 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 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 convert
Date, never null
public static boolean equals(Object o1,
Object o2)
public static void setHelper(Caster h)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||