T
- the type of elements for this dictionary builder@NotThreadSafe public final class DictionaryBuilder<T> extends Object implements Thawed<Dictionary<T>>
This is the "thawed", alterable form of a Dictionary
.
To build a dictionary out of this class, use freeze()
.
All mutation methods return this
, so you can chain
additions/deletions:
final Dictionary<Foo> dict = Dictionary.newBuilder() .addEntry("foo1", foo1).addEntry("foo2", foo2).freeze();
Modifier and Type | Method and Description |
---|---|
DictionaryBuilder<T> |
addAll(Dictionary<T> other)
Add all entries from another dictionary
|
DictionaryBuilder<T> |
addEntry(String key,
T value)
Add one entry to this builder
|
Dictionary<T> |
freeze()
Build an immutable dictionary out of this builder
|
DictionaryBuilder<T> |
removeEntry(String key)
Remove one entry from this builder
|
public DictionaryBuilder<T> addEntry(String key, T value)
key
- the keyvalue
- the valueNullPointerException
- either the key or the value is nullpublic DictionaryBuilder<T> addAll(Dictionary<T> other)
other
- the other dictionaryNullPointerException
- the dictionary is nullpublic DictionaryBuilder<T> removeEntry(String key)
key
- the key to removepublic Dictionary<T> freeze()
freeze
in interface Thawed<Dictionary<T>>
Dictionary
with all elements from this builder