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

org.mybatis.dynamic.sql.where.condition.IsBetween Maven / Gradle / Ivy

/**
 *    Copyright 2016-2019 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.mybatis.dynamic.sql.where.condition;

import java.util.function.BiPredicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

import org.mybatis.dynamic.sql.AbstractTwoValueCondition;

public class IsBetween extends AbstractTwoValueCondition {

    protected IsBetween(Supplier valueSupplier1, Supplier valueSupplier2) {
        super(valueSupplier1, valueSupplier2);
    }
    
    protected IsBetween(Supplier valueSupplier1, Supplier valueSupplier2, BiPredicate predicate) {
        super(valueSupplier1, valueSupplier2, predicate);
    }
    
    @Override
    public String renderCondition(String columnName, String placeholder1, String placeholder2) {
        return columnName + " between " + placeholder1 + " and " + placeholder2; //$NON-NLS-1$ //$NON-NLS-2$
    }

    public static class Builder extends AndGatherer> {
        private Builder(Supplier valueSupplier1) {
            super(valueSupplier1);
        }
        
        @Override
        protected IsBetween build() {
            return new IsBetween<>(valueSupplier1, valueSupplier2);
        }
    }
    
    public static  Builder isBetween(Supplier valueSupplier1) {
        return new Builder<>(valueSupplier1);
    }

    public IsBetween when(BiPredicate predicate) {
        return new IsBetween<>(valueSupplier1, valueSupplier2, predicate);
    }

    public IsBetween then(UnaryOperator transformer1, UnaryOperator transformer2) {
        return shouldRender() ? new IsBetween<>(() -> transformer1.apply(value1()),
                () -> transformer2.apply(value2())) : this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy