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
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();
for (String 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 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.equals(
ArrayFilterType.ALL_OF)) {
return false;
}
if (filterItem.contains(objCondition.toString()) && (arrayFilterType.equals(
ArrayFilterType.ANY_OF)) || isNegate) {
return true;
}
}
return arrayFilterType.equals(ArrayFilterType.ALL_OF);
}
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.equals(
ArrayFilterType.ALL_OF)) {
return false;
}
if (filterItem.startsWith(objCondition.toString()) && (
arrayFilterType.equals(ArrayFilterType.ANY_OF) || isNegate)) {
return true;
}
}
return arrayFilterType.equals(ArrayFilterType.ALL_OF);
}
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.equals(
ArrayFilterType.ALL_OF)) {
return false;
}
if (filterItem.endsWith(objCondition.toString()) && (
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 (String str : objFilter) {
if (objCondition.contains(str)) {
return true;
}
}
}
return false;
}
}