package dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface Utils {
    static String whereAnd(Map<String,String> map){
        List<String> list = linkKeyValue(map);
        String sql = "WHERE ";
        for(String s:list){
            sql+=s+" AND ";
        }
        sql = utils.Utils.cutTail(sql,5)+"";
        return sql;
    }
    //with ", "
    static String linkColumn(List<String> list){
        String sql = "";
        for(String c:list){
            sql+=c+", ";
        }
        return utils.Utils.cutTail(sql,2);
    }
    //with " = "
    static List<String> linkKeyValue(Map<String, String> map){
        List<String> list = new ArrayList<>();
        for(Map.Entry<String,String> entry:map.entrySet()){
            list.add(entry.getKey()+" = \'"+entry.getValue()+"\'");
        }
        return list;
    }
}
