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

ca.odell.glazedlists.impl.adt.IdentityMultimap Maven / Gradle / Ivy

/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl.adt;

import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;

/**
 * A poor man's multimap, used only to reduce the complexity code that deals
 * with these otherwise painful structures.
 *
 * @author Jesse Wilson
 */
public class IdentityMultimap extends IdentityHashMap> {
    public void addValue(K key, V value) {
        List values = super.get(key);
        if(values == null) {
            values = new ArrayList(2);
            put(key, values);
        }
        values.add(value);
    }
    @Override
    public List get(Object key) {
        List values = super.get(key);
        return values == null ? Collections.emptyList() : values;
    }
    public int count(Object key) {
        List values = super.get(key);
        return values == null ? 0 : values.size();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy