|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.staccatocommons.lang.MapBuilder<K,V,M>
K - V - M - public class MapBuilder<K,V,M extends Map<K,V>>
A Builder for Maps. With the exception of
from(Map, Applicable), all factory methods of MapBuilder
grant to return builders that build Unmodifiable maps
| Constructor Summary | |
|---|---|
MapBuilder(M map,
net.sf.staccatocommons.defs.Applicable<M,M> wrapperFunction)
Creates a new MapBuilder |
|
| Method Summary | ||
|---|---|---|
M |
build()
Returns the built object. |
|
static
|
from(Map<K,V> map)
Creates a new MapBuilder that uses the given map instance, and
using toUnmodifiableMap() as postprocessor. |
|
static
|
linkedMapWith(K key,
V value)
Creates a new MapBuilder using a LinkedHashMap as map
implementation and the first key and value. |
|
static
|
mapWith(K key,
V value)
Creates a new MapBuilder using a HashMap as map
implementation and the first key and value. |
|
static
|
toUnmodifiableMap()
A constant function that returns an unmodifiable view of its map argument |
|
static
|
toUnmodifiableSortedMap()
A constant function that returns an unmodifiable view of its sortedmap argument |
|
static
|
treeMapWith(K key,
V value)
Creates a new MapBuilder using a TreeMap as map
implementation and the first key and value. |
|
MapBuilder<K,V,M> |
unwrap()
Disables wrapping, which means that a built map will be returned just as it was created. |
|
MapBuilder<K,V,M> |
with(K key,
V value)
Adds a key-value pair to the map |
|
MapBuilder<K,V,M> |
with(Map.Entry<K,V> entry)
Adds an entry to the map |
|
MapBuilder<K,V,M> |
withWrapper(net.sf.staccatocommons.defs.Applicable<M,M> wrapperFunction)
Sets the wrapper function, that is, the Applicable to apply to the
resulting map before returning it through build(). |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MapBuilder(@NonNull
M map,
@NonNull
net.sf.staccatocommons.defs.Applicable<M,M> wrapperFunction)
MapBuilder
map - the map to build. Non null| Method Detail |
|---|
@NonNull
public MapBuilder<K,V,M> with(K key,
V value)
key - value -
MapBuilder
@NonNull
public MapBuilder<K,V,M> with(@NonNull
Map.Entry<K,V> entry)
entry - the entry to add. Non null
MapBuilder
@NonNull
public MapBuilder<K,V,M> withWrapper(@NonNull
net.sf.staccatocommons.defs.Applicable<M,M> wrapperFunction)
Applicable to apply to the
resulting map before returning it through build().
By default, maps are wrapped with unmodifiable wrappers, but this behavior
can be changed through this method.
wrapperFunction -
@NonNull public MapBuilder<K,V,M> unwrap()
build() will be modifiable.
@NonNull public M build()
Builder
Builders are not meant to be used more than once. So this method can only
be invoked successfully one time. Subsequent invocations after a successful
return will throw an BuilderAlreadyUsedException. However,
implementors may relax this, and be reusable, that is being able to be used
more than once; such implementors should document that feature.
Builders may impose restriction to the state of the object under
construction. If such constraints are not met while invoking this method, a
ObjectUnderConstructionException exception must be thrown.
build in interface Builder<M extends Map<K,V>>
@NonNull
public static <K,V> MapBuilder<K,V,Map<K,V>> from(@NonNull
Map<K,V> map)
MapBuilder that uses the given map instance, and
using toUnmodifiableMap() as postprocessor. The map built by the
returned Builder grants to be Unmodifiable
K - V - map -
MapBuilder that builds unmodifiable views of the
given map
@NonNull
public static <K,V> MapBuilder<K,V,Map<K,V>> mapWith(K key,
V value)
MapBuilder using a HashMap as map
implementation and the first key and value. The map built by the returned
Builder grants to be Unmodifiable
K - type of keyV - type of valuekey - value -
MapBuilder
@NonNull
public static <K,V> MapBuilder<K,V,Map<K,V>> linkedMapWith(K key,
V value)
MapBuilder using a LinkedHashMap as map
implementation and the first key and value. The map built by the returned
Builder grants to be Unmodifiable
K - type of keyV - type of valuekey - value -
MapBuilder
@NonNull
public static <K,V> MapBuilder<K,V,SortedMap<K,V>> treeMapWith(K key,
V value)
MapBuilder using a TreeMap as map
implementation and the first key and value. The map built by the returned
Builder grants to be Unmodifiable
K - type of keyV - type of valuekey - value -
MapBuilder@Constant public static <K,V> net.sf.staccatocommons.defs.function.Function<Map<K,V>,Map<K,V>> toUnmodifiableMap()
K - V -
Function@Constant public static <K,V> net.sf.staccatocommons.defs.function.Function<SortedMap<K,V>,SortedMap<K,V>> toUnmodifiableSortedMap()
K - V -
Function
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||