Java Map Put putNotDup(Map tbl, String key, String value)

Here you can find the source of putNotDup(Map tbl, String key, String value)

Description

put Not Dup

License

Open Source License

Declaration

private static void putNotDup(Map<String, String> tbl, String key, String value) 

Method Source Code

//package com.java2s;
/*//from w w w.ja v  a  2s  . com
 * Copyright 2011-2016 ZXC.com All right reserved. This software is the confidential and proprietary information of
 * ZXC.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with ZXC.com.
 */

import java.util.Map;

public class Main {
    private static void putNotDup(Map<String, String> tbl, String key, String value) {
        if (tbl.containsKey(key)) {
            String v = tbl.get(key);
            if (!contains(v, value)) {
                tbl.put(key, v + "," + value);
            }
        } else {
            tbl.put(key, value);
        }
    }

    private static boolean contains(String py, String unit) {
        if (!py.contains(unit)) {
            return false;
        }
        String[] splits = py.split(",");
        for (String s : splits) {
            if (s.equals(unit)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. putMapNotNullKey(Map map, K key, V value)
  2. putMapValue(String path, Object value, Map map)
  3. putModifiedAttribute(Map aMap, String name, Object value)
  4. putMultiEntry(Map map, Iterable keys, V value)
  5. putMultiple(Map map, Object key, Object value)
  6. putObject(Map map, V key, W value)
  7. putObjectsInMultiMap(Map>> multiMap, Integer key, List stringPair)
  8. putOrCreateList(Map> map, K key, V value)
  9. putOrRemove(Map map, String key, Object obj)