O'Reilly logo

Learning Neo4j 3.x - Second Edition by Rik Van Bruggen, Jérôme Baton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a function

This is not rocket science, a function is just a method in a Java class. This method must be annotated with @UserFunction and @Description (both in the org.neo4j.procedure package).

To start, let's create a function that returns true if the given parameter is an odd number, and its even counterpart. The source code is as follows:

package learningneo4j;import org.neo4j.procedure.Description;import org.neo4j.procedure.Name;import org.neo4j.procedure.UserFunction;public class OddEven {    @UserFunction    @Description("Returns true if the given number is odd")    public Boolean isOdd(@Name("number") Long number){        if(number!=null) return number%2==1;        else            return false;    }    @UserFunction    @Description("Returns true if the given number ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required