Package eu.bandm.tools.util.java
Class Collections.MapBuilder<K,V>
java.lang.Object
eu.bandm.tools.util.java.Collections.MapBuilder<K,V>
- Type Parameters:
K- the type of keysV- the type of values
- All Implemented Interfaces:
BiConsumer<K,V>
- Enclosing class:
Collections
Helper class for building maps incrementally.
Operations of this class are not thread-safe. Use external synchronization if needed.
-
Constructor Details
-
MapBuilder
public MapBuilder()Creates a new empty instance.
-
-
Method Details
-
accept
Adds an entry.Null keys and/or values are not recommended; they may or may not be supported by the map implementation to be used.
- Specified by:
acceptin interfaceBiConsumer<K,V> - Parameters:
key- the keyvalue- the value- Throws:
IllegalArgumentException- if the given key already has a valueIllegalStateException- if theclose()operation has already been invoked
-
add
Adds an entry.Null keys and/or values are not recommended; they may or may not be supported by the map implementation to be used.
- Parameters:
key- the keyvalue- the value- Returns:
this- Throws:
IllegalArgumentException- if the given key already has a valueIllegalStateException- if theclose()operation has already been invoked
-
close
Returns the completed map and releases resources.This method can be called only once; the map builder is then rendered useless and should be discarded.
- Returns:
- an unmodifiable map containing all the entries previously added
- Throws:
IllegalStateException- if this operation has already been invoked
-