Java Map Create createMap(String entries)

Here you can find the source of createMap(String entries)

Description

create Map

License

LGPL

Declaration

public static Map<String, String> createMap(String entries) 

Method Source Code

//package com.java2s;
/*****************************************************************
 OWLBeans is a toolkit to manipulate ontologies.
 Its main purpose is to extract JavaBeans from OWL documents.
 Copyright (C) 2004 University of Parma.
    /*from   ww  w.j  ava 2  s.c om*/
 GNU Lesser General Public License
    
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation,
 version 2.1 of the License.
    
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
    
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA  02111-1307, USA.
 *****************************************************************/

import java.util.*;

public class Main {
    public static Map<String, String> createMap(String entries) {
        return fillMap(new HashMap<String, String>(), entries);
    }

    public static Map fillMap(Map map, String entries) {
        if (entries == null)
            return map;
        return fillMap(map, parseKVPairs(entries));
    }

    public static Map fillMap(Map map, String[][] kv) {
        for (int i = 0; i < kv.length; i++) {
            if (kv[i].length > 1)
                map.put(kv[i][0], kv[i][1]);
        }
        return map;
    }

    public static String[][] parseKVPairs(String kv) {
        // comma-separated list of entries
        String[] list = kv.split(",");
        String[][] result = new String[list.length][];
        for (int i = 0; i < list.length; i++) {
            // each entry is a colon-separated key-val pair
            result[i] = list[i].trim().split(":");
        }
        return result;
    }
}

Related

  1. createMap(Object keys[], Object values[])
  2. createMap(Object... args)
  3. createMap(Object... objects)
  4. createMap(Object... objects)
  5. createMap(Object[] keysValues)
  6. createMap(String key, Object value)
  7. createMap(String[] list1, String[] list2)
  8. createMap(String[] mappings, String sep)
  9. createMap(T... _args)