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

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

public final class MapUtils
extends Object

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

Author:
Adam Rogal

Constructor Summary
MapUtils()
          Default constructor.
 
Method Summary
<K,V,T> T[]
toArray(Map<K,V> map, T[] a)
          Generates an array of entries from a map.
<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
 

Constructor Detail

MapUtils

public MapUtils()
Default constructor.

Method Detail

toMap

public <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, represnted 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:
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> or if entryArray == null

toArray

public <K,V,T> T[] toArray(Map<K,V> map,
                           T[] a)
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 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
a - the array into which the entries of this map are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
Returns:
an array of all map entries contained within the map parameter


Copyright © 2012. All Rights Reserved.