Java Map Clone cloneMap(Map> map)

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

Description

Clone the specified map.

License

Open Source License

Parameter

Parameter Description
map an Object of Map<String, List<String>>

Return

an Object of Map<String, List<String>>

Declaration

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

Method Source Code

//package com.java2s;
/*/* w w  w.  ja  v  a  2 s .  c o m*/
    
Copyright (C) 2006-2013  Board of Regents of the University of Wisconsin System (Univ. of Wisconsin-Madison, Trace R&D Center).
    
This piece of the software package, developed by the Trace Center - University of Wisconsin is released to the public domain with only the following restrictions:
    
1) That the following acknowledgement be included in the source code and documentation for the program or package that use this code:
    
"Parts of this program were based on software developed by the Trace Center, University of Wisconsin-Madison under funding from NIDRR / US Dept of Education."
    
2) That this program not be modified unless it is plainly marked as modified from the original distributed by Trace.
    
NOTE: This license agreement does not cover third-party components bundled with this software, which have their own license agreement with them. A list of included third-party components with references to their license files is provided with this distribution. 
    
This software was developed under funding from NIDRR / US Dept of Education under grant # H133E030012.
    
THIS SOFTWARE IS EXPERIMENTAL/DEMONSTRATION IN NATURE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    
*/

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    private static Map<String, String> userProf_vs_Res;

    /**
     * Clone the specified map.
     * 
     * @param map an Object of Map&lt;String, List&lt;String&gt;&gt;
     * @return an Object of Map&lt;String, List&lt;String&gt;&gt;
     */
    public static Map<String, List<String>> cloneMap(Map<String, List<String>> map) {

        if (map == null)
            return null;

        Map<String, List<String>> cloneMap = new HashMap<String, List<String>>();

        for (Entry<String, List<String>> entry : map.entrySet()) {

            if (entry == null)
                continue;

            String key = userProf_vs_Res.get(entry.getKey());

            cloneMap.put(key == null ? entry.getKey() : key, cloneStringList(entry.getValue()));
        }

        return cloneMap;
    }

    /**
     * Clone the specified List.
     * 
     * @param list an Object of List&lt;String&gt;
     * @return an Object of List&lt;String&gt;
     */
    private static List<String> cloneStringList(List<String> list) {

        if (list == null)
            return null;

        List<String> cloneList = new ArrayList<String>();

        for (String value : list)
            cloneList.add(value);

        return cloneList;
    }
}

Related

  1. clone(Map map)
  2. cloneDefaults(Map defaults)
  3. cloneMap(final Map m)
  4. cloneMap(Map map)
  5. cloneMap(Map orig)