Package org.apache.juneau.internal
Class MapBuilder<K,V>
java.lang.Object
org.apache.juneau.internal.MapBuilder<K,V>
- Type Parameters:
K
- Key type.V
- Value type.
Builder for maps.
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionMapBuilder<K,
V> Adds a single entry to this map.MapBuilder<K,
V> Appends the contents of the specified map into this map.MapBuilder<K,
V> Adds arbitrary values to this list.MapBuilder<K,
V> Adds entries to this list via JSON object strings.MapBuilder<K,
V> Adds a list of key/value pairs to this map.build()
Builds the map.MapBuilder<K,
V> copy()
Forces the existing set to be copied instead of appended to.MapBuilder<K,
V> sorted()
Converts the set into aSortedMap
.MapBuilder<K,
V> sorted
(Comparator<K> comparator) Converts the set into aSortedMap
using the specified comparator.MapBuilder<K,
V> sparse()
When specified, thebuild()
method will returnnull if the map is empty.MapBuilder<K,
V> When specified,build()
will return an unmodifiable map.
-
Constructor Details
-
MapBuilder
Constructor.- Parameters:
keyType
- The key type.valueType
- The value type.valueTypeArgs
- The value type generic arguments if there are any.
-
MapBuilder
Constructor.- Parameters:
addTo
- The map to add to.
-
-
Method Details
-
build
Builds the map.- Returns:
- A map conforming to the settings on this builder.
-
sparse
When specified, thebuild()
method will returnnull if the map is empty.Otherwise
build()
will never returnnull .- Returns:
- This object.
-
unmodifiable
When specified,build()
will return an unmodifiable map.- Returns:
- This object.
-
copy
Forces the existing set to be copied instead of appended to.- Returns:
- This object.
-
sorted
Converts the set into aSortedMap
.- Returns:
- This object.
-
sorted
Converts the set into aSortedMap
using the specified comparator.- Parameters:
comparator
- The comparator to use for sorting.- Returns:
- This object.
-
addAll
Appends the contents of the specified map into this map.This is a no-op if the value is
null .- Parameters:
value
- The map to add to this map.- Returns:
- This object.
-
add
Adds a single entry to this map.- Parameters:
key
- The map key.value
- The map value.- Returns:
- This object.
-
addJson
Adds entries to this list via JSON object strings.- Parameters:
values
- The JSON object strings to parse and add to this list.- Returns:
- This object.
-
addAny
Adds arbitrary values to this list.Objects can be any of the following:
- Maps of key/value types convertible to the key/value types of this map.
- JSON object strings parsed and convertible to the key/value types of this map.
- Parameters:
values
- The values to add.- Returns:
- This object.
-
addPairs
Adds a list of key/value pairs to this map.- Parameters:
pairs
- The pairs to add.- Returns:
- This object.
-