Skip to content

Commit 22aa381

Browse files
authored
"It is finished."
When Jesus therefore had received the vinegar, he said, "It is finished." He bowed his head, and gave up his spirit. (John 19:30)
1 parent 0daa18a commit 22aa381

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
//When Jesus therefore had received the vinegar, he said, "It is finished." He bowed his head, and gave up his spirit. (John 19:30)
3+
4+
package com.javarush.task.task22.task2208;
5+
6+
import java.util.Map;
7+
import java.util.LinkedHashMap;
8+
9+
/*
10+
Формируем WHERE
11+
*/
12+
public class Solution {
13+
public static void main(String[] args) {
14+
Map<String, String> map = new LinkedHashMap<>();
15+
map.put("name","Ivanov");
16+
map.put("country","Ukraine");
17+
map.put("city","Kiev");
18+
map.put("age",null);
19+
map.put("name1","Ivanov");
20+
map.put("name2","Ivanov");
21+
22+
System.out.println(getQuery(map));
23+
}
24+
25+
public static String getQuery(Map<String, String> params) {
26+
StringBuilder result = new StringBuilder();
27+
if (params == null || params.isEmpty())
28+
return result.toString();
29+
30+
for (Map.Entry<String, String> pair : params.entrySet()) {
31+
if (pair.getKey() == null || pair.getValue() == null)
32+
continue;
33+
34+
result.append(pair.getKey()).append(" = '").append(pair.getValue()).append("' and ");
35+
}
36+
37+
if (result.length() > 5)
38+
result.delete(result.length() - 5, result.length());
39+
40+
return result.toString();
41+
}
42+
}
43+
/*
44+
Формируем WHERE
45+
Сформируй часть запроса WHERE используя StringBuilder.
46+
Если значение null, то параметр не должен попадать в запрос.
47+
48+
Пример:
49+
{"name", "Ivanov", "country", "Ukraine", "city", "Kiev", "age", null}
50+
51+
Результат:
52+
"name = 'Ivanov' and country = 'Ukraine' and city = 'Kiev'"
53+
54+
55+
Требования:
56+
1. Метод getQuery должен принимать один параметр типа Map.
57+
2. Метод getQuery должен иметь тип возвращаемого значения String.
58+
3. Метод getQuery должен быть статическим.
59+
4. Метод getQuery должен возвращать строку сформированную по правилам описанным в условии задачи.
60+
*/

0 commit comments

Comments
 (0)