All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xin.xihc.jba.sql.KV Maven / Gradle / Ivy

package xin.xihc.jba.sql;

import xin.xihc.utils.common.CommonUtil;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * KV键值对MAP
 *
 * @author Leo.Xi
 * @date 2020/3/5
 * @since 1.0
 **/
public class KV extends LinkedHashMap {

    private int index = 0;
    private String prefix = "w_kv_";

    public KV() {
    }

    public KV(String name) {
        if (CommonUtil.isNotNullEmpty(name)) {
            this.prefix = name + "_kv_";
        }
    }

    @Override
    @Deprecated
    public Object put(String key, Object value) {
        throw new RuntimeException("please use add() method.");
    }

    public String add(Object value) {
        String key = this.prefix + index++;
        super.put(key, value);
        return key;
    }

    public void merge(KV kv) {
        for (Map.Entry next : kv.entrySet()) {
            super.put(next.getKey(), next.getValue());
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy