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

cool.linco.common.convert.MemoryDictContainer Maven / Gradle / Ivy

The newest version!
package cool.linco.common.convert;


import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

public class MemoryDictContainer extends AbstractDictContainer {

	private Map> dictHolder = new HashMap<>();

	MemoryDictContainer() {
	}

	@Override
	protected void addDict(String key, Map values) {
		dictHolder.put(key, values);
	}

	@Override
	protected Object getValueCache(String dict, String key) {
		return Optional.ofNullable(dictHolder.get(dict)).map(item -> item.get(key)).orElse(null);
	}

	@Override
	protected boolean contains(String dict) {
		return dictHolder.containsKey(dict);
	}

	@Override
	protected void saveDictValue(String dict, String key, Object value) {
		if (value == null) {
			dictHolder.get(dict).remove(key);
		} else {
			dictHolder.get(dict).put(key, value);
		}
	}
}


/* Object转成Map
   从Object读取属性, 将dict中有的列按字典转换为值, 无法转换或不在字典的属性维持
   可选传入Map, 定义需要转换的属性, 转换dict的key和转换后的id
* */




© 2015 - 2025 Weber Informatics LLC | Privacy Policy