Валидатор не пропускает, на мой взгляд выполнено правильно.
package com.javarush.task.task22.task2208;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/*
Формируем WHERE
*/
public class Solution {
public static void main(String[] args) {
Map<String, String> map = new LinkedHashMap<>();
map.put("name", null);
map.put("country",null);
map.put("city", null);
map.put("age", null);
System.out.println(getQuery(map));
}
public static String getQuery(Map<String, String> params) {
StringBuilder sb = new StringBuilder();
if (!params.isEmpty()){
Iterator<Map.Entry<String, String>> element = params.entrySet().iterator();
while (element.hasNext()){
Map.Entry<String, String> el = element.next();
if (el.getValue() != null){
sb.append(String.format("%s = '%s' and ", el.getKey(), el.getValue()));
}
else{
if (sb.length()>0) sb.delete(sb.length() - 5, sb.length());
}
}
}
return sb.toString();
}
}