|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.atlassian.jira.util.collect.MapBuilder<K,V>
K
- the key typeV
- the value typepublic class MapBuilder<K,V>
Utility for easily creating Maps of all standard types. If your map does not need to
contain null
as either a key or a value, then ImmutableMap.builder()
should be preferred.
Field Summary | |
---|---|
protected Map<K,V> |
map
|
Constructor Summary | |
---|---|
protected |
MapBuilder()
prefer newBuilder() for inferred generic arguments. |
Method Summary | ||
---|---|---|
MapBuilder<K,V> |
add(K key,
V value)
Add a key/value. |
|
MapBuilder<K,V> |
addAll(Map<? extends K,? extends V> map)
Add all the entries contained in the map. |
|
MapBuilder<K,V> |
addIfValueNotNull(K key,
V value)
Add a key/value only if the value is not null . |
|
static
|
build(K key,
V value)
Returns an immutable Map containing the given key-value pair. |
|
static
|
build(K key1,
V value1,
K key2,
V value2)
Returns an immutable Map containing the given key-value pairs. |
|
static
|
build(K key1,
V value1,
K key2,
V value2,
K key3,
V value3)
Returns an immutable Map containing the given key-value pairs. |
|
static
|
build(K key1,
V value1,
K key2,
V value2,
K key3,
V value3,
K key4,
V value4)
Returns an immutable Map containing the given key-value pairs. |
|
static
|
emptyMap()
Static factory method for creating an empty map. |
|
static
|
newBuilder()
Static factory method for creating a fresh MapBuilder . |
|
static
|
newBuilder(K key,
V value)
Static factory method for creating a fresh MapBuilder and adding the given key/value pair. |
|
static
|
newBuilder(K key1,
V value1,
K key2,
V value2)
Static factory method for creating a fresh MapBuilder and adding the given key/value pairs. |
|
static
|
newBuilder(K key1,
V value1,
K key2,
V value2,
K key3,
V value3)
Static factory method for creating a fresh MapBuilder and adding the given key/value pairs. |
|
static
|
newBuilder(K key1,
V value1,
K key2,
V value2,
K key3,
V value3,
K key4,
V value4)
Static factory method for creating a fresh MapBuilder and adding the given key/value pairs. |
|
static
|
newBuilder(Map<? extends K,? extends V> map)
Static factory method for creating a fresh MapBuilder based on the contents of a source Map. |
|
static
|
singletonMap(K key,
V value)
Static factory method for creating an immutable Map with a single entry. |
|
Map<K,V> |
toFastMap()
Deprecated. Use ImmutableMap directly instead. Since v6.1. |
|
SortedMap<K,V> |
toFastSortedMap()
Deprecated. Use ImmutableSortedMap directly instead. Since v6.1. |
|
SortedMap<K,V> |
toFastSortedMap(Comparator<K> comparator)
Deprecated. Use ImmutableSortedMap directly instead. Since v6.1. |
|
HashMap<K,V> |
toHashMap()
Returns a mutable HashMap where the entries are in no defined order. |
|
Map<K,V> |
toImmutableMap()
Deprecated. use toMap() instead, or consider using ImmutableMap if
if the map does not need to accept null s. |
|
LinkedHashMap<K,V> |
toLinkedHashMap()
Returns a mutable LinkedHashMap where the entries are in the same order as they were added. |
|
Map<K,V> |
toListOrderedMap()
Returns an immutable Map where the entries are in the same order as they were added. |
|
Map<K,V> |
toMap()
Returns an immutable Map where the entries are in no defined order. |
|
Map<K,V> |
toMutableMap()
|
|
SortedMap<K,V> |
toSortedMap()
|
|
SortedMap<K,V> |
toSortedMap(Comparator<K> comparator)
|
|
TreeMap<K,V> |
toTreeMap()
|
|
TreeMap<K,V> |
toTreeMap(Comparator<K> comparator)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Map<K,V> map
Constructor Detail |
---|
protected MapBuilder()
newBuilder()
for inferred generic arguments.
Method Detail |
---|
public static <K,V> Map<K,V> emptyMap()
Collections.emptyMap()
and is provided only for completeness.
K
- the key typeV
- the value type
public static <K,V> MapBuilder<K,V> newBuilder()
MapBuilder
.
K
- the key typeV
- the value type
MapBuilder
public static <K,V> MapBuilder<K,V> newBuilder(K key, V value)
MapBuilder
and adding the given key/value pair.
K
- the key typeV
- the value typekey
- the keyvalue
- the value
MapBuilder
public static <K,V> MapBuilder<K,V> newBuilder(K key1, V value1, K key2, V value2)
MapBuilder
and adding the given key/value pairs.
K
- the key typeV
- the value typekey1
- the keyvalue1
- the valuekey2
- the keyvalue2
- the value
MapBuilder
with the specified elementspublic static <K,V> MapBuilder<K,V> newBuilder(K key1, V value1, K key2, V value2, K key3, V value3)
MapBuilder
and adding the given key/value pairs.
K
- the key typeV
- the value typekey1
- the keyvalue1
- the valuekey2
- the keyvalue2
- the valuekey3
- the keyvalue3
- the value
MapBuilder
with the specified elementspublic static <K,V> MapBuilder<K,V> newBuilder(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
MapBuilder
and adding the given key/value pairs.
K
- the key typeV
- the value typekey1
- the keyvalue1
- the valuekey2
- the keyvalue2
- the valuekey3
- the keyvalue3
- the valuekey4
- the keyvalue4
- the value
MapBuilder
with the specified elementspublic static <K,V> MapBuilder<K,V> newBuilder(@Nullable Map<? extends K,? extends V> map)
MapBuilder
based on the contents of a source Map.
K
- the key typeV
- the value typemap
- the source map, may be null
MapBuilder
, populated with the values from map
, if one is providedpublic static <K,V> Map<K,V> singletonMap(K key, V value)
Map
with a single entry. This is
exactly equivalent to Collections.singletonMap(key, value)
and is only provided
for completeness.
K
- the key typeV
- the value typekey
- the keyvalue
- the value
MapBuilder
public static <K,V> Map<K,V> build(K key, V value)
ImmutableMap.of(Object,Object)
if neither key
nor
value
will ever need to be null
.
K
- the key typeV
- the value typekey
- The Keyvalue
- The Value
public static <K,V> Map<K,V> build(K key1, V value1, K key2, V value2)
ImmutableMap.of(Object,Object,Object,Object)
if none of
the keys or values will ever need to be null
.
K
- the key typeV
- the value typekey1
- The Keyvalue1
- The Valuekey2
- The Keyvalue2
- The Value
public static <K,V> Map<K,V> build(K key1, @Nullable V value1, K key2, @Nullable V value2, K key3, @Nullable V value3)
ImmutableMap.of(Object,Object,Object,Object,Object,Object)
if none of
the keys or values will ever need to be null
.
K
- the key typeV
- the value typekey1
- The Keyvalue1
- The Valuekey2
- The Keyvalue2
- The Valuekey3
- The Keyvalue3
- The Value
public static <K,V> Map<K,V> build(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
ImmutableMap.of(Object,Object,Object,Object,Object,Object,Object,Object)
if none of the keys or values will ever need to be null
.
K
- the key typeV
- the value typekey1
- The Keyvalue1
- The Valuekey2
- The Keyvalue2
- The Valuekey3
- The Keyvalue3
- The Valuekey4
- The Keyvalue4
- The Value
public MapBuilder<K,V> add(@Nullable K key, @Nullable V value)
null
s. Prefer ImmutableMap.builder()
if
that is not needed.
key
- the keyvalue
- the value
public MapBuilder<K,V> addIfValueNotNull(K key, @Nullable V value)
null
. If the intent is to
produce an immutable map that does not contain null
values, then
ImmutableMap
should be preferred. This method should only be useful
when intending to call toMutableMap()
.
key
- the keyvalue
- the value
public MapBuilder<K,V> addAll(@Nullable Map<? extends K,? extends V> map)
map
- the map to add
public Map<K,V> toMap()
Map
where the entries are in no defined order.
The map may contain null
s. If this ability is not needed, then
ImmutableMap
is preferred.
Map
where the entries are in no defined order.public HashMap<K,V> toHashMap()
HashMap
where the entries are in no defined order.
HashMap
where the entries are in no defined order.public LinkedHashMap<K,V> toLinkedHashMap()
LinkedHashMap
where the entries are in the same order as they were added.
LinkedHashMap
where the entries are in the same order as they were added.public Map<K,V> toListOrderedMap()
Map
where the entries are in the same order as they were added.
The map may contain null
s. If this ability is not needed, then
using ImmutableMap
is preferred.
Map
where the entries are in the same order as they were added.public SortedMap<K,V> toSortedMap()
SortedMap
where the entries are in the natural order of the keys.
Note that the key type must implement Comparable
.public SortedMap<K,V> toSortedMap(Comparator<K> comparator)
comparator
- used to sort the keys.
SortedMap
where the entries are in the order defined by the
supplied Comparator
.public TreeMap<K,V> toTreeMap()
TreeMap
where the entries are in the natural order of the keys.
Note that the key type must implement Comparable
.public TreeMap<K,V> toTreeMap(Comparator<K> comparator)
comparator
- used to sort the keys.
TreeMap
where the entries are in the order defined by the
supplied Comparator
.public Map<K,V> toMutableMap()
Map
where the entries are in no defined order.@Deprecated public Map<K,V> toFastMap()
ImmutableMap
directly instead. Since v6.1.
ImmutableMap
, which does not accept null
s.
Please use that class directly, instead.
NullPointerException
- if there are any null
s in this builder.public SortedMap<K,V> toFastSortedMap()
ImmutableSortedMap
directly instead. Since v6.1.
ImmutableSortedMap
, which does not accept null
s.
Please use that class directly, instead.
NullPointerException
- if there are any null
s in this builder.
ClassCastException
- if the keys in this builder do not implement Comparable
.public SortedMap<K,V> toFastSortedMap(Comparator<K> comparator)
ImmutableSortedMap
directly instead. Since v6.1.
ImmutableSortedMap
, which does not accept null
s.
Please use that class directly, instead.
comparator
- for sorting the map
NullPointerException
- if there are any null
s in this builder.
ClassCastException
- if the keys in this builder do not implement Comparable
.@Deprecated public Map<K,V> toImmutableMap()
toMap()
instead, or consider using ImmutableMap
if
if the map does not need to accept null
s.
null
s. If that
ability is not needed, then ImmutableMap
is preferred.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |