com.google.api.ads.common.lib.utils
Class Maps

java.lang.Object
  extended by com.google.api.ads.common.lib.utils.Maps

public final class Maps
extends Object

A utility class for managing maps as represented in the API.

Author:
Adam Rogal

Method Summary
static
<K,V,T> T[]
toArray(Map<K,V> map, T[] entryArray)
          Generates an array of entries from a map.
static
<K,V,T> List<T>
toList(Map<K,V> map, Class<T> entryClass)
          Generates a list of entries from a map.
static
<K,V,T> Map<K,V>
toMap(List<T> entryList)
          Generates a map from a list of entries.
static
<K,V,T> Map<K,V>
toMap(T[] entryArray)
          Generates a map from an array an entries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toMap

public static <K,V,T> Map<K,V> toMap(List<T> entryList)
                      throws IllegalArgumentException
Generates a map from a list of entries. Entries are defined in the API as a class which consists of a key and value with a name typically in the form of Key_ValueMapEntry, represented here as T. The generated map must have same type K as the key within Key_ValueMapEntry. The same applies for V and value within Key_ValueMapEntry.

Type Parameters:
K - the type of the entry key
V - the type of the entry value
T - the map entry type
Parameters:
entryList - the list of entries constituting a map as represented in the API
Returns:
a map of type K and V representing the entry array
Throws:
IllegalArgumentException - if entryArray is not compatible with Map<K, V> or if entryArray == null

toMap

public static <K,V,T> Map<K,V> toMap(T[] entryArray)
                      throws IllegalArgumentException
Generates a map from an array an entries. Entries are defined in the API as a class which consists of a key and value with a name typically in the form of Key_ValueMapEntry, represented here as T. The generated map must have same type K as the key within Key_ValueMapEntry. The same applies for V and value within Key_ValueMapEntry. If entryArray == null, an emtpy map is returned.

Type Parameters:
K - the type of the entry key
V - the type of the entry value
T - the map entry type
Parameters:
entryArray - the array of entries constituting a map as represented in the API
Returns:
a map of type K and V representing the entry array
Throws:
IllegalArgumentException - if entryArray is not compatible with Map<K, V>.

toArray

public static <K,V,T> T[] toArray(Map<K,V> map,
                                  T[] entryArray)
Generates an array of entries from a map. Entries are defined in the API as a class which consists of a key and value with a name typically in the form of Key_ValueMapEntry, represented here as T. The generated array can be used in objects where List<Key_ValueMapEntry> is taken as a value. The input map must have same type K as the key within Key_ValueMapEntry. The same applies for V and value within Key_ValueMapEntry.

Type Parameters:
K - the type of the entry key
V - the type of the entry value
T - the map entry type
Parameters:
map - a map of type K and V representing the entry array
entryArray - the entry array that entries will be added into
Returns:
an array all map entries contained within the map parameter into the provided array or a new array if there was not enough room

toList

public static <K,V,T> List<T> toList(Map<K,V> map,
                                     Class<T> entryClass)
Generates a list of entries from a map. Entries are defined in the API as a class which consists of a key and value with a name typically in the form of Key_ValueMapEntry, represented here as T. The generated array can be used in objects where List<Key_ValueMapEntry> is taken as a value. The input map must have same type K as the key within Key_ValueMapEntry. The same applies for V and value within Key_ValueMapEntry.

Type Parameters:
K - the type of the entry key
V - the type of the entry value
T - the map entry type
Parameters:
map - a map of type K and V representing the entry array
entryClass - the entry class of type
Returns:
a list of all map entries contained within the map parameter


Copyright © 2012. All Rights Reserved.