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

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

There is a newer version: 9.2.0.M1
Show newest version
/*
 * Copyright (c) 2016 Shotaro Sano.
 * 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.Serializable;

import org.eclipse.collections.api.bag.MutableBag;
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.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.multimap.AbstractSynchronizedMultimap;

public class SynchronizedBagMultimap
        extends AbstractSynchronizedMultimap
        implements MutableBagMultimap, Serializable
{
    private static final long serialVersionUID = 1L;

    public SynchronizedBagMultimap(MutableBagMultimap multimap)
    {
        super(multimap);
    }

    public SynchronizedBagMultimap(MutableBagMultimap multimap, Object newLock)
    {
        super(multimap, newLock);
    }

    /**
     * This method will take a Multimap and wrap it directly in a SynchronizedBagMultimap.
     */
    public static  SynchronizedBagMultimap of(MutableBagMultimap multimap)
    {
        if (multimap == null)
        {
            throw new IllegalArgumentException("cannot create a SynchronizedBagMultimap for null");
        }

        return new SynchronizedBagMultimap<>(multimap);
    }

    /**
     * This method will take a Multimap and wrap it directly in a SynchronizedBagMultimap.
     * Additionally, a developer specifies which lock to use with the collection.
     */
    public static  SynchronizedBagMultimap of(MutableBagMultimap multimap, Object lock)
    {
        if (multimap == null)
        {
            throw new IllegalArgumentException("cannot create a SynchronizedBagMultimap for null");
        }

        return new SynchronizedBagMultimap<>(multimap, lock);
    }

    @Override
    public MutableBag replaceValues(K key, Iterable values)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().replaceValues(key, values);
        }
    }

    @Override
    public MutableBag removeAll(Object key)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().removeAll(key);
        }
    }

    @Override
    public MutableBagMultimap newEmpty()
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().newEmpty().asSynchronized();
        }
    }

    @Override
    public MutableBag get(K key)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().get(key);
        }
    }

    @Override
    public MutableBagMultimap toMutable()
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().toMutable();
        }
    }

    @Override
    public ImmutableBagMultimap toImmutable()
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().toImmutable();
        }
    }

    @Override
    public void putOccurrences(K key, V value, int occurrences)
    {
        synchronized (this.getLock())
        {
            this.getDelegate().putOccurrences(key, value, occurrences);
        }
    }

    @Override
    public MutableBagMultimap flip()
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().flip();
        }
    }

    @Override
    public MutableBagMultimap selectKeysValues(Predicate2 predicate)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().selectKeysValues(predicate);
        }
    }

    @Override
    public MutableBagMultimap rejectKeysValues(Predicate2 predicate)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().rejectKeysValues(predicate);
        }
    }

    @Override
    public MutableBagMultimap selectKeysMultiValues(Predicate2> predicate)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().selectKeysMultiValues(predicate);
        }
    }

    @Override
    public MutableBagMultimap rejectKeysMultiValues(Predicate2> predicate)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().rejectKeysMultiValues(predicate);
        }
    }

    @Override
    public  MutableBagMultimap collectKeysValues(Function2> function)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().collectKeysValues(function);
        }
    }

    @Override
    public  MutableBagMultimap collectValues(Function function)
    {
        synchronized (this.getLock())
        {
            return this.getDelegate().collectValues(function);
        }
    }

    @Override
    public MutableBagMultimap asSynchronized()
    {
        return this;
    }

    @Override
    protected MutableBagMultimap getDelegate()
    {
        return (MutableBagMultimap) super.getDelegate();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy