|
|||||||||
| 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 Class |
ImmutableMapClass
|
| Method Summary | ||
|---|---|---|
static
|
cloneMap(Map<K,V> m)
Helper method to clone a map |
|
static Map |
convertListToMap(List keys)
Create a Map of Maps from a List. |
|
static Map |
copyMap(Map source)
Copy a Map. |
|
static Map |
diff(Map change,
Map baseline)
|
|
static
|
elementsArray(Map<?,? extends T> ht)
Returns an Object array containing the Map's elements. |
|
static
|
elementsList(Map<?,? extends T> ht)
Returns a List containing the Map's elements. |
|
static Iterator |
enumerationToIterator(Enumeration e)
A simple wrapper to convert an Enumeration to an Iterator. |
|
static void |
fromSerializedString(Map m,
String serialized)
Populates the hashtable with serialized data from the string. |
|
static Object |
getPath(Map map,
String path)
Fetch the object (if any) in the designated Map, at the coordinates specified by the path, using dot notation. |
|
static Map |
immutableMap(Map m)
Returns a version of the map that is not modifiable If m is null, null will be returned. |
|
static int |
indexOfMapInList(List l1,
Map h1)
Search a list for a map. |
|
static boolean |
isImmutable(Map m)
Test a map to see if it is immutable. |
|
static Enumeration |
iteratorToEnumeration(Iterator i)
A simple wrapper to convert an Iterator to an Enumeration. |
|
static
|
keysArray(Map<? extends T,?> ht)
Returns an Object array containing the Map's keys. |
|
static
|
keysList(Map<? extends T,?> ht)
Returns a List containing the Map's keys. |
|
static Map |
makeImmutable(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(Map<? extends K,? extends V> source)
Creates new Map with the same contents as the given Map. |
|
static boolean |
mapEquals(Map h1,
Map h2)
Determine if the two maps are equal. |
|
static
|
merge(Map<K,C> map,
K key,
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(Map<K,List<V>> map,
K key,
Collection<? extends V> values)
Convenience generic method that merges key and
value into the supplied map. |
|
static
|
merge(Map<K,List<V>> map,
K key,
V value)
Convenience generic method that merges key and
value into the supplied map. |
|
static Map |
mergeMapIntoMap(Map dest,
Map source)
Merges two Maps together. |
|
static Map |
mergeMapIntoMap(Map dest,
Map source,
boolean appendMergeListProperties)
|
|
static Map |
mergeMapIntoMapWithObjects(Map dest,
Map source)
Merges two Maps together. |
|
static Map |
mergeMapIntoMapWithObjects(Map dest,
Map source,
boolean overwriteMismatchedClasses)
|
|
static boolean |
nullOrEmptyMap(Map<?,?> map)
Determine if a Map is null or empty. |
|
static Map |
overlayMapOntoMap(Map dest,
Map source)
Overlays source onto dest. |
|
static Map |
overwriteMap(Map overriding,
Map overridden)
Overwrites the contents of a given Map with the contents of another Map. |
|
static void |
overwriteMapInPlace(Map overriding,
Map overridden)
A version of overwriteMap that sideeffects the overriden Map directly, instead of making a copy to return. |
|
static boolean |
performDeletesOnMap(Object deletes,
Map table)
Applies a single deletion or list of deletions to a map. |
|
static int |
removeElement(Map ht,
Object element)
Finds and removes all occurrences of element from the Map. |
|
static
|
sortedMap()
Creates an empty SortedMap |
|
static
|
sortedMap(Comparator<K> comparator)
Creates an empty SortedMap |
|
static
|
sortedMap(SortedMap<? extends K,? extends V> source)
Creates a new SortedMap with the same content as the given SortedMap |
|
static String |
toSerializedString(Map m)
Returns a string serialization of the Hashtable using the Serializer. |
|
static String[] |
toStringArray(Map m)
Converts a string into a string array for persistence purposes. |
|
static
|
transformValues(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 Class ImmutableMapClass
| Method Detail |
|---|
public static <K,V> Map<K,V> map()
public static <K,V> Map<K,V> cloneMap(Map<K,V> m)
m - the map to clone
public static <K,V> 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> Map<K,V> map(Map<? extends K,? extends V> source)
Map:Map<K,V> typesafe = MapUtil.map()
Map:Map raw = MapUtil.map()
source - source Map
sourcepublic static <K,V> SortedMap<K,V> sortedMap()
SortedMappublic static <K,V> SortedMap<K,V> sortedMap(Comparator<K> comparator)
comparator - the comparator that will be used to sort this map
SortedMappublic static <K,V> SortedMap<K,V> sortedMap(SortedMap<? extends K,? extends V> source)
source - the sorted map whose mappings are to be placed in this map
SortedMappublic static <T> List<T> keysList(Map<? extends T,?> ht)
ht - the table to return keys from
public static <T> List<T> elementsList(Map<?,? extends T> ht)
ht - the Map whose elements are to be returned in the
returned list.
public static <T> T[] keysArray(Map<? extends T,?> ht)
ht - the table to return keys from
public static <T> T[] elementsArray(Map<?,? extends T> ht)
ht - the table to return elements from
public static int removeElement(Map ht,
Object element)
ht - the Map to modifyelement - the element to search for. Map compares elements
using equals().
public static boolean nullOrEmptyMap(Map<?,?> map)
map - a map object to check
public static Map convertListToMap(List keys)
keys - a List of items to become keys in created
Map
public static Map mergeMapIntoMap(Map dest,
Map 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 destdest - the map into which source is to be merged
public static Map mergeMapIntoMap(Map dest,
Map source,
boolean appendMergeListProperties)
public static Map mergeMapIntoMapWithObjects(Map dest,
Map source)
source - the map to merge into destdest - the map into which source is to be merged
public static Map mergeMapIntoMapWithObjects(Map dest,
Map source,
boolean overwriteMismatchedClasses)
public static Map overlayMapOntoMap(Map dest,
Map source)
source onto dest.
This method has similar behavior to mergeMapIntoMap(java.util.Map, java.util.Map) 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, java.util.Map).
source - the map to merge into destdest - the map into which source is to be merged
dest
public static Map overwriteMap(Map overriding,
Map overridden)
overriding - the overriding Mapoverridden - the Map to be overridden
public static void overwriteMapInPlace(Map overriding,
Map overridden)
public static boolean performDeletesOnMap(Object deletes,
Map table)
public static Map copyMap(Map source)
source - the source map to copy.
public static boolean mapEquals(Map h1,
Map h2)
h1 - the first Maph2 - the second Map
public static <K,V> void merge(Map<K,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 value
public static <K,V,C extends Collection<V>> void merge(Map<K,C> map,
K key,
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 needed
public static <K,V> void merge(Map<K,List<V>> map,
K key,
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 String toSerializedString(Map m)
Serializer
public static void fromSerializedString(Map m,
String serialized)
serialized - String containing serialized Hashtable data
public static Object getPath(Map map,
String path)
map - The map to searchpath - The dotted path to traverse
public static String[] toStringArray(Map m)
public static int indexOfMapInList(List l1,
Map h1)
l1 - the listh1 - the Map
public static Enumeration iteratorToEnumeration(Iterator i)
i - the Iterator to convert to an Enumeration
public static Iterator enumerationToIterator(Enumeration e)
e - the Enumeration to convert to an Iterator
public static boolean isImmutable(Map m)
m - The Map to be tested
public static Map immutableMap(Map m)
public static Map makeImmutable(Map aMap)
aMap - - the Map to be made immutable.
public static <K,X,Y> Map<K,Y> transformValues(Map<K,X> m,
MapUtil.Transformer<X,Y> t)
public static Map diff(Map change,
Map baseline)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||