-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
73 lines (50 loc) · 2.42 KB
/
Solution.java
File metadata and controls
73 lines (50 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//His mother saith unto the servants, Whatsoever he saith unto you, do it. (John 2:5)
package com.javarush.task.task37.task3705;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
/*
Ambiguous behavior for NULL
*/
public class Solution {
public static void main(String[] args) {
Map expectedMap = getExpectedMap();
System.out.println("****** check the key \"s\" whether it IS NOT in the map");
checkObject(expectedMap, "s");
System.out.println("\n****** check the key \"s\" whether it IS in the map");
expectedMap.put("s", "vvv");
checkObject(expectedMap, "s");
System.out.println("\n****** ambiguous behavior for NULL");
expectedMap.put(null, null);
checkObject(expectedMap, null);
/* expected output for NULL
****** ambiguous behavior for NULL
map contains the value for key = null
map does NOT contain the value for key = null
*/
}
public static Map getExpectedMap() {
return new HashMap();
}
public static void checkObject(Map map, Object key) {
String s1 = map.containsKey(key) ?
"map contains the value for key = " + key : "map does NOT contain the value for key = " + key;
System.out.println(s1);
//if value is null, it means that the map doesn't contain the value
Object value = map.get(key);
String s2 = value != null ?
"map contains the value for key = " + key : "map does NOT contain the value for key = " + key;
System.out.println(s2);
}
}
/*
Ambiguous behavior for NULL
Измени реализацию метода getExpectedMap, он должен вернуть объект такого класса, для которого будет противоположное поведение при добавлении ссылки null.
См. пример вывода в методе main.
Остальной код не менять.
Требования:
1. Метод getExpectedMap не должен возвращать объект типа Hashtable.
2. Метод getExpectedMap должен возвращать стандартную реализацию Map удовлетворяющую условию задачи.
3. Метод main класса Solution должен выводить данные на экран.
4. Метод getExpectedMap должен быть статическим.
*/