-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRefToRefDictionary.java
More file actions
35 lines (27 loc) · 1.11 KB
/
RefToRefDictionary.java
File metadata and controls
35 lines (27 loc) · 1.11 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
package javasabr.rlib.collections.dictionary;
import java.util.function.BiConsumer;
import javasabr.rlib.collections.dictionary.impl.ImmutableHashBasedRefToRefDictionary;
import javasabr.rlib.collections.dictionary.impl.SimpleRefToRefEntry;
public interface RefToRefDictionary<K, V> extends Dictionary<K, V> {
static <K, V> RefToRefEntry<K, V> entry(K key, V value) {
return new SimpleRefToRefEntry<>(key, value);
}
static <K, V> RefToRefDictionary<K, V> empty() {
return ImmutableHashBasedRefToRefDictionary.empty();
}
static <K, V> RefToRefDictionary<K, V> of(K key, V value) {
return ofEntries(entry(key, value));
}
static <K, V> RefToRefDictionary<K, V> of(K k1, V v1, K k2, V v2) {
return ofEntries(entry(k1, v1), entry(k2, v2));
}
@SafeVarargs
static <K, V> RefToRefDictionary<K, V> ofEntries(RefToRefEntry<K, V>... entries) {
MutableRefToRefDictionary<K, V> mutable = DictionaryFactory.mutableRefToRefDictionary();
for (var entry : entries) {
mutable.put(entry.key(), entry.value());
}
return mutable.toReadOnly();
}
void forEach(BiConsumer<K, V> consumer);
}