-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMap.java
More file actions
48 lines (33 loc) · 935 Bytes
/
Map.java
File metadata and controls
48 lines (33 loc) · 935 Bytes
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
package ssj.algorithm;
import com.google.common.base.Preconditions;
import java.util.Iterator;
/**
* Created by shenshijun on 15/2/3.
*/
public interface Map<K, V> {
void set(K key, V value);
V get(K key);
public default V getDefault(K key, V default_value) {
Preconditions.checkNotNull(key);
V value = get(key);
return (value == null) ? default_value : value;
}
public default V setIfAbsent(K key, V default_value){
Preconditions.checkNotNull(key);
V value = get(key);
if (value == null) {
set(key, default_value);
value = default_value;
}
return value;
}
public int size();
boolean containsKey(K key);
MapIterator<K, V> iterator();
Iterator<K> keyIterator();
Iterator<V> valueIterator();
public default boolean isEmpty() {
return size() <= 0;
}
V remove(K key);
}