Package ch.andre601.expressionparser
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic ToBooleanExpression
toBoolean
(ToDoubleExpression expression) Converts the providedToDoubleExpression
into aToBooleanExpression
with its boolean value being true if the ToDoubleExpression's double value is anything but zero.static ToBooleanExpression
toBoolean
(ToStringExpression expression) Converts the providedToStringExpression
into aToBooleanExpression
with its boolean value being the output ofBoolean.parseBoolean(expression.evaluate())
.static ToDoubleExpression
toDouble
(ToBooleanExpression expression) Converts the providedToBooleanExpression
into aToDoubleExpression
with its double value being one should the ToBooleanExpression's boolean value be true, else zero.static ToDoubleExpression
toDouble
(ToStringExpression expression) Converts the providedToStringExpression
into aToDoubleExpression
with its double value being parsed from the ToStringExpression's String value using astatic NumberFormatter
.static ToStringExpression
toString
(ToBooleanExpression expression) Converts the providedToBooleanExpression
into aToStringExpression
with its String value being the output ofBoolean.toString(expression.evaluate())
.static ToStringExpression
toString
(ToDoubleExpression expression) Converts the providedToDoubleExpression
into aToStringExpression
with its String value being the output of eitherInteger.toString((int)expression.evaluate())
orDouble.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 providedToDoubleExpression
into aToBooleanExpression
with 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 providedToStringExpression
into aToBooleanExpression
with its boolean value being the output ofBoolean.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 providedToBooleanExpression
into aToDoubleExpression
with 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 providedToStringExpression
into aToDoubleExpression
with its double value being parsed from the ToStringExpression's String value using astatic 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 providedToBooleanExpression
into aToStringExpression
with its String value being the output ofBoolean.toString(expression.evaluate())
.- Parameters:
expression
- The ToBooleanExpression to convert.- Returns:
- ToStringExpression who's String value is the output of
Boolean.toString(boolean)
.
-
toString
Converts the providedToDoubleExpression
into aToStringExpression
with its String value being the output of eitherInteger.toString((int)expression.evaluate())
orDouble.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 who's String value is the output of either
Integer.toString(int)
orDouble.toString(double)
.
-