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

com.gs.collections.impl.map.SynchronizedMapIterable 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 2011 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.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;

import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.RichIterable;
import com.gs.collections.api.bag.MutableBag;
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.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
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.block.procedure.primitive.ObjectIntProcedure;
import com.gs.collections.api.collection.primitive.MutableBooleanCollection;
import com.gs.collections.api.collection.primitive.MutableByteCollection;
import com.gs.collections.api.collection.primitive.MutableCharCollection;
import com.gs.collections.api.collection.primitive.MutableDoubleCollection;
import com.gs.collections.api.collection.primitive.MutableFloatCollection;
import com.gs.collections.api.collection.primitive.MutableIntCollection;
import com.gs.collections.api.collection.primitive.MutableLongCollection;
import com.gs.collections.api.collection.primitive.MutableShortCollection;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.map.MapIterable;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.map.sorted.MutableSortedMap;
import com.gs.collections.api.multimap.MutableMultimap;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.sorted.MutableSortedSet;
import com.gs.collections.api.tuple.Pair;

/**
 * A synchronized view of a map.
 */
public abstract class SynchronizedMapIterable
        implements MapIterable, Serializable
{
    private static final long serialVersionUID = 1L;

    protected final Object lock;
    private final MapIterable mapIterable;

    protected SynchronizedMapIterable(MapIterable newMap)
    {
        this(newMap, null);
    }

    protected SynchronizedMapIterable(MapIterable newMap, Object newLock)
    {
        if (newMap == null)
        {
            throw new IllegalArgumentException("Cannot create a SynchronizedMapIterable on a null map");
        }
        this.mapIterable = newMap;
        this.lock = newLock == null ? this : newLock;
    }

    protected MapIterable getMap()
    {
        return this.mapIterable;
    }

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

    public boolean containsKey(Object key)
    {
        synchronized (this.lock)
        {
            return this.mapIterable.containsKey(key);
        }
    }

    public boolean containsValue(Object value)
    {
        synchronized (this.lock)
        {
            return this.mapIterable.containsValue(value);
        }
    }

    public void forEachValue(Procedure procedure)
    {
        synchronized (this.lock)
        {
            this.mapIterable.forEachValue(procedure);
        }
    }

    public void forEachKey(Procedure procedure)
    {
        synchronized (this.lock)
        {
            this.mapIterable.forEachKey(procedure);
        }
    }

    public void forEachKeyValue(Procedure2 procedure2)
    {
        synchronized (this.lock)
        {
            this.mapIterable.forEachKeyValue(procedure2);
        }
    }

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

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

    public 

V getIfAbsentWith(K key, Function function, P parameter) { synchronized (this.lock) { return this.mapIterable.getIfAbsentWith(key, function, parameter); } } public A ifPresentApply(K key, Function function) { synchronized (this.lock) { return this.mapIterable.ifPresentApply(key, function); } } public abstract RichIterable keysView(); public abstract RichIterable valuesView(); public Pair detect(Predicate2 predicate) { synchronized (this.lock) { return this.mapIterable.detect(predicate); } } public int size() { synchronized (this.lock) { return this.mapIterable.size(); } } public boolean isEmpty() { synchronized (this.lock) { return this.mapIterable.isEmpty(); } } public boolean notEmpty() { synchronized (this.lock) { return this.mapIterable.notEmpty(); } } public V getFirst() { synchronized (this.lock) { return this.mapIterable.getFirst(); } } public V getLast() { synchronized (this.lock) { return this.mapIterable.getLast(); } } public boolean contains(Object object) { synchronized (this.lock) { return this.mapIterable.contains(object); } } public boolean containsAllIterable(Iterable source) { synchronized (this.lock) { return this.mapIterable.containsAllIterable(source); } } public boolean containsAll(Collection source) { synchronized (this.lock) { return this.mapIterable.containsAll(source); } } public boolean containsAllArguments(Object... elements) { synchronized (this.lock) { return this.mapIterable.containsAllArguments(elements); } } public > R select(Predicate predicate, R target) { synchronized (this.lock) { return this.mapIterable.select(predicate, target); } } public

RichIterable selectWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.mapIterable.selectWith(predicate, parameter); } } public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { synchronized (this.lock) { return this.mapIterable.selectWith(predicate, parameter, targetCollection); } } public > R reject(Predicate predicate, R target) { synchronized (this.lock) { return this.mapIterable.reject(predicate, target); } } public

RichIterable rejectWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.mapIterable.rejectWith(predicate, parameter); } } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { synchronized (this.lock) { return this.mapIterable.rejectWith(predicate, parameter, targetCollection); } } public V detect(Predicate predicate) { synchronized (this.lock) { return this.mapIterable.detect(predicate); } } public

V detectWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.mapIterable.detectWith(predicate, parameter); } } public V detectIfNone(Predicate predicate, Function0 function) { synchronized (this.lock) { return this.mapIterable.detectIfNone(predicate, function); } } public

V detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { synchronized (this.lock) { return this.mapIterable.detectWithIfNone(predicate, parameter, function); } } public int count(Predicate predicate) { synchronized (this.lock) { return this.mapIterable.count(predicate); } } public

int countWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.mapIterable.countWith(predicate, parameter); } } public boolean anySatisfy(Predicate predicate) { synchronized (this.lock) { return this.mapIterable.anySatisfy(predicate); } } public boolean allSatisfy(Predicate predicate) { synchronized (this.lock) { return this.mapIterable.allSatisfy(predicate); } } public boolean noneSatisfy(Predicate predicate) { synchronized (this.lock) { return this.mapIterable.noneSatisfy(predicate); } } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.mapIterable.anySatisfyWith(predicate, parameter); } } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.mapIterable.allSatisfyWith(predicate, parameter); } } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.mapIterable.noneSatisfyWith(predicate, parameter); } } public IV injectInto(IV injectedValue, Function2 function) { synchronized (this.lock) { return this.mapIterable.injectInto(injectedValue, function); } } public int injectInto(int injectedValue, IntObjectToIntFunction function) { synchronized (this.lock) { return this.mapIterable.injectInto(injectedValue, function); } } public long injectInto(long injectedValue, LongObjectToLongFunction function) { synchronized (this.lock) { return this.mapIterable.injectInto(injectedValue, function); } } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { synchronized (this.lock) { return this.mapIterable.injectInto(injectedValue, function); } } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { synchronized (this.lock) { return this.mapIterable.injectInto(injectedValue, function); } } public long sumOfInt(IntFunction function) { synchronized (this.lock) { return this.mapIterable.sumOfInt(function); } } public double sumOfFloat(FloatFunction function) { synchronized (this.lock) { return this.mapIterable.sumOfFloat(function); } } public long sumOfLong(LongFunction function) { synchronized (this.lock) { return this.mapIterable.sumOfLong(function); } } public double sumOfDouble(DoubleFunction function) { synchronized (this.lock) { return this.mapIterable.sumOfDouble(function); } } public MutableList toList() { synchronized (this.lock) { return this.mapIterable.toList(); } } public MutableList toSortedList() { synchronized (this.lock) { return this.mapIterable.toSortedList(); } } public MutableList toSortedList(Comparator comparator) { synchronized (this.lock) { return this.mapIterable.toSortedList(comparator); } } public MutableSortedSet toSortedSet() { synchronized (this.lock) { return this.mapIterable.toSortedSet(); } } public MutableSortedSet toSortedSet(Comparator comparator) { synchronized (this.lock) { return this.mapIterable.toSortedSet(comparator); } } public MutableSet toSet() { synchronized (this.lock) { return this.mapIterable.toSet(); } } public MutableBag toBag() { synchronized (this.lock) { return this.mapIterable.toBag(); } } public MutableMap toMap( Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.mapIterable.toMap(keyFunction, valueFunction); } } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.mapIterable.toSortedMap(keyFunction, valueFunction); } } public MutableSortedMap toSortedMap( Comparator comparator, Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.mapIterable.toSortedMap(comparator, keyFunction, valueFunction); } } public LazyIterable asLazy() { synchronized (this.lock) { return this.mapIterable.asLazy(); } } public Object[] toArray() { synchronized (this.lock) { return this.mapIterable.toArray(); } } public T[] toArray(T[] a) { synchronized (this.lock) { return this.mapIterable.toArray(a); } } public V min(Comparator comparator) { synchronized (this.lock) { return this.mapIterable.min(comparator); } } public V max(Comparator comparator) { synchronized (this.lock) { return this.mapIterable.max(comparator); } } public V min() { synchronized (this.lock) { return this.mapIterable.min(); } } public V max() { synchronized (this.lock) { return this.mapIterable.max(); } } public String makeString() { synchronized (this.lock) { return this.mapIterable.makeString(); } } public String makeString(String separator) { synchronized (this.lock) { return this.mapIterable.makeString(separator); } } public String makeString(String start, String separator, String end) { synchronized (this.lock) { return this.mapIterable.makeString(start, separator, end); } } public void appendString(Appendable appendable) { synchronized (this.lock) { this.mapIterable.appendString(appendable); } } public void appendString(Appendable appendable, String separator) { synchronized (this.lock) { this.mapIterable.appendString(appendable, separator); } } public void appendString(Appendable appendable, String start, String separator, String end) { synchronized (this.lock) { this.mapIterable.appendString(appendable, start, separator, end); } } public >> R zip(Iterable that, R target) { synchronized (this.lock) { return this.mapIterable.zip(that, target); } } public >> R zipWithIndex(R target) { synchronized (this.lock) { return this.mapIterable.zipWithIndex(target); } } public RichIterable> chunk(int size) { synchronized (this.lock) { return this.mapIterable.chunk(size); } } public > R groupBy(Function function, R target) { synchronized (this.lock) { return this.mapIterable.groupBy(function, target); } } public > R groupByEach(Function> function, R target) { synchronized (this.lock) { return this.mapIterable.groupByEach(function, target); } } public > V minBy(Function function) { synchronized (this.lock) { return this.mapIterable.minBy(function); } } public > V maxBy(Function function) { synchronized (this.lock) { return this.mapIterable.maxBy(function); } } public > MutableSortedSet toSortedSetBy(Function function) { synchronized (this.lock) { return this.mapIterable.toSortedSetBy(function); } } public > MutableList toSortedListBy(Function function) { synchronized (this.lock) { return this.mapIterable.toSortedListBy(function); } } public > R flatCollect(Function> function, R target) { synchronized (this.lock) { return this.mapIterable.flatCollect(function, target); } } public RichIterable collectWith( Function2 function, P parameter) { synchronized (this.lock) { return this.mapIterable.collectWith(function, parameter); } } public > R collectIf( Predicate predicate, Function function, R target) { synchronized (this.lock) { return this.mapIterable.collectIf(predicate, function, target); } } public > R collectWith( Function2 function, P parameter, R targetCollection) { synchronized (this.lock) { return this.mapIterable.collectWith(function, parameter, targetCollection); } } public > R collect( Function function, R target) { synchronized (this.lock) { return this.mapIterable.collect(function, target); } } public R collectBoolean(BooleanFunction booleanFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectBoolean(booleanFunction, target); } } public R collectByte(ByteFunction byteFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectByte(byteFunction, target); } } public R collectChar(CharFunction charFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectChar(charFunction, target); } } public R collectDouble(DoubleFunction doubleFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectDouble(doubleFunction, target); } } public R collectFloat(FloatFunction floatFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectFloat(floatFunction, target); } } public R collectInt(IntFunction intFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectInt(intFunction, target); } } public R collectLong(LongFunction longFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectLong(longFunction, target); } } public R collectShort(ShortFunction shortFunction, R target) { synchronized (this.lock) { return this.mapIterable.collectShort(shortFunction, target); } } public void forEach(Procedure procedure) { synchronized (this.lock) { this.mapIterable.forEach(procedure); } } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { synchronized (this.lock) { this.mapIterable.forEachWithIndex(objectIntProcedure); } } public

void forEachWith(Procedure2 procedure2, P parameter) { synchronized (this.lock) { this.mapIterable.forEachWith(procedure2, parameter); } } public Iterator iterator() { return this.mapIterable.iterator(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy