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

com.hazelcast.util.collection.InternalMultiMap Maven / Gradle / Ivy

There is a newer version: 5.4.0
Show newest version
/*
 * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
 *
 * 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 com.hazelcast.util.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Simplistic implementation of MultiMap.
 * It's not thread-safe, concurrent access has to be externally synchronized.
 *
 * It allows duplicates: The same value can be associated with the same key multiple times
 *
 * The name has a prefix Internal- to avoid confusion with {@link com.hazelcast.core.MultiMap}
 *
 * @param 
 * @param 
 */
public class InternalMultiMap {
    private final Map> backingMap;

    public InternalMultiMap() {
        this.backingMap = new HashMap>();
    }

    /**
     * Put value to a given key. It allows duplicates under the same key
     *
     * @param key
     * @param value
     */
    public void put(K key, V value) {
        List values = backingMap.get(key);
        if (values == null) {
            values = new ArrayList();
            backingMap.put(key, values);
        }
        values.add(value);
    }

    /**
     * Return collection of values associated with a given key
     *
     * @param key
     * @return
     */
    public Collection get(K key) {
        return backingMap.get(key);
    }

    public Set>> entrySet() {
        return backingMap.entrySet();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy