Java Map Create map(Map map)

Here you can find the source of map(Map map)

Description

map

License

Apache License

Declaration

public static Map<String, String> map(Map map) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;
import java.util.Iterator;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class Main {

    public static Map<String, String> map(Map map) {
        if (map == null) {
            return null;
        }/*from  w w  w .  j  a  va2 s. c  o m*/
        Map<String, String> result = new HashMap<String, String>();
        if (map.isEmpty()) {
            return result;
        }
        Set<Entry<String, Object>> entrySet = map.entrySet();
        Iterator<Entry<String, Object>> iterator = entrySet.iterator();
        while (iterator.hasNext()) {
            Entry<String, Object> next = iterator.next();
            String key = next.getKey();
            Object value = next.getValue();
            if (value == null) {
                result.put(key, null);
            } else {
                result.put(key, value + "");
            }
        }
        return result;
    }

    public static boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        }
        if ("".equals(obj)) {
            return true;
        }
        return false;
    }

    public static <K, V> Map<K, V> put(Map<K, V> map, K key, V value) {
        V valueOld = map.get(key);
        if (valueOld == null) {
            map.put(key, value);
        }
        return map;
    }
}

Related

  1. map(K key, V value, Object... moreKeysAndValues)
  2. map(K key0, V value0)
  3. map(K key1, V value1, Object... objects)
  4. map(K[] keys, V[] values)
  5. map(M map, K key, V value)
  6. map(Map map, Object key)
  7. map(Map.Entry... entries)
  8. map(Map.Entry... entries)
  9. map(Map accumulator, Key key, Value value)