0

this is a FreePlane Groovy code. The task is to extract the node details and cast it to integer, or leave it equal to 1 if details are null (empty) or non-numeric. Initially, node details contain only "4" in plain text layout.

Here is my code:

def getRepetitions(node)
{
    if (node.details!=null){
        node['node.details']=node.details
        node['node.details.size()']=node.details.size()
        node['getPlain()']=node.details.getPlain()
        node['getPlain().size()']=node.details.getPlain().size()
        node['node.details.status']='not null'
     getRepetitions=(double)(node.details.getPlain())-48
    }else{
        node['node.details.status']='null'
        getRepetitions=1
    }
}

Here is a problem, as code doesn't convert text "4" to 4, but rather to 52 (which is incidentally ASCII code of "4"). And worse, when I substract 48, so that the difference is equal to number itself, it doesn't pay attention.

I wouldn't be posting this, if such functions as toNumber(...) or .to.num0 would work, but when trying to implement this I see


"message: No signature of method: org.freeplane.plugin.script.proxy.Proxy$NodeRO.toNumber() is applicable for argument types: (java.lang.String) values: [4]Line number: -1Result:No signature of method: org.freeplane.plugin.script.proxy.Proxy$NodeRO.toNumber() is applicable for argument types: (java.lang.String) values: [4] at line -1"


Thanks in advance.

Emil
  • 629
  • 2
  • 7
  • 24

1 Answers1

0

It looks like you can get the number like this: node.details.num

The proxy mentioned in your error is this interface. That will tell you which methods are available for your nodes.

What is the deal with getRepetitions=x? That looks like VB code. The Groovy equivalent the return statement (or an expression).

Emmanuel Rosa
  • 9,697
  • 2
  • 14
  • 20
  • I've already solved that problem: I had to use node.details.getPlain() method to get the text, and then use .toInteger() method to get a number. Thanks anyway. – Emil Sep 04 '15 at 20:46