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

io.polaris.core.map.SetMultiMap Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.core.map;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

/**
 * @author Qt
 * @since 1.8
 */
public class SetMultiMap extends BaseMultiMap> {

	public SetMultiMap(Map> raw, Supplier> supplier) {
		super(raw, supplier);
	}

	public SetMultiMap(Map> raw) {
		super(raw, HashSet::new);
	}

	public SetMultiMap(Supplier> supplier) {
		super(new HashMap<>(), supplier);
	}

	public SetMultiMap() {
		super(new HashMap<>(), HashSet::new);
	}

	@Override
	public V getOne(Object key) {
		Set c = get(key);
		if (c == null || c.isEmpty()) {
			return null;
		}
		return c.iterator().next();
	}

	@Override
	public Set putOne(K key, V value) {
		Set c = get(key);
		if (c == null) {
			c = supplier.get();
			put(key, c);
		}
		c.add(value);
		return c;
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy