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

fr.vergne.collection.MultiMap Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version
package fr.vergne.collection;

import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;

/**
 * A {@link MultiMap} allows to map a key to several values. This class is
 * similar to the Apache MultiMap, but assumes that it is a proper {@link Map} between a
 * key and a set of values rather than a special {@link Map} between a
 * key and each of its single values. Thus, where the Apache one appears
 * as a common {@link Map} but with the need to make casting and other tricky
 * things to use it fully, this {@link MultiMap} implements as much as possible
 * the concept to provide a user-friendly class.
 * 
 * @author Matthieu Vergne 
 * 
 * @param 
 * @param 
 */
public interface MultiMap extends Map>,
		Iterable> {
	/**
	 * Same as {@link #populate(Object, Collection)}.
	 */
	public boolean populate(Key key, Value... values);

	/**
	 * Map a key to all the provided values. If there is already values mapped
	 * to this key, the new values are added (the old ones are kept, not
	 * replaced).
	 * 
	 * @return true if some values have been added
	 */
	public boolean populate(Key key, Collection values);

	/**
	 * Same as {@link #depopulate(Object, Collection)}.
	 */
	public boolean depopulate(Key key, Value... values);

	/**
	 * Remove some values from a key. Values which are not mapped to this key
	 * does not generate any exception.
	 * 
	 * @param key
	 *            the key to remove values from
	 * @param values
	 *            the values to remove
	 * @return true if some values have been removed
	 */
	public boolean depopulate(Key key, Collection values);

	/**
	 * 
	 * @param key
	 *            the key to check
	 * @param value
	 *            the value to check
	 * @return true if the key is known and the value is actually
	 *         mapped to it
	 */
	public boolean containsCouple(Key key, Value value);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy