55import cu .lt .joe .jcalc .exceptions .NotNumericResultException ;
66
77/**
8- * This class is the entry point of this library. It includes the method to solve Math operations
9- * and is the recommended portal to solve Math expressions using this library.
8+ * This class is the entry point of this library. It is, indeed, the class intended to solve Math
9+ * expressions once you configure all the parameters required to do so by using the {@link #with(ConfigurationBuilder)}
10+ * method, passing a {@link ConfigurationBuilder} instance with all the parameters set as you wish.
1011 *
1112 * @author <a href="https://github.com/jr20xx">jr20xx</a>
12- * @see #solveMathExpression(String)
13- * @since 2.0.0
13+ * @since 3.0.0
1414 */
1515public class JCalc
1616{
17- private final ConfigurationBuilder builder ;
17+ private final ConfigurationBuilder configurationBuilder ;
1818
19- private JCalc (ConfigurationBuilder builder )
19+ private JCalc (ConfigurationBuilder configurationBuilder )
2020 {
21- this .builder = builder ;
21+ this .configurationBuilder = configurationBuilder ;
2222 }
2323
24- public static JCalc with (ConfigurationBuilder builder )
24+ /**
25+ * This method receives a {@link ConfigurationBuilder} instance that is later used to customize
26+ * the way the Math expressions are treated. First of all, that {@link ConfigurationBuilder} instance
27+ * defines the value of the precision used for the final result obtained after solving a Math
28+ * expression and, besides that, it also determines if the parentheses in the Math expression are
29+ * automatically balanced and if trigonometric functions will use radians or degrees when solving
30+ * a Math expression. If you forget to setup that instance or pass {@code null} as parameter, a
31+ * {@link ConfigurationBuilder} instance with the default values will be used instead.
32+ *
33+ * @param configurationBuilder a {@link ConfigurationBuilder} instance containing the settings
34+ * to define how Math expressions are treated
35+ * @return A {@link JCalc} object ready to solve any Math expression using the provided
36+ * {@link ConfigurationBuilder} instance
37+ * @author <a href="https://github.com/jr20xx">jr20xx</a>
38+ * @since 3.0.0
39+ */
40+ public static JCalc with (ConfigurationBuilder configurationBuilder )
2541 {
26- return new JCalc (builder );
42+ if (configurationBuilder == null )
43+ configurationBuilder = new ConfigurationBuilder ();
44+ return new JCalc (configurationBuilder );
2745 }
2846
2947 /**
3048 * Takes a Math expression and returns its result. If the expression is empty, {@code null} will
31- * be returned. If the expression contains any whitespace, they'll be ignored.
49+ * be returned. If the expression contains any whitespace, they'll be ignored. Please, notice that
50+ * this method relies heavily on the {@link ConfigurationBuilder} instance defined using the
51+ * {@link #with(ConfigurationBuilder)} method, so to customize the results returned by this method,
52+ * just tweak the corresponding value of the {@link ConfigurationBuilder} instance in use.
3253 *
3354 * @param mathExpression a {@link String} containing the Math expression to solve
34- * @return A {@link String} containing the result of solving the given Math expression
55+ * @return A {@link String} containing the result of solving the given Math expression or {@code null}
56+ * if the given expression is empty
3557 * @throws NotNumericResultException when a not numeric (NaN) value is obtained
3658 * @throws InfiniteResultException when an Infinite result is obtained
3759 * @author <a href="https://github.com/jr20xx">jr20xx</a>
3860 * @since 3.0.0
3961 */
4062 public String solveMathExpression (String mathExpression )
4163 {
42- return ShuntingYardAlgImpl .solveMathExpression (mathExpression , builder .isBalanceParenthesesEnabled (), builder .getPrecision (), builder .isUseRadiansEnabled ());
64+ return ShuntingYardAlgImpl .solveMathExpression (mathExpression , configurationBuilder .isBalanceParenthesesEnabled (), configurationBuilder .getPrecision (), configurationBuilder .isUseRadiansEnabled ());
4365 }
4466}
0 commit comments