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>
- Direct Known Subclasses:
LocationTree.Builder
- Enclosing class:
Collections
Helper class for building maps incrementally.
Operations of this class are type-safe but not thread-safe. Use external synchronization if needed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.Adds an entry for a new key.close()Returns the completed map and releases resources.Returns the completed map and releases resources.Adds or overwrites an entry.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiConsumer
andThen
-
Constructor Details
-
MapBuilder
public MapBuilder()Creates a new empty instance.
-
-
Method Details
-
accept
Deprecated.Usethis::addorthis::putinstead.Adds an entry for a new key.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 for a new key.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, for method chaining- Throws:
IllegalArgumentException- if the given key already has a valueIllegalStateException- if theclose()operation has already been invoked
-
put
Adds or overwrites 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, for method chaining- Throws:
IllegalStateException- if theclose()operation has already been invoked- Since:
- 1.1
-
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
-
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.
- Parameters:
create- an operation that creates the result map from a temporary- Returns:
- a map of the specified kind containing all the entries previously added
- Throws:
IllegalStateException- if this operation has already been invokedNullPointerException- ifcreateis null- Since:
- 1.3
-
this::addorthis::putinstead.