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

cn.icuter.jsql.condition.Conditions Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package cn.icuter.jsql.condition;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author edward
 * @since 2018-08-05
 */
public class Conditions implements Condition {

    private final Combination combination;
    private List conditionList;

    Conditions(Combination combination) {
        this.combination = combination;
        conditionList = new LinkedList<>();
    }

    Conditions addCondition(List conditionList) {
        this.conditionList.addAll(conditionList);
        return this;
    }

    Conditions addCondition(Condition ...condition) {
        Collections.addAll(conditionList, condition);
        return this;
    }

    public String toSql() {
        return "(" + conditionList.stream()
                .map(Condition::toSql)
                .collect(Collectors.joining(" " + combination.getSymbol() + " ")) + ")";
    }

    @Override
    public String getField() {
        throw new UnsupportedOperationException("getField does not support in Conditions");
    }

    @Override
    public Object getValue() {
        return conditionList.stream().filter(condition -> condition.prepareType() == PrepareType.PLACEHOLDER.getType())
                .map(Condition::getValue).collect(Collectors.toList());
    }

    @Override
    public int prepareType() {
        return PrepareType.PLACEHOLDER.getType();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy