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

com.gs.collections.impl.map.AbstractSynchronizedMapIterable Maven / Gradle / Ivy

Go to download

GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.

There is a newer version: 7.0.3
Show newest version
/*
 * Copyright 2015 Goldman Sachs.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gs.collections.impl.map;

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

import com.gs.collections.api.RichIterable;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function0;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.map.MutableMapIterable;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.collection.AbstractSynchronizedRichIterable;
import com.gs.collections.impl.tuple.AbstractImmutableEntry;
import com.gs.collections.impl.utility.Iterate;
import com.gs.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();
    }

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

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

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

    public 

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

V getIfAbsentPutWith(K key, Function function, P parameter) { synchronized (this.lock) { return this.getDelegate().getIfAbsentPutWith(key, function, parameter); } } public V put(K key, V value) { synchronized (this.lock) { return this.getDelegate().put(key, value); } } public V remove(Object key) { synchronized (this.lock) { return this.getDelegate().remove(key); } } public V removeKey(K key) { synchronized (this.lock) { return this.getDelegate().removeKey(key); } } public void putAll(Map map) { synchronized (this.lock) { this.getDelegate().putAll(map); } } public void clear() { synchronized (this.lock) { this.getDelegate().clear(); } } public V add(Pair keyValuePair) { synchronized (this.lock) { return this.put(keyValuePair.getOne(), keyValuePair.getTwo()); } } public V updateValue(K key, Function0 factory, Function function) { synchronized (this.lock) { return this.getDelegate().updateValue(key, factory, function); } } public

V updateValueWith( K key, Function0 factory, Function2 function, P parameter) { synchronized (this.lock) { return this.getDelegate().updateValueWith(key, factory, function, parameter); } } public RichIterable> keyValuesView() { synchronized (this.lock) { Set> entries = this.getDelegate().entrySet(); Iterable> pairs = Iterate.collect(entries, AbstractImmutableEntry.getPairFunction()); return LazyIterate.adapt(pairs); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy