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

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

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


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy