public class Convertible extends groovy.lang.GroovyObjectSupport implements Convertible
| Constructor and Description |
|---|
Convertible(java.lang.Object object)
Use
toString(Object) to convert to String, i.e. conversion is done properly. |
Convertible(java.lang.String text)
Use the
text unchanged, i. e. oesn't evaluate formulas since this would require
a calculation rule or NodeModel. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
asBoolean()
For implicit conversion to boolean: true if the text is not empty.
|
int |
compareTo(Convertible convertible) |
int |
compareTo(java.lang.Object string) |
boolean |
equals(java.lang.Object obj) |
boolean |
getBool()
parses the text (case insensitive) as boolean via
Boolean.parseBoolean(String). |
java.util.Calendar |
getCalendar()
Converts to Calendar if possible.
|
java.util.Date |
getDate()
Converts to Date if possible.
|
java.lang.Number |
getNum()
Convert to Number.
|
java.lang.Number |
getNum0()
Safe variant of
getNum(), throws nothing - on any error (long) 0 is returned. |
java.lang.Object |
getObject()
Uses the following priority ranking to determine the type of the text:
null
Long
Double
Date
String
|
java.lang.String |
getPlain()
Removes HTML markup if necessary.
|
java.lang.Object |
getProperty(java.lang.String property)
pretend we are a String if we don't provide a property for ourselves.
|
java.lang.Object |
getRaw()
Returns original object
|
java.lang.String |
getString()
No conversion.
|
java.lang.String |
getText()
No conversion.
|
Convertible |
getTo()
Allow statements like this:
node['attr_name'].to.num. |
java.net.URI |
getUri()
Converts to URI if possible.
|
int |
hashCode()
since equals handles Strings special we have to stick to that here too since
equal objects have to have the same hasCode.
|
java.lang.Object |
invokeMethod(java.lang.String name,
java.lang.Object args)
pretend we are a String if we don't provide a method for ourselves.
|
boolean |
isDate()
Type check.
|
boolean |
isNum()
Type check.
|
void |
setProperty(java.lang.String property,
java.lang.Object newValue) |
java.lang.String |
toString() |
static java.lang.String |
toString(java.lang.Object value)
has special conversions for
Date and Calendar are converted by
org.apache.commons.lang.time.DateFormatUtils.format(date, "yyyy-MM-dd'T'HH:mm:ss.SSSZ"), i.e. to
GMT timestamps, e.g.: "2010-08-16T22:31:55.123+0000".
|
public Convertible(java.lang.String text)
text unchanged, i. e. oesn't evaluate formulas since this would require
a calculation rule or NodeModel.text - the String to convert.public Convertible(java.lang.Object object)
toString(Object) to convert to String, i.e. conversion is done properly.object - the Object to convertpublic java.lang.Number getNum()
throws org.freeplane.plugin.script.proxy.ConversionException
Long.decode(String)getNum in interface ConvertibleConversionException - if text is not a number.public java.lang.Number getNum0()
getNum(), throws nothing - on any error (long) 0 is returned.getNum0 in interface Convertiblepublic java.lang.String getString()
getString in interface Convertiblepublic java.lang.String getText()
getText in interface Convertiblepublic java.lang.String getPlain()
getPlain in interface ConvertibleHtmlUtils.htmlToPlain(String)public java.util.Date getDate()
throws org.freeplane.plugin.script.proxy.ConversionException
getDate in interface ConvertibleConversionException - if the text is not convertible to a Date.public java.util.Calendar getCalendar()
throws org.freeplane.plugin.script.proxy.ConversionException
getDate() for recognized patterns.getCalendar in interface ConvertibleConversionException - if the text is not convertible to a Date.public java.net.URI getUri()
throws org.freeplane.plugin.script.proxy.ConversionException
getUri in interface ConvertibleConversionException - if the text is not convertible to a URI.public java.lang.Object getObject()
getObject in interface Convertiblepublic Convertible getTo()
node['attr_name'].to.num.public boolean isNum()
isNum in interface Convertiblepublic boolean isDate()
isDate in interface Convertiblepublic java.lang.Object getProperty(java.lang.String property)
getProperty in interface groovy.lang.GroovyObjectproperty - a property of String, e. g. "bytes".public java.lang.Object invokeMethod(java.lang.String name,
java.lang.Object args)
invokeMethod in interface groovy.lang.GroovyObjectname - method nameargs - method argspublic static java.lang.String toString(java.lang.Object value)
value - the object to convertpublic int compareTo(java.lang.Object string)
compareTo in interface Convertiblepublic int compareTo(Convertible convertible)
compareTo in interface Convertiblepublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic void setProperty(java.lang.String property,
java.lang.Object newValue)
setProperty in interface groovy.lang.GroovyObjectpublic boolean getBool()
Boolean.parseBoolean(String).getBool in interface Convertiblepublic boolean asBoolean()
asBoolean in interface Convertiblepublic java.lang.Object getRaw()
ConvertiblegetRaw in interface Convertible