All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.moengage.operator.StringArrayOperation Maven / Gradle / Ivy

There is a newer version: 1.3.7
Show 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();
        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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy