Java ConcurrentHashMap ParseKeyValString(String keyValString, ConcurrentHashMap map)

Here you can find the source of ParseKeyValString(String keyValString, ConcurrentHashMap map)

Description

Parse Key Val String

License

Apache License

Declaration

public static void ParseKeyValString(String keyValString, ConcurrentHashMap<String, String> map) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * StringUtils.java//from   w w w.ja  v a  2s.co  m
 * 
 * Copyright 2010-2013 Andrew Marder
 * heelcurve5@gmail.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

import java.util.concurrent.ConcurrentHashMap;

public class Main {
    public static void ParseKeyValString(String keyValString, ConcurrentHashMap<String, String> map) {
        // If i's not a comment
        if (!keyValString.startsWith("#") && !keyValString.startsWith("//") && !keyValString.startsWith("/*")) {
            StringBuffer sb = new StringBuffer();
            int i;
            String key = "";
            String val = "";
            /* read the key until a separator character is encountered */
            for (i = 0; i < keyValString.length(); ++i) {
                char cur = keyValString.charAt(i);
                if (cur == ' ' || cur == '\t' || cur == '=') {
                    i++;
                    break;
                }
                sb.append(cur);
            }
            /* Do we have a key? */
            if (sb.length() > 0 && i != 0 && i < keyValString.length()) {
                /*parse the value*/
                val = keyValString.substring(i).trim();
                key = sb.toString();
                if (!val.isEmpty() & !key.isEmpty()) {
                    map.put(key, val);
                }

            }
        }

    }
}

Related

  1. createConcurrentHashMap()
  2. getConcurrentHashMap()
  3. getDoubleSafe(ConcurrentHashMap map, String key)
  4. getMapSafe( ConcurrentHashMap> map, String key)
  5. max(ConcurrentHashMap map)
  6. parseMap(String config, ConcurrentHashMap map)
  7. putIfAbsent(ConcurrentHashMap col, K key, V val)
  8. setFieldValue(Object value, ConcurrentHashMap fieldHolder, String name, String desc)