MXReflection: A Java Math Framework
See what MXReflection can do for you.
Join the DZone community and get the full member experience.Join For Free
MXReflection is a Java math framework based on mXparser library capabilities.
You can calculate complex mathematical operations and functions with Java, just by using class-related fields. MXReflection reads values from the assigned fields and injects the results in the
@Expression annotated fields.
How to Use It
You just need two Java annotations:
- With an
@Argvalue, we can assign customized argument names to be used in the target function.
@Expressionannotation value contains the function expression with the arguments.
Field 3 result: -34.32819235851987
Supported Math Collections
MXReflection supports the math collection available in the mXparser math library:
- Operators (+, -, *, /, #, !, ^)
- Binary Relations (=, ==, =<, =>, <, >, <>, !=, ~=)
- Boolean Operators (&, &&, /, ~&, ~&&, ~/, |, ||…)
- Bitwise Operators (@~, @&, @^, @|, @<<, @>>)
- Unary Functions (sin, cos, tan, tg, ctan, ctg, cot, sec,…)
- Binary Functions (log, mod, C, Bern, Stirl1, Stirl2, …)
- 3-args Functions (if, chi, CHi, Chi, cHi, pUni, cUni, qUni, pNor, cNor, qNor)
- Variadic Functions (iff, min, max, ConFrac, ConPol, gcd, …)
- Iterated Operators (sum, prod, avg, vari, stdi, mini, maxi)
- Calculus Operators (int, der, der-, der+, dern, diff, difb)
- Math Constants (pi, e, [gam], [phi], [PN], [B*], [F’d], [F’a], …)
- Physical Constants ([c], [G.], [g], [hP], [h-], [lP], [mP], [tP])
- Astronomical Constants ([ly], [au], [pc], [kpc], [Earth-R-eq], …)
- Random Variables ([Uni], [Int], [Int1], [Int2], [Int3], [Int4], …)
- Metric prefixes ([%], [%%], [Y], [sept], [Z], [sext], [E], …)
- Parser Symbols ((, ), ,, ;)
MXReflection supports all field data types with numeric content as an argument. You can use all Java types with
toString implementations that return numeric results.
Supported result field java types:
Note that for long, Long, and BigInteger, MXReflection uses
Math.round to parse the final result before injecting it. It is recommended to be sure that the expression returns an integer type.
With MXReflection, you can use function results as arguments for other results:
Field 3 result: 2.8 Field 4 result: -2.2 Field 5 result: -2.8 Field 6 result: 0.6 Field 7 result: 3 Field 8 result: 8
MXReflection resolves a graph of dependencies between functions and arguments. It makes sure that there is no cycle in the field dependency.
Published at DZone with permission of Ismail Mekni. See the original article here.
Opinions expressed by DZone contributors are their own.