V
- The value type for built maps.public final class MapBuilder<V> extends Object
This class can be used to create builders for objects that use values (like obfuscators) per keys, where each key can be treated individually as case sensitive or case insensitive.
Note that like a TreeMap
created with String.CASE_INSENSITIVE_ORDER
, maps built with this builder fail to obey the general
contract of Map.equals(Object)
if they contain any case insensitive mappings. Two maps built with the same settings will be equal to
each other though.
Constructor and Description |
---|
MapBuilder()
Creates a new map builder.
|
Modifier and Type | Method and Description |
---|---|
Map<String,V> |
build()
Returns an immutable map with the entries added to this builder.
|
MapBuilder<V> |
caseInsensitiveByDefault()
Sets the default case sensitivity for new entries to
CaseSensitivity.CASE_INSENSITIVE . |
MapBuilder<V> |
caseSensitiveByDefault()
Sets the default case sensitivity for new entries to
CaseSensitivity.CASE_SENSITIVE . |
MapBuilder<V> |
testEntry(String key)
Tests that an entry can be added.
|
MapBuilder<V> |
testEntry(String key,
CaseSensitivity caseSensitivity)
Tests that an entry can be added.
|
<R> R |
transform(Function<? super MapBuilder<?>,? extends R> f)
This method allows the application of a function to this builder.
|
MapBuilder<V> |
withEntry(String key,
V value)
Adds an entry.
|
MapBuilder<V> |
withEntry(String key,
V value,
CaseSensitivity caseSensitivity)
Adds an entry.
|
public MapBuilder<V> withEntry(String key, V value)
withEntry(String, Object, CaseSensitivity)
with the last specified default case sensitivity using
caseSensitiveByDefault()
or caseInsensitiveByDefault()
. The default is CaseSensitivity.CASE_SENSITIVE
.key
- The key for the entry.value
- The value for the entry.NullPointerException
- If the key or value is null
.IllegalArgumentException
- If an entry with the same key and the same case sensitivity was already added.public MapBuilder<V> withEntry(String key, V value, CaseSensitivity caseSensitivity)
key
- The key for the entry.value
- The value for the entry.caseSensitivity
- The case sensitivity for the key.NullPointerException
- If the key, value or case sensitivity is null
.IllegalArgumentException
- If an entry with the same key and the same case sensitivity was already added.public MapBuilder<V> testEntry(String key)
withEntry(String, Object)
except it doesn't actually add the entry.
It can be used to validate entries first.key
- The key for the entry.NullPointerException
- If the key, value or case sensitivity is null
.IllegalArgumentException
- If an entry with the same key and the same case sensitivity was already added.public MapBuilder<V> testEntry(String key, CaseSensitivity caseSensitivity)
withEntry(String, Object, CaseSensitivity)
except it doesn't actually add the entry.
It can be used to validate entries first.key
- The key for the entry.caseSensitivity
- The case sensitivity for the key.NullPointerException
- If the key or case sensitivity is null
.IllegalArgumentException
- If an entry with the same key and the same case sensitivity was already added.public MapBuilder<V> caseSensitiveByDefault()
CaseSensitivity.CASE_SENSITIVE
. This is the default setting.
Note that this will not change the case sensitivity of any entry that was already added.
public MapBuilder<V> caseInsensitiveByDefault()
CaseSensitivity.CASE_INSENSITIVE
.
Note that this will not change the case sensitivity of any entry that was already added.
public <R> R transform(Function<? super MapBuilder<?>,? extends R> f)
Any exception thrown by the function will be propagated to the caller.
R
- The type of the result of the function.f
- The function to apply.Copyright © 2020–2023. All rights reserved.