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

org.eclipse.collections.impl.map.AbstractSynchronizedMapIterable Maven / Gradle / Ivy

/*
 * Copyright (c) 2019 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.map;

import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.collection.MutableCollection;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.MutableMapIterable;
import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.multimap.MutableMultimap;
import org.eclipse.collections.api.partition.PartitionMutableCollection;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.collection.AbstractSynchronizedRichIterable;
import org.eclipse.collections.impl.tuple.AbstractImmutableEntry;
import org.eclipse.collections.impl.utility.Iterate;
import org.eclipse.collections.impl.utility.LazyIterate;

/**
 * A synchronized view of a map.
 */
public abstract class AbstractSynchronizedMapIterable
        extends AbstractSynchronizedRichIterable
        implements MutableMapIterable
{
    protected AbstractSynchronizedMapIterable(MutableMapIterable delegate)
    {
        super(delegate, null);
    }

    protected AbstractSynchronizedMapIterable(MutableMapIterable delegate, Object lock)
    {
        super(delegate, lock);
    }

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

    @Override
    public V get(Object key)
    {
        synchronized (this.lock)
        {
            return this.getDelegate().get(key);
        }
    }

    @Override
    public V getIfAbsent(K key, Function0 function)
    {
        synchronized (this.lock)
        {
            return this.getDelegate().getIfAbsent(key, function);
        }
    }

    @Override
    public V getIfAbsentValue(K key, V value)
    {
        synchronized (this.lock)
        {
            return this.getDelegate().getIfAbsentValue(key, value);
        }
    }

    @Override
    public 

V getIfAbsentWith(K key, Function function, P parameter) { synchronized (this.lock) { return this.getDelegate().getIfAbsentWith(key, function, parameter); } } @Override public A ifPresentApply(K key, Function function) { synchronized (this.lock) { return this.getDelegate().ifPresentApply(key, function); } } @Override public boolean containsKey(Object key) { synchronized (this.lock) { return this.getDelegate().containsKey(key); } } @Override public boolean containsValue(Object value) { synchronized (this.lock) { return this.getDelegate().containsValue(value); } } @Override public void forEachValue(Procedure procedure) { synchronized (this.lock) { this.getDelegate().forEachValue(procedure); } } @Override public void forEachKey(Procedure procedure) { synchronized (this.lock) { this.getDelegate().forEachKey(procedure); } } @Override public void forEachKeyValue(Procedure2 procedure2) { synchronized (this.lock) { this.getDelegate().forEachKeyValue(procedure2); } } @Override public Pair detect(Predicate2 predicate) { synchronized (this.lock) { return this.getDelegate().detect(predicate); } } @Override public Optional> detectOptional(Predicate2 predicate) { synchronized (this.lock) { return this.getDelegate().detectOptional(predicate); } } @Override public V getIfAbsentPut(K key, Function0 function) { synchronized (this.lock) { return this.getDelegate().getIfAbsentPut(key, function); } } @Override public V getIfAbsentPut(K key, V value) { synchronized (this.lock) { return this.getDelegate().getIfAbsentPut(key, value); } } @Override public V getIfAbsentPutWithKey(K key, Function function) { synchronized (this.lock) { return this.getDelegate().getIfAbsentPutWithKey(key, function); } } @Override public

V getIfAbsentPutWith(K key, Function function, P parameter) { synchronized (this.lock) { return this.getDelegate().getIfAbsentPutWith(key, function, parameter); } } @Override public V put(K key, V value) { synchronized (this.lock) { return this.getDelegate().put(key, value); } } @Override public V remove(Object key) { synchronized (this.lock) { return this.getDelegate().remove(key); } } @Override public V removeKey(K key) { synchronized (this.lock) { return this.getDelegate().removeKey(key); } } @Override public boolean removeAllKeys(Set keys) { synchronized (this.lock) { return this.getDelegate().removeAllKeys(keys); } } @Override public boolean removeIf(Predicate2 predicate) { synchronized (this.lock) { return this.getDelegate().removeIf(predicate); } } @Override public void putAll(Map map) { synchronized (this.lock) { this.getDelegate().putAll(map); } } @Override public void clear() { synchronized (this.lock) { this.getDelegate().clear(); } } @Override public V putPair(Pair keyValuePair) { synchronized (this.lock) { return this.put(keyValuePair.getOne(), keyValuePair.getTwo()); } } @Override public V add(Pair keyValuePair) { synchronized (this.lock) { return this.putPair(keyValuePair); } } @Override public V updateValue(K key, Function0 factory, Function function) { synchronized (this.lock) { return this.getDelegate().updateValue(key, factory, function); } } @Override public

V updateValueWith( K key, Function0 factory, Function2 function, P parameter) { synchronized (this.lock) { return this.getDelegate().updateValueWith(key, factory, function, parameter); } } @Override public MutableMapIterable groupByUniqueKey(Function function) { synchronized (this.lock) { return this.getDelegate().groupByUniqueKey(function); } } @Override public MutableMap aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { synchronized (this.lock) { return this.getDelegate().aggregateInPlaceBy(groupBy, zeroValueFactory, mutatingAggregator); } } @Override public MutableMap aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { synchronized (this.lock) { return this.getDelegate().aggregateBy(groupBy, zeroValueFactory, nonMutatingAggregator); } } @Override public MutableMap aggregateBy( Function keyFunction, Function valueFunction, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { synchronized (this.lock) { return this.getDelegate().aggregateBy(keyFunction, valueFunction, zeroValueFactory, nonMutatingAggregator); } } @Override public RichIterable> keyValuesView() { synchronized (this.lock) { Set> entries = this.getDelegate().entrySet(); Iterable> pairs = Iterate.collect(entries, AbstractImmutableEntry.getPairFunction()); return LazyIterate.adapt(pairs); } } @Override public MutableObjectLongMap sumByInt(Function groupBy, IntFunction function) { synchronized (this.lock) { return this.getDelegate().sumByInt(groupBy, function); } } @Override public MutableObjectDoubleMap sumByFloat(Function groupBy, FloatFunction function) { synchronized (this.lock) { return this.getDelegate().sumByFloat(groupBy, function); } } @Override public MutableObjectLongMap sumByLong(Function groupBy, LongFunction function) { synchronized (this.lock) { return this.getDelegate().sumByLong(groupBy, function); } } @Override public MutableObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction function) { synchronized (this.lock) { return this.getDelegate().sumByDouble(groupBy, function); } } /** * @since 9.0 */ @Override public MutableMultimap groupBy(Function function) { return (MutableMultimap) super.groupBy(function); } /** * @since 9.0 */ @Override public MutableMultimap groupByEach(Function> function) { return (MutableMultimap) super.groupByEach(function); } /** * @since 9.0 */ @Override public MutableCollection> zip(Iterable that) { return (MutableCollection>) super.zip(that); } /** * @since 9.0 */ @Override public MutableCollection> zipWithIndex() { return (MutableCollection>) super.zipWithIndex(); } /** * @since 9.0 */ @Override public MutableCollection select(Predicate predicate) { return (MutableCollection) super.select(predicate); } /** * @since 9.0 */ @Override public MutableCollection selectInstancesOf(Class clazz) { return (MutableCollection) super.selectInstancesOf(clazz); } /** * @since 9.0 */ @Override public

MutableCollection selectWith(Predicate2 predicate, P parameter) { return (MutableCollection) super.selectWith(predicate, parameter); } /** * @since 9.0 */ @Override public

MutableCollection rejectWith(Predicate2 predicate, P parameter) { return (MutableCollection) super.rejectWith(predicate, parameter); } /** * @since 9.0 */ @Override public PartitionMutableCollection partition(Predicate predicate) { return (PartitionMutableCollection) super.partition(predicate); } /** * @since 9.0 */ @Override public MutableBag countBy(Function function) { return (MutableBag) super.countBy(function); } /** * @since 9.0 */ @Override public MutableBag countByWith(Function2 function, P parameter) { return (MutableBag) super.countByWith(function, parameter); } /** * @since 10.0.0 */ @Override public MutableBag countByEach(Function> function) { return (MutableBag) super.countByEach(function); } /** * @since 9.0 */ @Override public MutableCollection reject(Predicate predicate) { return (MutableCollection) super.reject(predicate); } /** * @since 9.0 */ @Override public MutableMapIterable tap(Procedure procedure) { return (MutableMapIterable) super.tap(procedure); } }