com.jchanghong.core.map.multi.SetValueMap Maven / Gradle / Ivy
The newest version!
package com.jchanghong.core.map.multi;
import com.jchanghong.core.map.MapWrapper;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
/**
* 值作为集合Set(LinkedHashSet)的Map实现,通过调用putValue可以在相同key时加入多个值,多个值用集合表示
*
* @author looly
*
* @param 键类型
* @param 值类型
* @since 4.3.3
*/
public class SetValueMap extends CollectionValueMap {
private static final long serialVersionUID = 6044017508487827899L;
// ------------------------------------------------------------------------- Constructor start
/**
* 构造
*/
public SetValueMap() {
this(MapWrapper.DEFAULT_INITIAL_CAPACITY);
}
/**
* 构造
*
* @param initialCapacity 初始大小
*/
public SetValueMap(int initialCapacity) {
this(initialCapacity, MapWrapper.DEFAULT_LOAD_FACTOR);
}
/**
* 构造
*
* @param m Map
*/
public SetValueMap(Map extends K, ? extends Collection> m) {
this(MapWrapper.DEFAULT_LOAD_FACTOR, m);
}
/**
* 构造
*
* @param loadFactor 加载因子
* @param m Map
*/
public SetValueMap(float loadFactor, Map extends K, ? extends Collection> m) {
this(m.size(), loadFactor);
this.putAll(m);
}
/**
* 构造
*
* @param initialCapacity 初始大小
* @param loadFactor 加载因子
*/
public SetValueMap(int initialCapacity, float loadFactor) {
super(new HashMap<>(initialCapacity, loadFactor));
}
// ------------------------------------------------------------------------- Constructor end
@Override
public Set get(Object key) {
return (Set) super.get(key);
}
@Override
protected Collection createCollection() {
return new LinkedHashSet<>(DEFAULT_COLLCTION_INITIAL_CAPACITY);
}
}