A lil one class library to quickly evaluate simple math expressions. Or just to parse it and apply syntax highlighting.
(just click the jitpack badge)
Use the MathExpression#parse method to get an instance of MathExpression. Think of this like compiling ahead of time. The required argument is the string of the expression (i.e. 19 * 12). You may also provide a map of string (name of variable) and double (value of variable) as an optional second argument. Alternatively, you can set a variable by invoking MathExpression#setVariable (chainable method), which takes a string and double. All of the constants in the JDK Math class are added automatically as built-in variables (i.e. PI). Once you are ready, simply invoke MathExpression#evaluate. You may invoke the method multiple times with different values for the variables.
Maven (edit pom.xml)
<repositories>
...
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
...
</repositories> <dependencies>
...
<dependency>
<groupId>com.github.AndyNoob</groupId>
<artifactId>math-expressions</artifactId>
<version>INSERT VERSION HERE!!!!!!</version>
</dependency>
...
</dependencies>Gradle (edit build.gradle)
repositories {
// ...
maven { url 'https://jitpack.io' }
// ...
}dependencies {
// ...
implementation 'com.github.AndyNoob:math-expressions:INSERT VERSION HERE !!!'
// ...
}