Class TypeCasting
- java.lang.Object
-
- com.flagsmith.flagengine.utils.types.TypeCasting
-
public class TypeCasting extends Object
-
-
Constructor Summary
Constructors Constructor Description TypeCasting()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Booleancompare(SegmentConditions condition, Comparable value1, Comparable value2)Run comparison with condition of primitive type.static Booleancompare(SegmentConditions condition, Object value1, Object value2)Compare the values value1 and value2 with the provided condition.static BooleancompareModulo(String conditionValue, Object traitValue)Modulo is a special case as the condition value holds both the divisor and remainder.static BooleanisBoolean(Object str)Is the object of type Boolean?.static BooleanisDouble(Object number)Is the object of type Double?.static BooleanisFloat(Object number)Is the object of type Float?.static BooleanisInteger(Object number)Is the object of type Integer?.static BooleanisSemver(Object str)Is the object of type Semver?.static BooleantoBoolean(Object str)Convert the object to Boolean.static DoubletoDouble(Object number)Convert the object to Double.static FloattoFloat(Object number)Convert the object to float.static IntegertoInteger(Object number)Convert to object to Integer.static org.apache.maven.artifact.versioning.ComparableVersiontoSemver(Object str)Convert the object to Semver.
-
-
-
Method Detail
-
compare
public static Boolean compare(SegmentConditions condition, Object value1, Object value2)
Compare the values value1 and value2 with the provided condition.- Parameters:
condition- SegmentCondition criteria to compare values against.value1- Value to compare.value2- Value to compare against.- Returns:
-
compare
public static Boolean compare(SegmentConditions condition, Comparable value1, Comparable value2)
Run comparison with condition of primitive type.- Parameters:
condition- SegmentCondition criteria to compare values against.value1- Value to compare.value2- Value to compare against.- Returns:
-
toDouble
public static Double toDouble(Object number)
Convert the object to Double.- Parameters:
number- Object to convert to Double.- Returns:
-
isDouble
public static Boolean isDouble(Object number)
Is the object of type Double?.- Parameters:
number- Object to type check.- Returns:
-
toFloat
public static Float toFloat(Object number)
Convert the object to float.- Parameters:
number- Object to convert to Float.- Returns:
-
isFloat
public static Boolean isFloat(Object number)
Is the object of type Float?.- Parameters:
number- Object to type check.- Returns:
-
toInteger
public static Integer toInteger(Object number)
Convert to object to Integer.- Parameters:
number- Object to convert to Integer.- Returns:
-
isInteger
public static Boolean isInteger(Object number)
Is the object of type Integer?.- Parameters:
number- Object to type check.- Returns:
-
toBoolean
public static Boolean toBoolean(Object str)
Convert the object to Boolean.- Parameters:
str- Object to convert to Boolean.- Returns:
-
isBoolean
public static Boolean isBoolean(Object str)
Is the object of type Boolean?.- Parameters:
str- Object to type check.- Returns:
-
toSemver
public static org.apache.maven.artifact.versioning.ComparableVersion toSemver(Object str)
Convert the object to Semver.- Parameters:
str- Object to convert to Semver.- Returns:
-
isSemver
public static Boolean isSemver(Object str)
Is the object of type Semver?.- Parameters:
str- Object to type check.- Returns:
-
compareModulo
public static Boolean compareModulo(String conditionValue, Object traitValue)
Modulo is a special case as the condition value holds both the divisor and remainder. This method compares the conditionValue and the traitValue by dividing the traitValue by the divisor and verifying that it correctly equals the remainder.- Parameters:
conditionValue- conditionValue in the format 'divisor|remainder'traitValue- the value of the matched trait- Returns:
- true if expression evaluates to true, false if unable to evaluate expression or it evaluates to false
-
-