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

pro.jk.ejoker.common.system.enhance.MapUtilx Maven / Gradle / Ivy

There is a newer version: 3.0.7.1
Show newest version
package pro.jk.ejoker.common.system.enhance;

import java.util.Map;

import pro.jk.ejoker.common.system.functional.IFunction;
import pro.jk.ejoker.common.system.functional.IFunction1;

public final class MapUtilx {

	/**
	 * 此方法并不负责线程安全,线程安全由具体的map实现类型负责
	 * @param 
	 * @param 
	 * @param map
	 * @param uniqueKey
	 * @param f
	 * @return
	 */
	public static  T getOrAdd(Map map, K uniqueKey, IFunction f) {
		T current, newOne = null;
		if(null == (current = map.get(uniqueKey))) {
			current = map.putIfAbsent(uniqueKey, newOne = f.trigger());
		}
		return null != current ? current : newOne;
	}

	/**
	 * 此方法并不负责线程安全,线程安全由具体的map实现类型负责
	 * @param 
	 * @param 
	 * @param map
	 * @param uniqueKey
	 * @param f
	 * @return
	 */
	public static  T getOrAdd(Map map, K uniqueKey, IFunction1 f) {
		T current, newOne = null;
		if(null == (current = map.get(uniqueKey))) {
			current = map.putIfAbsent(uniqueKey, newOne = f.trigger(uniqueKey));
		}
		return null != current ? current : newOne;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy