Class Conversions
java.lang.Object
ch.andre601.expressionparser.Conversions
Class containing static methods to convert
ToBooleanExpression, ToDoubleExpression and
ToStringExpression into their respective counterparts.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ToBooleanExpressiontoBoolean(ToDoubleExpression expression) Converts the providedToDoubleExpressioninto aToBooleanExpressionwith its boolean value being true if the ToDoubleExpression's double value is anything but zero.static ToBooleanExpressiontoBoolean(ToStringExpression expression) Converts the providedToStringExpressioninto aToBooleanExpressionwith its boolean value being the output of Boolean.parseBoolean(expression.evaluate()).static ToDoubleExpressiontoDouble(ToBooleanExpression expression) Converts the providedToBooleanExpressioninto aToDoubleExpressionwith its double value being one should the ToBooleanExpression's boolean value be true, else zero.static ToDoubleExpressiontoDouble(ToStringExpression expression) Converts the providedToStringExpressioninto aToDoubleExpressionwith its double value being parsed from the ToStringExpression's String value using a static NumberFormatter.static ToStringExpressiontoString(ToBooleanExpression expression) Converts the providedToBooleanExpressioninto aToStringExpressionwith its String value being the output of Boolean.toString(expression.evaluate()).static ToStringExpressiontoString(ToDoubleExpression expression) Converts the providedToDoubleExpressioninto aToStringExpressionwith its String value being the output of either Integer.toString((int)expression.evaluate()) or Double.toString(expression.evaluate()) depending on if the ToDoubleExpression's double value can be cast to an Integer.
-
Constructor Details
-
Conversions
public Conversions()
-
-
Method Details
-
toBoolean
Converts the providedToDoubleExpressioninto aToBooleanExpressionwith its boolean value being true if the ToDoubleExpression's double value is anything but zero.- Parameters:
expression- The ToDoubleExpression to convert.- Returns:
- ToBooleanExpression who's boolean value is true if the ToDoubleExpression's double value is not zero.
-
toBoolean
Converts the providedToStringExpressioninto aToBooleanExpressionwith its boolean value being the output of Boolean.parseBoolean(expression.evaluate()).- Parameters:
expression- The ToStringExpression to convert.- Returns:
- ToBooleanExpression who's boolean value is the output of
Boolean.parseBoolean(String).
-
toDouble
Converts the providedToBooleanExpressioninto aToDoubleExpressionwith its double value being one should the ToBooleanExpression's boolean value be true, else zero.- Parameters:
expression- The ToBooleanExpression to convert.- Returns:
- ToDoubleExpression with its double value being one if the ToBooleanExpression's boolean value be true, else zero.
-
toDouble
Converts the providedToStringExpressioninto aToDoubleExpressionwith its double value being parsed from the ToStringExpression's String value using a static NumberFormatter.
Should the parsing fail will the String value's length be used instead.- Parameters:
expression- The ToStringExpression to convert.- Returns:
- ToDoubleExpression who's double value either matches the ToStringExpression's String value text, if showing a number, else the String's text length.
-
toString
Converts the providedToBooleanExpressioninto aToStringExpressionwith its String value being the output of Boolean.toString(expression.evaluate()).- Parameters:
expression- The ToBooleanExpression to convert.- Returns:
- ToStringExpression whose String value is the output of
Boolean.toString(boolean).
-
toString
Converts the providedToDoubleExpressioninto aToStringExpressionwith its String value being the output of either Integer.toString((int)expression.evaluate()) or Double.toString(expression.evaluate()) depending on if the ToDoubleExpression's double value can be cast to an Integer.- Parameters:
expression- The ToDoubleExpression to convert.- Returns:
- ToStringExpression whose String value is the output of either
Integer.toString(int)orDouble.toString(double).
-