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

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

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

import java.util.*;
import java.util.function.Supplier;

/**
 * @author Qt
 * @since 1.8
 */
public abstract class BaseMultiMap> implements MultiMap {
	protected final Map raw;
	protected final Supplier supplier;

	public BaseMultiMap(Map raw, Supplier supplier) {
		this.raw = raw;
		this.supplier = supplier;
	}

	@Override
	public String toString() {
		return raw.toString();
	}

	@Override
	public E putAll(K key, V[] values) {
		return putAll(key, Arrays.asList(values));
	}

	@Override
	public E putAll(K key, Iterable values) {
		E vs = null;
		for (V value : values) {
			vs = putOne(key, value);
		}
		return vs;
	}

	@Override
	public boolean removeOne(K key, V value) {
		E vs = get(key);
		if (vs != null) {
			return vs.remove(value);
		}
		return false;
	}

	@Override
	public boolean containsOneValue(Object value) {
		Iterator> i = entrySet().iterator();
		if (value == null) {
			while (i.hasNext()) {
				Entry e = i.next();
				if (e.getValue() == null) {
					return true;
				}
			}
		} else {
			while (i.hasNext()) {
				Entry e = i.next();
				if (e.getValue().contains(value)) {
					return true;
				}
			}
		}
		return false;
	}

	@Override
	public int size() {
		return raw.size();
	}

	@Override
	public boolean isEmpty() {
		return raw.isEmpty();
	}

	@Override
	public boolean containsKey(Object key) {
		return raw.containsKey(key);
	}

	@Override
	public boolean containsValue(Object value) {
		return raw.containsValue(value);
	}

	@Override
	public E get(Object key) {
		return raw.get(key);
	}

	@Override
	public E put(K key, E value) {
		return raw.put(key, value);
	}

	@Override
	public E remove(Object key) {
		return raw.remove(key);
	}

	@Override
	public void putAll(Map m) {
		raw.putAll(m);
	}

	@Override
	public void clear() {
		raw.clear();
	}

	@Override
	public Set keySet() {
		return raw.keySet();
	}

	@Override
	public Collection values() {
		return raw.values();
	}

	@Override
	public Set> entrySet() {
		return raw.entrySet();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy