com.moengage.operator.StringArrayOperation 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
The newest version!
package com.moengage.operator;
import java.util.ArrayList;
import com.moengage.datatype.MOEDataType;
import com.moengage.enum_models.ArrayFilterType;
@SuppressWarnings({"unchecked", "rawtypes"})
public class StringArrayOperation extends BaseOperation {
//public class DoubleArrayOperation & MOEDataType>> extends BaseOperation {
public StringArrayOperation() {
super();
}
public boolean equals(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
Object objFilter = filterObject.cast();
Object objCondition = conditionObject.cast();
ArrayList objFilterList = (ArrayList) objFilter;
if (objFilterList.isEmpty()){
return false;
// when payload is empty ; equals is always false
}
for (String filterItem : objFilterList) {
if (!filterItem.equals(objCondition) && ArrayFilterType.ALL_OF.equals(arrayFilterType)) {
return false;
}
if (filterItem.equals(objCondition) && (ArrayFilterType.ANY_OF.equals(arrayFilterType) || isNegate)) {
return true;
}
}
return ArrayFilterType.ALL_OF.equals(arrayFilterType);
}
public boolean contains(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
Object objFilter = filterObject.cast();
Object objCondition = conditionObject.cast();
for (String filterItem : (ArrayList) objFilter) {
if (!filterItem.contains(objCondition.toString()) && ArrayFilterType.ALL_OF.equals(arrayFilterType)) {
return false;
}
if (filterItem.contains(objCondition.toString()) && (ArrayFilterType.ANY_OF.equals(arrayFilterType)) || isNegate) {
return true;
}
}
return ArrayFilterType.ALL_OF.equals(arrayFilterType);
}
public boolean startsWith(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
Object objFilter = filterObject.cast();
Object objCondition = conditionObject.cast();
for (String filterItem : (ArrayList) objFilter) {
if (!filterItem.startsWith(objCondition.toString()) && ArrayFilterType.ALL_OF.equals(
arrayFilterType)) {
return false;
}
if (filterItem.startsWith(objCondition.toString()) && (
ArrayFilterType.ANY_OF.equals(arrayFilterType) || isNegate)) {
return true;
}
}
return ArrayFilterType.ALL_OF.equals(arrayFilterType);
}
public boolean endsWith(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
Object objFilter = filterObject.cast();
Object objCondition = conditionObject.cast();
for (String filterItem : (ArrayList) objFilter) {
if (!filterItem.endsWith(objCondition.toString()) && ArrayFilterType.ALL_OF.equals(
arrayFilterType)) {
return false;
}
if (filterItem.endsWith(objCondition.toString()) && (
ArrayFilterType.ANY_OF.equals(arrayFilterType) || isNegate)) {
return true;
}
}
return ArrayFilterType.ALL_OF.equals(arrayFilterType);
}
public boolean inTheFollowing(T filterObject, T conditionObject, String arrayFilterType,
boolean isNegate) {
ArrayList objFilter = (ArrayList) filterObject.cast();
ArrayList objCondition = (ArrayList) conditionObject.cast();
if (ArrayFilterType.ALL_OF.equals(arrayFilterType)) {
if (objFilter.isEmpty()){
return false;
}
return objCondition.containsAll(objFilter);
} else if (ArrayFilterType.ANY_OF.equals(arrayFilterType) || isNegate) {
for (String str : objFilter) {
if (objCondition.contains(str)) {
return true;
}
}
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy