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

org.eclipse.collections.impl.multimap.set.ImmutableSetMultimapImpl Maven / Gradle / Ivy

There is a newer version: 11.1.0-r13
Show newest version
/*
 * Copyright (c) 2022 Goldman Sachs and others.
 * 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.set;

import java.io.Externalizable;
import java.io.Serializable;

import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.multimap.set.ImmutableSetMultimap;
import org.eclipse.collections.api.multimap.set.MutableSetMultimap;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.multimap.AbstractImmutableMultimap;
import org.eclipse.collections.impl.multimap.AbstractMutableMultimap;
import org.eclipse.collections.impl.multimap.ImmutableMultimapSerializationProxy;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.utility.Iterate;

/**
 * The default ImmutableBagMultimap implementation.
 *
 * @since 1.0
 */
public final class ImmutableSetMultimapImpl
        extends AbstractImmutableMultimap>
        implements ImmutableSetMultimap, Serializable
{
    private static final long serialVersionUID = 1L;

    public ImmutableSetMultimapImpl(MutableMap> map)
    {
        super(map);
    }

    public ImmutableSetMultimapImpl(ImmutableMap> map)
    {
        super(map);
    }

    @Override
    protected ImmutableSet createCollection()
    {
        return Sets.immutable.empty();
    }

    @Override
    public void forEachKeyImmutableSet(Procedure2> procedure)
    {
        this.getMap().forEachKeyValue(procedure);
    }

    @Override
    public ImmutableSetMultimap newEmpty()
    {
        return new ImmutableSetMultimapImpl<>(Maps.immutable.with());
    }

    @Override
    public MutableSetMultimap toMutable()
    {
        return new UnifiedSetMultimap<>(this);
    }

    @Override
    public ImmutableSetMultimap toImmutable()
    {
        return this;
    }

    private Object writeReplace()
    {
        return new ImmutableSetMultimapSerializationProxy<>(this.map);
    }

    private static final class ImmutableSetMultimapSerializationProxy
            extends ImmutableMultimapSerializationProxy> implements Externalizable
    {
        private static final long serialVersionUID = 1L;

        public ImmutableSetMultimapSerializationProxy()
        {
            // For Externalizable use only
        }

        private ImmutableSetMultimapSerializationProxy(ImmutableMap> map)
        {
            super(map);
        }

        @Override
        protected AbstractMutableMultimap> createEmptyMutableMultimap()
        {
            return new UnifiedSetMultimap<>();
        }
    }

    @Override
    public ImmutableSetMultimap newWith(K key, V value)
    {
        return (ImmutableSetMultimap) super.newWith(key, value);
    }

    @Override
    public ImmutableSetMultimap newWithout(Object key, Object value)
    {
        return (ImmutableSetMultimap) super.newWithout(key, value);
    }

    @Override
    public ImmutableSetMultimap newWithAll(K key, Iterable values)
    {
        return (ImmutableSetMultimap) super.newWithAll(key, values);
    }

    @Override
    public ImmutableSetMultimap newWithoutAll(Object key)
    {
        return (ImmutableSetMultimap) super.newWithoutAll(key);
    }

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

    @Override
    public ImmutableSetMultimap selectKeysValues(Predicate2 predicate)
    {
        return this.selectKeysValues(predicate, UnifiedSetMultimap.newMultimap()).toImmutable();
    }

    @Override
    public ImmutableSetMultimap rejectKeysValues(Predicate2 predicate)
    {
        return this.rejectKeysValues(predicate, UnifiedSetMultimap.newMultimap()).toImmutable();
    }

    @Override
    public ImmutableSetMultimap selectKeysMultiValues(Predicate2> predicate)
    {
        return this.selectKeysMultiValues(predicate, UnifiedSetMultimap.newMultimap()).toImmutable();
    }

    @Override
    public ImmutableSetMultimap rejectKeysMultiValues(Predicate2> predicate)
    {
        return this.rejectKeysMultiValues(predicate, UnifiedSetMultimap.newMultimap()).toImmutable();
    }

    @Override
    public  ImmutableBagMultimap collectKeysValues(Function2> function)
    {
        return this.collectKeysValues(function, HashBagMultimap.newMultimap()).toImmutable();
    }

    @Override
    public  ImmutableBagMultimap collectKeyMultiValues(Function keyFunction, Function valueFunction)
    {
        MutableBagMultimap mutableMultimap = this.collectKeyMultiValues(keyFunction, valueFunction, HashBagMultimap.newMultimap());
        return mutableMultimap.toImmutable();
    }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy