Package org.freeplane.plugin.script.proxy

# Class Convertible

java.lang.Object
groovy.lang.GroovyObjectSupport
org.freeplane.plugin.script.proxy.Convertible

All Implemented Interfaces:
  `groovy.lang.GroovyObject`, `Convertible`

public class Convertible extends groovy.lang.GroovyObjectSupport implements Convertible
Utility wrapper class around a String that is used to convert node texts to different types. It's especially important for Formulas.

## Constructor Summary

Constructors
Constructor
Description
`Convertible(Object object)`
Use `toString(Object)` to convert to String, i.e.
`Convertible(String text)`
Use the `text` unchanged, i.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`asBoolean()`
For implicit conversion to boolean: true if the text is not empty.
`int`
`compareTo(Object string)`
`int`
`compareTo(Convertible convertible)`
`boolean`
`equals(Object obj)`
`boolean`
`getBool()`
parses the text (case insensitive) as boolean via `Boolean.parseBoolean(String)`.
`Calendar`
`getCalendar()`
Converts to Calendar if possible.
`Date`
`getDate()`
Converts to Date if possible.
`Number`
`getNum()`
Convert to Number.
`Number`
`getNum0()`
Safe variant of `getNum()`, throws nothing - on any error (long) 0 is returned.
`Object`
`getObject()`
Uses the following priority ranking to determine the type of the text: null Long Double Date String
`String`
`getPlain()`
Removes HTML markup if necessary.
`Object`
`getProperty(String property)`
pretend we are a String if we don't provide a property for ourselves.
`Object`
`getRaw()`
Returns original object
`String`
`getString()`
No conversion.
`String`
`getText()`
No conversion.
`Convertible`
`getTo()`
Allow statements like this: `node['attr_name'].to.num`.
`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.
`Object`
`invokeMethod(String name, 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(String property, Object newValue)`
`String`
`toString()`
`static String`
`toString(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.

### Methods inherited from class groovy.lang.GroovyObjectSupport

`getMetaClass, setMetaClass`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### Convertible

public Convertible(String text)
Use the `text` unchanged, i. e. oesn't evaluate formulas since this would require a calculation rule or NodeModel.

Parameters:
  `text` - the String to convert.

### Convertible

public Convertible(Object object)
Use `toString(Object)` to convert to String, i.e. conversion is done properly.

Parameters:
  `object` - the Object to convert

## Method Details

### getNum

public Number getNum() throws org.freeplane.plugin.script.proxy.ConversionException
Convert to Number. All Java number literals are allowed as described by `Long.decode(String)`

Specified by:
  `getNum` in interface `Convertible`
Returns:
  a Long or a Double, whatever fits best.
Throws:
  `org.freeplane.plugin.script.proxy.ConversionException` - if text is not a number.

### getNum0

public Number getNum0()
Safe variant of `getNum()`, throws nothing - on any error (long) 0 is returned.

Specified by:
  `getNum0` in interface `Convertible`
Returns:
  a Long or a Double if text is convertible to it or 0 otherwise (even if text is null).

### getString

public String getString()
No conversion.

Specified by:
  `getString` in interface `Convertible`
Returns:
  The original string.

### getText

public String getText()
No conversion.

Specified by:
  `getText` in interface `Convertible`
Returns:
  The original string.

### getPlain

public String getPlain()
Removes HTML markup if necessary.

Specified by:
  `getPlain` in interface `Convertible`
Returns:
  The result of `HtmlUtils.htmlToPlain(String)`

### getDate

public Date getDate() throws org.freeplane.plugin.script.proxy.ConversionException
Converts 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:
  `getDate` in 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.

### getCalendar

public Calendar getCalendar() throws org.freeplane.plugin.script.proxy.ConversionException
Converts to Calendar if possible. See `getDate()` for recognized patterns.

Specified by:
  `getCalendar` in 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.

### getUri

public URI getUri() throws org.freeplane.plugin.script.proxy.ConversionException
Converts to URI if possible.

Specified by:
  `getUri` in interface `Convertible`
Returns:
  a URI
Throws:
  `org.freeplane.plugin.script.proxy.ConversionException` - if the text is not convertible to a URI.

### getObject

public Object getObject()
Uses the following priority ranking to determine the type of the text:

1. null
2. Long
3. Double
4. Date
5. String

Specified by:
  `getObject` in interface `Convertible`
Returns:
  Object - the type that fits best.

### getTo

public Convertible getTo()
Allow statements like this: `node['attr_name'].to.num`.

Returns:
  this

### isNum

public boolean isNum()
Type check.

Specified by:
  `isNum` in interface `Convertible`
Returns:
  true if the text is convertible to number.

### isDate

public boolean isDate()
Type check.

Specified by:
  `isDate` in interface `Convertible`
Returns:
  true if the text is convertible to date.

### getProperty

public Object getProperty(String property)
pretend we are a String if we don't provide a property for ourselves.

Specified by:
  `getProperty` in interface `groovy.lang.GroovyObject`
Overrides:
  `getProperty` in class `groovy.lang.GroovyObjectSupport`
Parameters:
  `property` - a property of `String`, e. g. "bytes".
Returns:
  the property of the original string.

### invokeMethod

public Object invokeMethod(String name, Object args)
pretend we are a String if we don't provide a method for ourselves.

Specified by:
  `invokeMethod` in interface `groovy.lang.GroovyObject`
Overrides:
  `invokeMethod` in class `groovy.lang.GroovyObjectSupport`
Parameters:
  `name` - method name
  `args` - method args
Returns:
  the result of the method invocation on the original string.

### toString

public static String toString(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".
- null is "converted" to null

All other types are converted via value.toString().

Parameters:
  `value` - the object to convert
Returns:
  the converted string

### compareTo

public int compareTo(Object string)

Specified by:
  `compareTo` in interface `Convertible`

### compareTo

public int compareTo(Convertible convertible)

Specified by:
  `compareTo` in interface `Convertible`

### hashCode

public int hashCode()
since equals handles Strings special we have to stick to that here too since equal objects have to have the same hasCode.

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### setProperty

public void setProperty(String property, Object newValue)

Specified by:
  `setProperty` in interface `groovy.lang.GroovyObject`
Overrides:
  `setProperty` in class `groovy.lang.GroovyObjectSupport`

### getBool

public boolean getBool()
parses the text (case insensitive) as boolean via `Boolean.parseBoolean(String)`.

Specified by:
  `getBool` in interface `Convertible`
Returns:
  boolean

### asBoolean

public boolean asBoolean()
For implicit conversion to boolean: true if the text is not empty.

Specified by:
  `asBoolean` in interface `Convertible`
Returns:
  boolean

### getRaw

public Object getRaw()
Description copied from interface: `Convertible`
Returns original object

Specified by:
  `getRaw` in interface `Convertible`
Returns:
  the original object