4 пункт
package com.javarush.task.task22.task2208;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.HashMap;
/*
Формируем WHERE
*/
public class Solution {
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<>();
map.put(null, null);
map.put("country", "Ukraine");
map.put("city", "Kiev");
map.put("age", null);
System.out.println(getQuery(map));
}
public static String getQuery(Map<String, String> params) {
String ss = "";
StringBuilder sb = new StringBuilder(ss);
// name = 'Ivanov' and country = 'Ukraine' and city = 'Kiev'
for (Map.Entry<String, String> pair : params.entrySet()) {
if( pair.getValue() != null && pair.getKey() != null) {
sb.append(pair.getKey());
sb.append(" = ");
sb.append("'"+pair.getValue()+"'");
sb.append(" and ");
}
if( pair.getValue() ==null)
sb.append("");
}
sb.setLength(sb.length() -5);
return sb.toString();
}
}