|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.core.MapUtil
public final class MapUtil
Map Utilities. These are helper functions for dealing with maps.
Nested Class Summary | |
---|---|
static interface |
MapUtil.Transformer<V,W>
|
Field Summary | |
---|---|
static java.lang.Class |
ImmutableMapClass
|
Method Summary | ||
---|---|---|
static boolean |
allElementsAreStrings(java.util.List<?> v)
Returns whether all list elements are strings |
|
static
|
cloneMap(java.util.Map<K,V> m)
Helper method to clone a map |
|
static
|
concurrentMap()
Creates an empty ConcurrentHashMap |
|
static java.util.Map |
convertListToMap(java.util.List keys)
Create a Map of Maps from a List. |
|
static java.util.SortedMap |
copyAndSortMap(java.util.Map<java.lang.String,java.lang.Object> source)
Copies the contents of a Map into a SortedMap. |
|
static java.util.Map |
copyMap(java.util.Map source)
Copy a Map. |
|
static void |
deserializeFromString(java.util.Map m,
java.lang.String serialized)
Populates the hashtable with serialized data from the string. |
|
static java.util.Map |
diff(java.util.Map change,
java.util.Map baseline)
|
|
static
|
elementsArray(java.util.Map<?,? extends T> ht)
Returns an Object array containing the Map's elements. |
|
static
|
elementsList(java.util.Map<?,? extends T> ht)
Returns a List containing the Map's elements. |
|
static java.util.Iterator |
enumerationToIterator(java.util.Enumeration e)
A simple wrapper to convert an Enumeration to an Iterator. |
|
static void |
fromSerializedString(java.util.Map m,
java.lang.String serialized)
Populates the hashtable with serialized data from the string. |
|
static java.math.BigDecimal |
getBigDecimalArg(java.util.Map args,
java.lang.String key)
Get a Big Decimal value out of the exported map |
|
static boolean |
getBooleanArg(java.util.Map args,
java.lang.String key)
Get a Boolean value out of the exported map |
|
static Date |
getDateArg(java.util.Map args,
java.lang.String key)
Get a date value out of the exported map |
|
static java.lang.Double |
getDoubleArg(java.util.Map args,
java.lang.String key)
Get a double value out of the exported map |
|
static java.lang.Double |
getDoubleArgOrNull(java.util.Map args,
java.lang.String key)
Get a double value out of the exported map |
|
static java.util.Map |
getHashtableArg(java.util.Map args,
java.lang.String key)
Get a Map value out of the exported map |
|
static int |
getIntArg(java.util.Map args,
java.lang.String key)
Get an int value out of the exported map |
|
static java.lang.Integer |
getIntArgOrNull(java.util.Map args,
java.lang.String key)
Get an int value out of the exported map |
|
static
|
getListArg(java.util.Map args,
java.lang.String key)
Get a List value out of the map |
|
static java.lang.Long |
getLongArg(java.util.Map args,
java.lang.String key)
Get a long value out of the exported map |
|
static java.lang.Long |
getLongArgOrNull(java.util.Map args,
java.lang.String key)
Get a long value out of the exported map |
|
static
|
getMapArg(java.util.Map args,
java.lang.String key)
Get a Map value out of the map |
|
static java.lang.Object |
getPath(java.util.Map map,
java.lang.String path)
Fetch the object (if any) in the designated Map, at the coordinates specified by the path, using dot notation. |
|
static java.lang.String |
getStringArg(java.util.Map args,
java.lang.String key)
Get a string value out of the map |
|
static java.util.List |
getVectorArg(java.util.Map args,
java.lang.String key)
Get a List value out of the map |
|
static java.util.Map |
immutableMap(java.util.Map m)
Returns a version of the map that is not modifiable If m is null, null will be returned. |
|
static int |
indexOfMapInList(java.util.List l1,
java.util.Map h1)
Search a list for a map. |
|
static boolean |
isImmutable(java.util.Map m)
Test a map to see if it is immutable. |
|
static java.util.Enumeration |
iteratorToEnumeration(java.util.Iterator i)
A simple wrapper to convert an Iterator to an Enumeration. |
|
static
|
keysArray(java.util.Map<? extends T,?> ht)
Returns an Object array containing the Map's keys. |
|
static
|
keysList(java.util.Map<? extends T,?> ht)
Returns a List containing the Map's keys. |
|
static java.util.Map |
makeImmutable(java.util.Map aMap)
Make a map immutable at all levels. |
|
static
|
map()
Constructs an empty Map. |
|
static
|
map(int initialCapacity)
Constructs a Map capable of holding a specified number of elements. |
|
static
|
map(java.util.Map<? extends K,? extends V> source)
Creates new Map with the same contents as the given Map. |
|
static boolean |
mapEquals(java.util.Map h1,
java.util.Map h2)
Determine if the two maps are equal. |
|
static
|
merge(java.util.Map<K,C> map,
K key,
java.util.Collection<? extends V> values,
Factory<C> factory)
Merges key and the collection of values
into map , by finding the collection of
values already in map and adding values
to it. |
|
static
|
merge(java.util.Map<K,java.util.List<V>> map,
K key,
java.util.Collection<? extends V> values)
Convenience generic method that merges key and
value into the supplied map . |
|
static
|
merge(java.util.Map<K,java.util.List<V>> map,
K key,
V value)
Convenience generic method that merges key and
value into the supplied map . |
|
static
|
mergeMapIntoMap(java.util.Map<K,V> dest,
java.util.Map<K,V> source)
Merges two Maps together. |
|
static
|
mergeMapIntoMap(java.util.Map<K,V> dest,
java.util.Map<K,V> source,
boolean appendMergeListProperties)
|
|
static
|
mergeMapIntoMap(java.util.Map<K,V> dest,
ReadOnlyMap<K,V> source)
Merges ReadOnlyMap into Map. |
|
static
|
mergeMapIntoMap(java.util.Map<K,V> dest,
ReadOnlyMap<K,V> source,
boolean appendMergeListProperties)
Merges ReadOnlyMap into Map. |
|
static java.util.Map |
mergeMapIntoMapWithObjects(java.util.Map dest,
java.util.Map source)
Merges two Maps together. |
|
static java.util.Map |
mergeMapIntoMapWithObjects(java.util.Map dest,
java.util.Map source,
boolean overwriteMismatchedClasses)
|
|
static boolean |
nullOrEmptyMap(java.util.Map<?,?> map)
Determine if a Map is null or empty. |
|
static java.util.Map |
overlayMapOntoMap(java.util.Map dest,
java.util.Map source)
Overlays source onto dest . |
|
static java.util.Map |
overwriteMap(java.util.Map overriding,
java.util.Map overridden)
Overwrites the contents of a given Map with the contents of another Map. |
|
static void |
overwriteMapInPlace(java.util.Map overriding,
java.util.Map overridden)
A version of overwriteMap that sideeffects the overriden Map directly, instead of making a copy to return. |
|
static boolean |
performDeletesOnMap(java.lang.Object deletes,
java.util.Map table)
Applies a single deletion or list of deletions to a map. |
|
static int |
removeElement(java.util.Map ht,
java.lang.Object element)
Finds and removes all occurrences of element from the Map. |
|
static
|
sortedMap()
Creates an empty SortedMap |
|
static
|
sortedMap(java.util.Comparator<K> comparator)
Creates an empty SortedMap |
|
static
|
sortedMap(java.util.SortedMap<? extends K,? extends V> source)
Creates a new SortedMap with the same content as the given SortedMap |
|
static java.lang.String |
toSerializedString(java.util.Map m)
Returns a string serialization of the Hashtable using the Serializer. |
|
static java.lang.String[] |
toStringArray(java.util.Map m)
Converts a string into a string array for persistence purposes. |
|
static
|
transformValues(java.util.Map<K,X> m,
MapUtil.Transformer<X,Y> t)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Class ImmutableMapClass
Method Detail |
---|
public static <K,V> java.util.Map<K,V> map()
public static <K,V> java.util.Map<K,V> cloneMap(java.util.Map<K,V> m)
m
- the map to clone
public static <K,V> java.util.Map<K,V> map(int initialCapacity)
Map
:Map<K,V> typesafe = MapUtil.map()
Map
:Map raw = MapUtil.map()
initialCapacity
- the number of elements this Map
is capable of holding before needing to grow.
public static <K,V> java.util.Map<K,V> map(java.util.Map<? extends K,? extends V> source)
Map
:Map<K,V> typesafe = MapUtil.map()
Map
:Map raw = MapUtil.map()
source
- source Map
source
public static <K,V> java.util.concurrent.ConcurrentHashMap<K,V> concurrentMap()
ConcurrentHashMap
public static <K,V> java.util.SortedMap<K,V> sortedMap()
SortedMap
public static <K,V> java.util.SortedMap<K,V> sortedMap(java.util.Comparator<K> comparator)
comparator
- the comparator that will be used to sort this map
SortedMap
public static <K,V> java.util.SortedMap<K,V> sortedMap(java.util.SortedMap<? extends K,? extends V> source)
source
- the sorted map whose mappings are to be placed in this map
SortedMap
public static java.util.SortedMap copyAndSortMap(java.util.Map<java.lang.String,java.lang.Object> source)
source
- the map whose mappings are to be copied into a SortedMap
SortedMap
,
ListUtil
public static <T> java.util.List<T> keysList(java.util.Map<? extends T,?> ht)
ht
- the table to return keys from
public static <T> java.util.List<T> elementsList(java.util.Map<?,? extends T> ht)
ht
- the Map whose elements are to be returned in the
returned list.
public static <T> T[] keysArray(java.util.Map<? extends T,?> ht)
ht
- the table to return keys from
public static <T> T[] elementsArray(java.util.Map<?,? extends T> ht)
ht
- the table to return elements from
public static int removeElement(java.util.Map ht, java.lang.Object element)
ht
- the Map to modifyelement
- the element to search for. Map compares elements
using equals().
public static boolean allElementsAreStrings(java.util.List<?> v)
public static boolean nullOrEmptyMap(java.util.Map<?,?> map)
map
- a map object to check
public static java.util.Map convertListToMap(java.util.List keys)
keys
- a List of items to become keys in created
Map
public static <K,V> java.util.Map<K,V> mergeMapIntoMap(java.util.Map<K,V> dest, ReadOnlyMap<K,V> source)
dest
- the map into which source
is to be mergedsource
- the map to merge into dest
public static <K,V> java.util.Map<K,V> mergeMapIntoMap(java.util.Map<K,V> dest, ReadOnlyMap<K,V> source, boolean appendMergeListProperties)
dest
- the map into which source
is to be mergedsource
- the map to merge into dest
appendMergeListProperties
-
public static <K,V> java.util.Map<K,V> mergeMapIntoMap(java.util.Map<K,V> dest, java.util.Map<K,V> source)
source
and dest
are (essentially) Strings
, Lists
and
Maps
. After the merge dest
can best
be described as "a union of the entries in itself and in
source
."
That is any entries in source
but not in
dest
will be copied into dest
.
For entries that are in both source
and dest
: Strings
, source
overwrites dest
Lists
they are unioned
Maps
they are
merged
(hence this method is recursive)
source
and dest
are not
the same type, things start to get complicated and are intuitive about
half the time. For instance if dest
contains a
List
and source
a String
, the
String
in source
gets added. (However,
the opposite situation is not-at-all intuitive.)
Important note: the only map modified in this method is
dest
. No sub-maps of dest
(or indeed any
maps of source
) are modified.
source
- the map to merge into dest
dest
- the map into which source
is to be merged
public static <K,V> java.util.Map<K,V> mergeMapIntoMap(java.util.Map<K,V> dest, java.util.Map<K,V> source, boolean appendMergeListProperties)
public static java.util.Map mergeMapIntoMapWithObjects(java.util.Map dest, java.util.Map source)
source
- the map to merge into dest
dest
- the map into which source
is to be merged
public static java.util.Map mergeMapIntoMapWithObjects(java.util.Map dest, java.util.Map source, boolean overwriteMismatchedClasses)
public static java.util.Map overlayMapOntoMap(java.util.Map dest, java.util.Map source)
source
onto dest
.
This method has similar behavior to mergeMapIntoMap(java.util.Map, ariba.util.core.ReadOnlyMap)
with the
exception that no merges happen--source
is simply written
on top of dest
. That is, every entry in source
but not in dest
is copied into dest
.
For every entry that is in both source
and dest
the source
value overwrites the dest
value.
So, in essence this method is alot simpler than mergeMapIntoMap(java.util.Map, ariba.util.core.ReadOnlyMap)
.
source
- the map to merge into dest
dest
- the map into which source
is to be merged
dest
public static java.util.Map overwriteMap(java.util.Map overriding, java.util.Map overridden)
overriding
- the overriding Mapoverridden
- the Map to be overridden
public static void overwriteMapInPlace(java.util.Map overriding, java.util.Map overridden)
public static boolean performDeletesOnMap(java.lang.Object deletes, java.util.Map table)
public static java.util.Map copyMap(java.util.Map source)
source
- the source map to copy.
public static boolean mapEquals(java.util.Map h1, java.util.Map h2)
h1
- the first Maph2
- the second Map
public static <K,V> void merge(java.util.Map<K,java.util.List<V>> map, K key, V value)
key
and
value
into the supplied map
.
The semantics are, add value
to the list of
values
associated with key
in
map
.
map
- the map to merge intokey
- the keyvalue
- the valuepublic static <K,V,C extends java.util.Collection<V>> void merge(java.util.Map<K,C> map, K key, java.util.Collection<? extends V> values, Factory<C> factory)
key
and the collection of values
into map
, by finding the collection of
values already in map
and adding values
to it.
map
- the map to merge intokey
- the keyvalues
- the collection of valuesfactory
- the factory to use to create new collections if neededpublic static <K,V> void merge(java.util.Map<K,java.util.List<V>> map, K key, java.util.Collection<? extends V> values)
key
and
value
into the supplied map
.
The semantics are, add value
to the list of
values
associated with key
in
map
.
map
- the map to merge intokey
- the keyvalues
- the valuespublic static java.lang.String toSerializedString(java.util.Map m)
Serializer
public static void fromSerializedString(java.util.Map m, java.lang.String serialized)
serialized
- String containing serialized Hashtable datapublic static void deserializeFromString(java.util.Map m, java.lang.String serialized) throws java.io.IOException, DeserializationException
m
- Hashtable to populate.serialized
- String containing serialized hashtable data
java.io.IOException
DeserializationException
public static java.lang.Object getPath(java.util.Map map, java.lang.String path)
map
- The map to searchpath
- The dotted path to traverse
public static java.lang.String[] toStringArray(java.util.Map m)
public static int indexOfMapInList(java.util.List l1, java.util.Map h1)
l1
- the listh1
- the Map
public static java.util.Enumeration iteratorToEnumeration(java.util.Iterator i)
i
- the Iterator to convert to an Enumeration
public static java.util.Iterator enumerationToIterator(java.util.Enumeration e)
e
- the Enumeration to convert to an Iterator
public static boolean isImmutable(java.util.Map m)
m
- The Map to be tested
public static java.util.Map immutableMap(java.util.Map m)
public static java.util.Map makeImmutable(java.util.Map aMap)
aMap
- - the Map to be made immutable.
public static java.lang.String getStringArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static <K,V> java.util.Map<K,V> getMapArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static <K> java.util.List<K> getListArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.util.List getVectorArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.util.Map getHashtableArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static Date getDateArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static int getIntArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.lang.Integer getIntArgOrNull(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.lang.Double getDoubleArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.lang.Double getDoubleArgOrNull(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.lang.Long getLongArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.lang.Long getLongArgOrNull(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static java.math.BigDecimal getBigDecimalArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static boolean getBooleanArg(java.util.Map args, java.lang.String key)
args
- the maps to get the key fromkey
- the key of the value we're looking up
public static <K,X,Y> java.util.Map<K,Y> transformValues(java.util.Map<K,X> m, MapUtil.Transformer<X,Y> t)
public static java.util.Map diff(java.util.Map change, java.util.Map baseline)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |