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

uk.co.codera.lang.collection.MultiMap Maven / Gradle / Ivy

There is a newer version: 0.0.13
Show newest version
package uk.co.codera.lang.collection;

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

public class MultiMap {

    private final Map> values;

    public MultiMap() {
        this.values = new HashMap<>();
    }

    public void put(K key, V value) {
        if (!this.values.containsKey(key)) {
            this.values.put(key, new ArrayList());
        }
        this.values.get(key).add(value);
    }

    public boolean remove(K key, V value) {
        return get(key).remove(value);
    }

    public Collection get(K key) {
        if (this.values.containsKey(key)) {
            return this.values.get(key);
        }
        return Collections.emptyList();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy