-
-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathInternalMap.java
More file actions
29 lines (20 loc) · 809 Bytes
/
InternalMap.java
File metadata and controls
29 lines (20 loc) · 809 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
package java_integration.fixtures;
import java.util.*;
import java.util.stream.Collectors;
public class InternalMap<K, V> extends AbstractMap<K, V> {
private final AbstractSet<Map.Entry<K,V>> entries = new HashSet<>();
public V put(K key, V value) {
Optional<Map.Entry<K,V>> entry = entries.stream().filter((e) -> e.getKey().equals(key)).findFirst();
if (entry.isPresent()) {
entries.remove(entry.get());
}
entries.add(new SimpleEntry(key, value));
return entry.isPresent() ? entry.get().getValue() : null;
}
public Set<Map.Entry<K,V>> entrySet() {
return entries.stream().filter((e) -> !e.getKey().toString().startsWith("_")).collect(Collectors.toSet());
}
public int size() {
return entries.size();
}
}