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

org.jboss.weld.util.collections.Multimap Maven / Gradle / Ivy

There is a newer version: 3.0.0.Alpha1
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2014, Red Hat, Inc., and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.weld.util.collections;

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

/**
 * A collection-like structure that maps keys to collections of values.
 *
 * @author Martin Kouba
 * @param  The key
 * @param  The value
 */
public interface Multimap {

    /**
     * Unlike com.google.common.collect.Multimap#size() this method returns the number of key-value mappings.
     *
     * @return the number of key-value mappings
     */
    int size();

    /**
     *
     * @return true if there are no key-value mappings
     */
    boolean isEmpty();

    /**
     * This method never returns null. If no collection of values for a given key exists a new value collection is initialized.
     *
     * @param key
     * @return the collection of values for the given key
     */
    Collection get(K key);

    /**
     *
     * @param key
     * @param value
     * @return true if the the size of the collection associated with the given key increased, false otherwise (e.g. if the collection
     *         of values doesn't allow duplicates)
     */
    boolean put(K key, V value);

    /**
     *
     * @param key
     * @param values
     * @return true if the the size of the collection associated with the given key increased, false otherwise (e.g. if the collection
     *         of values doesn't allow duplicates)
     */
    boolean putAll(K key, Collection values);

    /**
     * Note that the original collection of values is completely replaced by a new collection which contains all elements from the given iterable. If the
     * collection of values doesn't allow duplicates, these elements are removed.
     *
     * @param key
     * @param values
     * @return the collection of replaced values
     */
    Collection replaceValues(K key, Iterable values);

    /**
     *
     * @param key
     * @return true if the multimap contains a mapping for the given key
     */
    boolean containsKey(Object key);

    /**
     *
     * @return an immutable set of keys
     */
    Set keySet();

    /**
     * The list may include the same value multiple times if it occurs in multiple mappings or if the collection of values for the mapping allows duplicate
     * elements.
     *
     * @return an immutable list of all the values in the multimap
     */
    List values();

    /**
     *
     * @return an immutable set of all the values in the multimap
     */
    Set uniqueValues();

    /**
     * {@link Entry#getValue()} always returns an unmodifiable collection. {@link Entry#setValue(Object)} operation is not supported.
     *
     * @return an immutable set of all key-value pairs
     */
    Set>> entrySet();

    /**
     * Removes all of the mappings.
     */
    void clear();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy