List of utility methods to do Map from Array
Map | toMap(Object... args) to Map if (args.length % 2 == 1) throw new RuntimeException("toMap must be called with an even number of parameters"); HashMap<String, Object> map = new HashMap<String, Object>(); for (int i = 0; i < args.length; i += 2) { String key = "" + args[i]; Object value = args[i + 1]; map.put(key, value); return map; |
Map | toMap(Object... data) to Map if (data.length % 2 != 0) { throw new IllegalArgumentException("data length: " + data.length); Map map = new HashMap(); for (int i = 0; i < data.length; i += 2) { map.put(data[i], data[i + 1]); return map; ... |
Map | toMap(Object... objects) to Map if (objects == null || objects.length % 2 != 0) throw new IllegalArgumentException("Illegal arguments provided to construct a map"); Map<K, V> ret = new HashMap<K, V>(); for (int i = 0; i < objects.length; i += 2) { ret.put((K) objects[i], (V) objects[i + 1]); return ret; |
Map | toMap(Object... objects) to Map Map map = new HashMap(); for (int i = 0; i < objects.length; i += 2) { map.put(objects[i], objects[i + 1]); return map; |
Map | toMap(Object... pairs) to Map Map<K, V> ret = new java.util.HashMap<K, V>(); if (pairs == null || pairs.length == 0) return ret; if (pairs.length % 2 != 0) { throw new IllegalArgumentException("Map pairs can not be odd number."); int len = pairs.length / 2; for (int i = 0; i < len; i++) { ... |
Map | toMap(Object... pairs) to Map Map<K, V> ret = new HashMap<K, V>(); if (pairs == null || pairs.length == 0) return ret; if (pairs.length % 2 != 0) { throw new IllegalArgumentException("Map pairs can not be odd number."); int len = pairs.length / 2; for (int i = 0; i < len; i++) { ... |
Map | toMap(Object[] array) to Map return toMap(array, null);
|
Map | toMap(Object[] array) Converts the given array into a java.util.Map . if (array == null) { return null; final Map<Object, Object> map = new HashMap<Object, Object>((int) (array.length * 1.5)); for (int i = 0; i < array.length; i++) { Object object = array[i]; if (object instanceof Map.Entry<?, ?>) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) object; ... |
Map | toMap(Object[] array, Map map) to Map if (array == null) { return (Map) map; } else { if (map == null) { map = new HashMap((int) ((double) array.length * 1.5D)); for (int i = 0; i < array.length; ++i) { Object object = array[i]; ... |
Map | toMap(Object[] keys, Object[] values) to Map if (keys == null || values == null) { return EMPTY_MAP; return toMap(new HashMap(keys.length), keys, values); |