Heartbeat is an expression evaluator API written in Java.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Heartbeat - Expression Evaluator API

Heartbeat is an expression evaluator API written in Java. It is an API (documentation below), and it uses a modified version of JEP.


You can download the binaries, source code here, from Github (navigate in the branch mvn-repo if you want the JAR).

The project and source code in zip and tar.gz can be downloaded from here.

To include it in your Maven project, add this in your POM :



Usage Examples

final Heartbeat heartbeat = new Heartbeat();

/* Operations with numbers : */
heartbeat.setVariableValue("x", new VariableValue(VariableType.BIGDECIMAL, new BigDecimal(2d, heartbeat.getContext())));
System.out.println(heartbeat.evaluate("x + 2")); // BigDecimal

/* With strings (case sensitive) : */

heartbeat.setVariableValue("x", new VariableValue(VariableType.STRING, "Heart"));
System.out.println(heartbeat.evaluate("x + \"beat\"")); // String
/* With functions (case sensitive) : */
System.out.println(heartbeat.evaluate("RANDOM(1, 10)")); // BigDecimal
System.out.println(heartbeat.evaluate("RANDOM()")); // null
/* With constants (case sensitive) : */
System.out.println(heartbeat.evaluate("pi")); // BigDecimal

Supported Operators

Mathematical Operators (case sensitive)
+Additive operator
-Subtraction operator / negative operator
*Multiplication operator
/Division operator
%Remainder operator (Modulo)
^Power operator
.Dot operator (vectors)
^^Cross operator
Boolean Operators (case sensitive)
!=Not equals
<Less than
<=Less than or equal to
>Greater than
>=Greater than or equal to
&&Boolean and
||Boolean or
!Boolean not
_Boolean operators result always in a BigDecimal value of 1 or 0 (zero). Any non-zero value is treated as a **true** value._

Supported Functions

Function (case sensitive)Description
IF(condition,value_if_true,value_if_false)Returns one value if the condition evaluates to true or the other if it evaluates to false
RANDOM(min,max)Produces a random number between 0 and 1
SIN(expression)Returns the trigonometric sine of an angle (in degrees)
COS(expression)Returns the trigonometric cosine of an angle (in degrees)
TAN(expression)Returns the trigonometric tangens of an angle (in degrees)
ASIN(expression)Returns the angle of asin (in degrees)
ACOS(expression)Returns the angle of acos (in degrees)
ATAN(expression)Returns the angle of atan (in degrees)
SINH(expression)Returns the hyperbolic sine of a value
COSH(expression)Returns the hyperbolic cosine of a value
TANH(expression)Returns the hyperbolic tangens of a value
RAD(expression)Converts an angle measured in degrees to an approximately equivalent angle measured in radians
DEG(expression)Converts an angle measured in radians to an approximately equivalent angle measured in degrees
MAX(...)Returns the bigger of all expressions
MIN(...)Returns the smaller of all expressions
ABS(expression)Returns the absolute (non-negative) value of the expression
LOG(expression)Returns the natural logarithm (base e) of an expression
LOG10(expression)Returns the common logarithm (base 10) of an expression
ROUND(expression,precision)Rounds a value to a certain number of digits, uses the current rounding mode
FLOOR(expression)Rounds the value down to the nearest integer
CEILING(expression)Rounds the value up to the nearest integer
SQRT(expression)Returns the square root of an expression
STR(expression)Converts any expression to a String expression

Supported Constants

Constant (case sensitive)Description
piThe value of PI, exact to 100 digits
eThe value of PI, exact to 100 digits
trueThe value one
falseThe value zero


Documentation built thanks to the EvalEx by uklimaschewski one. This project uses a modified version of JEP. Licensed under GNU GPL v3.