com.github.fge.jsonschema.core.util
Class DictionaryBuilder<T>

java.lang.Object
  extended by com.github.fge.jsonschema.core.util.DictionaryBuilder<T>
Type Parameters:
T - the type of elements for this dictionary builder
All Implemented Interfaces:
Thawed<Dictionary<T>>

@NotThreadSafe
public final class DictionaryBuilder<T>
extends Object
implements Thawed<Dictionary<T>>

A dictionary builder

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();
 


Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addEntry

public DictionaryBuilder<T> addEntry(String key,
                                     T value)
Add one entry to this builder

Parameters:
key - the key
value - the value
Returns:
this
Throws:
NullPointerException - either the key or the value is null

addAll

public DictionaryBuilder<T> addAll(Dictionary<T> other)
Add all entries from another dictionary

Parameters:
other - the other dictionary
Returns:
this
Throws:
NullPointerException - the dictionary is null

removeEntry

public DictionaryBuilder<T> removeEntry(String key)
Remove one entry from this builder

Parameters:
key - the key to remove
Returns:
this

freeze

public Dictionary<T> freeze()
Build an immutable dictionary out of this builder

Specified by:
freeze in interface Thawed<Dictionary<T>>
Returns:
a new Dictionary with all elements from this builder