package com.ffii.core.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * MapUtils
 *
 * @author Patrick
 */
public class MapUtils {

	/**
	 * Convert key-value pairs to HashMap
	 *
	 * @param keyValuePairs
	 *            Keys and values must be in pairs
	 *
	 * @return Map
	 */
	@SuppressWarnings("unchecked")
	public static <K, V> Map<K, V> toHashMap(Object... keyValuePairs) {
		if (keyValuePairs.length % 2 != 0)
			throw new IllegalArgumentException("Keys and values must be in pairs");

		Map<K, V> map = new HashMap<K, V>(keyValuePairs.length / 2);

		for (int i = 0; i < keyValuePairs.length; i += 2) {
			map.put((K) keyValuePairs[i], (V) keyValuePairs[i + 1]);
		}

		return map;
	}

}
