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

com.github.sidhant92.boolparser.operator.InOperator Maven / Gradle / Ivy

The newest version!
package com.github.sidhant92.boolparser.operator;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.github.sidhant92.boolparser.constant.ContainerDataType;
import com.github.sidhant92.boolparser.constant.DataType;
import com.github.sidhant92.boolparser.constant.Operator;
import lombok.AllArgsConstructor;

/**
 * @author sidhant.aggarwal
 * @since 05/03/2023
 */
@AllArgsConstructor
public class InOperator extends AbstractOperator {
    private final EqualsOperator equalsOperator;

    @Override
    public > boolean evaluate(final ContainerDataType containerDataType, final DataType dataType,
                                                              final Object leftOperand, final Object... rightOperands) {
        return Arrays
                .stream(rightOperands).anyMatch(a -> equalsOperator.evaluate(containerDataType, dataType, leftOperand, a));
    }

    @Override
    public Operator getOperator() {
        return Operator.IN;
    }

    @Override
    public String getSymbol() {
        return "IN";
    }

    @Override
    public List getAllowedContainerTypes() {
        return Collections.singletonList(ContainerDataType.PRIMITIVE);
    }

    @Override
    public List getAllowedDataTypes() {
        return Arrays.asList(DataType.values());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy