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

org.eclipse.collections.impl.multimap.bag.HashBagMultimap Maven / Gradle / Ivy

There is a newer version: 12.0.0.M3
Show newest version
/*
 * Copyright (c) 2016 Goldman Sachs.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

package org.eclipse.collections.impl.multimap.bag;

import java.io.Externalizable;

import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.Multimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.eclipse.collections.impl.utility.Iterate;

public final class HashBagMultimap
        extends AbstractMutableBagMultimap implements Externalizable
{
    private static final long serialVersionUID = 1L;

    public HashBagMultimap()
    {
    }

    public HashBagMultimap(Multimap multimap)
    {
        super(Math.max(multimap.keysView().size() * 2, 16));
        this.putAll(multimap);
    }

    public HashBagMultimap(Pair... pairs)
    {
        super(pairs);
    }

    public HashBagMultimap(Iterable> inputIterable)
    {
        super(inputIterable);
    }

    public static  HashBagMultimap newMultimap(Multimap multimap)
    {
        return new HashBagMultimap<>(multimap);
    }

    public static  HashBagMultimap newMultimap()
    {
        return new HashBagMultimap<>();
    }

    public static  HashBagMultimap newMultimap(Pair... pairs)
    {
        return new HashBagMultimap<>(pairs);
    }

    public static  HashBagMultimap newMultimap(Iterable> inputIterable)
    {
        return new HashBagMultimap<>(inputIterable);
    }

    @Override
    protected MutableMap> createMap()
    {
        return UnifiedMap.newMap();
    }

    @Override
    protected MutableMap> createMapWithKeyCount(int keyCount)
    {
        return UnifiedMap.newMap(keyCount);
    }

    @Override
    protected MutableBag createCollection()
    {
        return HashBag.newBag();
    }

    @Override
    public HashBagMultimap newEmpty()
    {
        return new HashBagMultimap<>();
    }

    @Override
    public MutableBagMultimap flip()
    {
        return Iterate.flip(this);
    }

    @Override
    public  HashBagMultimap collectValues(Function function)
    {
        return this.collectValues(function, HashBagMultimap.newMultimap());
    }

    @Override
    public HashBagMultimap selectKeysValues(Predicate2 predicate)
    {
        return this.selectKeysValues(predicate, this.newEmpty());
    }

    @Override
    public HashBagMultimap rejectKeysValues(Predicate2 predicate)
    {
        return this.rejectKeysValues(predicate, this.newEmpty());
    }

    @Override
    public HashBagMultimap selectKeysMultiValues(Predicate2> predicate)
    {
        return this.selectKeysMultiValues(predicate, this.newEmpty());
    }

    @Override
    public HashBagMultimap rejectKeysMultiValues(Predicate2> predicate)
    {
        return this.rejectKeysMultiValues(predicate, this.newEmpty());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy