Java String Split splitIdKeyConfig(String config)

Here you can find the source of splitIdKeyConfig(String config)

Description

split a keyid string into a map

License

Open Source License

Parameter

Parameter Description
config a parameter

Declaration

public static Map<String, String> splitIdKeyConfig(String config) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.util.*;

public class Main {
    /**//w w  w  .  jav  a  2s. c o  m
     * split a keyid string into a map
     *
     * @param config
     * @return
     */
    public static Map<String, String> splitIdKeyConfig(String config) {
        //example confing: mp@rec-mp,blub,test-rec@test-rec-key

        //key , id pair
        HashMap<String, String> result = new HashMap<>();
        String[] split = config.split(",");

        for (String s : split) {
            //id should be something like mp@mp-test -> id@display-name
            if (s != null && !s.isEmpty()) {
                if (s.contains("@")) {
                    String[] idSplit = s.split("@");
                    if (idSplit.length > 1) {
                        result.put(idSplit[1], idSplit[0]);
                    }
                } else {
                    //if no @ is available the key equals the id
                    result.put(s, s);
                }
            }
        }

        return result;
    }
}

Related

  1. splitForIndexMatching(String string)
  2. splitGenericIfNeeded(String name)
  3. splitHelperName(String name)
  4. splitHistory(String history)
  5. splitHTMLTags(final String string)
  6. splitInitialItems(final String text)
  7. splitInput(String cliInput)
  8. splitIntArray(final String iInput)
  9. splitIntegerFromString(String str)