com.moengage.operator.DoubleArrayOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of condition-evaluator Show documentation
Show all versions of condition-evaluator Show documentation
Condition Evaluator for MoEngage Platform
package com.moengage.operator;
import com.moengage.datatype.MOEDataType;
import com.moengage.enum_models.ArrayFilterType;
import java.util.ArrayList;
@SuppressWarnings({"unchecked", "rawtypes"})
public class DoubleArrayOperation & MOEDataType> extends BaseOperation {
public DoubleArrayOperation() {
super();
}
public boolean equals(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
Object objFilter = filterObject.cast();
Object objCondition = conditionObject.cast();
for (Double filterItem : (ArrayList) objFilter) {
if (!filterItem.equals(objCondition) && arrayFilterType.equals(
ArrayFilterType.ALL_OF)) {
return false;
}
if (filterItem.equals(objCondition) && (arrayFilterType.equals(ArrayFilterType.ANY_OF)
|| isNegate)) {
return true;
}
}
return arrayFilterType.equals(ArrayFilterType.ALL_OF);
}
public boolean lessThan(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
Object objFilter = filterObject.cast();
Object objCondition = conditionObject.cast();
for (Double filterItem : (ArrayList) objFilter) {
if (filterItem >= (Double) objCondition && arrayFilterType.equals(
ArrayFilterType.ALL_OF)) {
return false;
}
if (filterItem < (Double) objCondition && (
arrayFilterType.equals(ArrayFilterType.ANY_OF) || isNegate)) {
return true;
}
}
return arrayFilterType.equals(ArrayFilterType.ALL_OF);
}
public boolean between(T filterObject, T startConditionObject, T maxConditionObject,
String arrayFilterType, boolean isNegate) {
Object objFilter = filterObject.cast();
Object objStartCondition = startConditionObject.cast();
Object objMaxCondition = maxConditionObject.cast();
for (Double filterItem : (ArrayList) objFilter) {
if (!(filterItem >= (Double) objStartCondition && filterItem < (Double) objMaxCondition)
&& arrayFilterType.equals(ArrayFilterType.ALL_OF)) {
return false;
}
if (filterItem >= (Double) objStartCondition && filterItem < (Double) objMaxCondition
&& (arrayFilterType.equals(ArrayFilterType.ANY_OF) || isNegate)) {
return true;
}
}
return arrayFilterType.equals(ArrayFilterType.ALL_OF);
}
public boolean greaterThan(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
Object objFilter = filterObject.cast();
Object objCondition = conditionObject.cast();
for (Double filterItem : (ArrayList) objFilter) {
if (filterItem <= (Double) objCondition && arrayFilterType.equals(
ArrayFilterType.ALL_OF)) {
return false;
}
if (filterItem > (Double) objCondition && (
arrayFilterType.equals(ArrayFilterType.ANY_OF) || isNegate)) {
return true;
}
}
return arrayFilterType.equals(ArrayFilterType.ALL_OF);
}
public boolean inTheFollowing(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
ArrayList objFilter = (ArrayList) filterObject.cast();
ArrayList objCondition = (ArrayList) conditionObject.cast();
if (arrayFilterType.equals(ArrayFilterType.ALL_OF)) {
return objCondition.containsAll(objFilter);
} else if (arrayFilterType.equals(ArrayFilterType.ANY_OF) || isNegate) {
for (Double d : objFilter) {
if (objCondition.contains(d)) {
return true;
}
}
}
return false;
}
}