Class Convertible
java.lang.Object
groovy.lang.GroovyObjectSupport
org.freeplane.plugin.script.proxy.Convertible
- All Implemented Interfaces:
- groovy.lang.GroovyObject,- Convertible
Utility wrapper class around a String that is used to convert node texts to different types.
 It's especially important for Formulas.
- 
Constructor SummaryConstructorsConstructorDescriptionConvertible(Object object) UsetoString(Object)to convert to String, i.e.Convertible(String text) Use thetextunchanged, i.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanFor implicit conversion to boolean: true if the text is not empty.intintcompareTo(Convertible convertible) booleanbooleangetBool()parses the text (case insensitive) as boolean viaBoolean.parseBoolean(String).Converts to Calendar if possible.getDate()Converts to Date if possible.getNum()Convert to Number.getNum0()Safe variant ofgetNum(), throws nothing - on any error (long) 0 is returned.Uses the following priority ranking to determine the type of the text: null Long Double Date StringgetPlain()Removes HTML markup if necessary.getProperty(String property) pretend we are a String if we don't provide a property for ourselves.getRaw()Returns original objectNo conversion.getText()No conversion.getTo()Allow statements like this:node['attr_name'].to.num.getUri()Converts to URI if possible.inthashCode()since equals handles Strings special we have to stick to that here too since equal objects have to have the same hasCode.invokeMethod(String name, Object args) pretend we are a String if we don't provide a method for ourselves.booleanisDate()Type check.booleanisNum()Type check.voidsetProperty(String property, Object newValue) toString()static Stringhas 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.Methods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClass
- 
Constructor Details- 
ConvertibleUse thetextunchanged, i. e. oesn't evaluate formulas since this would require a calculation rule or NodeModel.- Parameters:
- text- the String to convert.
 
- 
ConvertibleUsetoString(Object)to convert to String, i.e. conversion is done properly.- Parameters:
- object- the Object to convert
 
 
- 
- 
Method Details- 
getNumConvert to Number. All Java number literals are allowed as described byLong.decode(String)- Specified by:
- getNumin interface- Convertible
- Returns:
- a Long or a Double, whatever fits best.
- Throws:
- org.freeplane.plugin.script.proxy.ConversionException- if text is not a number.
 
- 
getNum0Safe variant ofgetNum(), throws nothing - on any error (long) 0 is returned.- Specified by:
- getNum0in interface- Convertible
- Returns:
- a Long or a Double if text is convertible to it or 0 otherwise (even if text is null).
 
- 
getStringNo conversion.- Specified by:
- getStringin interface- Convertible
- Returns:
- The original string.
 
- 
getTextNo conversion.- Specified by:
- getTextin interface- Convertible
- Returns:
- The original string.
 
- 
getPlainRemoves HTML markup if necessary.- Specified by:
- getPlainin interface- Convertible
- Returns:
- The result of HtmlUtils.htmlToPlain(String)
 
- 
getDateConverts to Date if possible. The valid date patterns are "yyyy-MM-dd HH:dd:ss.SSSZ" with optional '-', ':'. ' ' may be replaced by 'T'.- Specified by:
- getDatein interface- Convertible
- Returns:
- a Date for the parsed text
- Throws:
- org.freeplane.plugin.script.proxy.ConversionException- if the text is not convertible to a Date.
 
- 
getCalendarConverts to Calendar if possible. SeegetDate()for recognized patterns.- Specified by:
- getCalendarin interface- Convertible
- Returns:
- a Calendar for the parsed text.
- Throws:
- org.freeplane.plugin.script.proxy.ConversionException- if the text is not convertible to a Date.
 
- 
getUriConverts to URI if possible.- Specified by:
- getUriin interface- Convertible
- Returns:
- a URI
- Throws:
- org.freeplane.plugin.script.proxy.ConversionException- if the text is not convertible to a URI.
 
- 
getObjectUses the following priority ranking to determine the type of the text:- null
- Long
- Double
- Date
- String
 - Specified by:
- getObjectin interface- Convertible
- Returns:
- Object - the type that fits best.
 
- 
getToAllow statements like this:node['attr_name'].to.num.- Returns:
- this
 
- 
isNumpublic boolean isNum()Type check.- Specified by:
- isNumin interface- Convertible
- Returns:
- true if the text is convertible to number.
 
- 
isDatepublic boolean isDate()Type check.- Specified by:
- isDatein interface- Convertible
- Returns:
- true if the text is convertible to date.
 
- 
getPropertypretend we are a String if we don't provide a property for ourselves.- Specified by:
- getPropertyin interface- groovy.lang.GroovyObject
- Parameters:
- property- a property of- String, e. g. "bytes".
- Returns:
- the property of the original string.
 
- 
invokeMethodpretend we are a String if we don't provide a method for ourselves.- Specified by:
- invokeMethodin interface- groovy.lang.GroovyObject
- Parameters:
- name- method name
- args- method args
- Returns:
- the result of the method invocation on the original string.
 
- 
toStringhas 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".
- null is "converted" to null
 - Parameters:
- value- the object to convert
- Returns:
- the converted string
 
- 
compareTo- Specified by:
- compareToin interface- Convertible
 
- 
compareTo- Specified by:
- compareToin interface- Convertible
 
- 
hashCodepublic int hashCode()since equals handles Strings special we have to stick to that here too since equal objects have to have the same hasCode.
- 
equals
- 
toString
- 
setProperty- Specified by:
- setPropertyin interface- groovy.lang.GroovyObject
 
- 
getBoolpublic boolean getBool()parses the text (case insensitive) as boolean viaBoolean.parseBoolean(String).- Specified by:
- getBoolin interface- Convertible
- Returns:
- boolean
 
- 
asBooleanpublic boolean asBoolean()For implicit conversion to boolean: true if the text is not empty.- Specified by:
- asBooleanin interface- Convertible
- Returns:
- boolean
 
- 
getRawDescription copied from interface:ConvertibleReturns original object- Specified by:
- getRawin interface- Convertible
- Returns:
- the original object
 
 
-