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

com.gs.collections.impl.map.mutable.UnmodifiableMutableMap 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.mutable;

import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;

import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.RichIterable;
import com.gs.collections.api.bag.MutableBag;
import com.gs.collections.api.bag.primitive.MutableBooleanBag;
import com.gs.collections.api.bag.primitive.MutableByteBag;
import com.gs.collections.api.bag.primitive.MutableCharBag;
import com.gs.collections.api.bag.primitive.MutableDoubleBag;
import com.gs.collections.api.bag.primitive.MutableFloatBag;
import com.gs.collections.api.bag.primitive.MutableIntBag;
import com.gs.collections.api.bag.primitive.MutableLongBag;
import com.gs.collections.api.bag.primitive.MutableShortBag;
import com.gs.collections.api.bag.sorted.MutableSortedBag;
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.ImmutableMap;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.map.primitive.ObjectDoubleMap;
import com.gs.collections.api.map.primitive.ObjectLongMap;
import com.gs.collections.api.map.sorted.MutableSortedMap;
import com.gs.collections.api.multimap.MutableMultimap;
import com.gs.collections.api.multimap.bag.MutableBagMultimap;
import com.gs.collections.api.multimap.set.MutableSetMultimap;
import com.gs.collections.api.ordered.OrderedIterable;
import com.gs.collections.api.partition.bag.PartitionMutableBag;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.sorted.MutableSortedSet;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.UnmodifiableIteratorAdapter;
import com.gs.collections.impl.UnmodifiableMap;
import com.gs.collections.impl.factory.Maps;
import com.gs.collections.impl.tuple.AbstractImmutableEntry;
import com.gs.collections.impl.utility.LazyIterate;

/**
 * An unmodifiable view of a map.
 *
 * @see MutableMap#asUnmodifiable()
 */
public class UnmodifiableMutableMap
        extends UnmodifiableMap
        implements MutableMap
{
    private static final long serialVersionUID = 1L;

    protected UnmodifiableMutableMap(MutableMap map)
    {
        super(map);
    }

    /**
     * This method will take a MutableMap and wrap it directly in a UnmodifiableMutableMap.  It will
     * take any other non-GS-map and first adapt it will a MapAdapter, and then return a
     * UnmodifiableMutableMap that wraps the adapter.
     */
    public static > UnmodifiableMutableMap of(M map)
    {
        if (map == null)
        {
            throw new IllegalArgumentException("cannot create a UnmodifiableMutableMap for null");
        }
        return new UnmodifiableMutableMap(MapAdapter.adapt(map));
    }

    public MutableMap newEmpty()
    {
        return this.getMutableMap().newEmpty();
    }

    public boolean notEmpty()
    {
        return this.getMutableMap().notEmpty();
    }

    public void forEachValue(Procedure procedure)
    {
        this.getMutableMap().forEachValue(procedure);
    }

    public void forEachKey(Procedure procedure)
    {
        this.getMutableMap().forEachKey(procedure);
    }

    public void forEachKeyValue(Procedure2 procedure)
    {
        this.getMutableMap().forEachKeyValue(procedure);
    }

    public MutableMap flipUniqueValues()
    {
        return this.getMutableMap().flipUniqueValues();
    }

    public  MutableMap collectKeysAndValues(
            Iterable iterable,
            Function keyFunction,
            Function valueFunction)
    {
        throw new UnsupportedOperationException("Cannot call collectKeysAndValues() on " + this.getClass().getSimpleName());
    }

    public V removeKey(K key)
    {
        throw new UnsupportedOperationException("Cannot call removeKey() on " + this.getClass().getSimpleName());
    }

    public V updateValue(K key, Function0 factory, Function function)
    {
        throw new UnsupportedOperationException("Cannot call updateValue() on " + this.getClass().getSimpleName());
    }

    public 

V updateValueWith( K key, Function0 factory, Function2 function, P parameter) { throw new UnsupportedOperationException("Cannot call updateValueWith() on " + this.getClass().getSimpleName()); } public V getIfAbsentPut(K key, Function0 function) { V result = this.get(key); if (this.isAbsent(result, key)) { throw new UnsupportedOperationException("Cannot mutate " + this.getClass().getSimpleName()); } return result; } public V getIfAbsentPut(K key, V value) { V result = this.get(key); if (this.isAbsent(result, key)) { throw new UnsupportedOperationException("Cannot mutate " + this.getClass().getSimpleName()); } return result; } public V getIfAbsentPutWithKey(K key, Function function) { return this.getIfAbsentPutWith(key, function, key); } public

V getIfAbsentPutWith( K key, Function function, P parameter) { V result = this.get(key); if (this.isAbsent(result, key)) { throw new UnsupportedOperationException("Cannot mutate " + this.getClass().getSimpleName()); } return result; } public V getIfAbsent(K key, Function0 function) { V result = this.get(key); if (this.isAbsent(result, key)) { return function.value(); } return result; } public V getIfAbsentValue(K key, V value) { V result = this.get(key); if (this.isAbsent(result, key)) { return value; } return result; } public

V getIfAbsentWith( K key, Function function, P parameter) { V result = this.get(key); if (this.isAbsent(result, key)) { return function.valueOf(parameter); } return result; } private boolean isAbsent(V result, K key) { return result == null && !this.containsKey(key); } public A ifPresentApply(K key, Function function) { return this.getMutableMap().ifPresentApply(key, function); } public V add(Pair keyValuePair) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public MutableMap withKeyValue(K key, V value) { throw new UnsupportedOperationException("Cannot call withKeyValue() on " + this.getClass().getSimpleName()); } public MutableMap withAllKeyValues(Iterable> keyValues) { throw new UnsupportedOperationException("Cannot call withAllKeyValues() on " + this.getClass().getSimpleName()); } public MutableMap withAllKeyValueArguments(Pair... keyValuePairs) { throw new UnsupportedOperationException("Cannot call withAllKeyValueArguments() on " + this.getClass().getSimpleName()); } public MutableMap withoutKey(K key) { throw new UnsupportedOperationException("Cannot call withoutKey() on " + this.getClass().getSimpleName()); } public MutableMap withoutAllKeys(Iterable keys) { throw new UnsupportedOperationException("Cannot call withoutAllKeys() on " + this.getClass().getSimpleName()); } public MutableSetMultimap flip() { return this.getMutableMap().flip(); } @Override public MutableMap clone() { return this; } public MutableMap asUnmodifiable() { return this; } public MutableMap asSynchronized() { return SynchronizedMutableMap.of(this); } public MutableMap tap(Procedure procedure) { this.forEach(procedure); return this; } public void forEach(Procedure procedure) { this.each(procedure); } public void each(Procedure procedure) { this.getMutableMap().forEach(procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.getMutableMap().forEachWithIndex(objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { this.getMutableMap().forEachWith(procedure, parameter); } public Iterator iterator() { return new UnmodifiableIteratorAdapter(this.getMutableMap().iterator()); } @Override public int hashCode() { return this.getMutableMap().hashCode(); } @Override public boolean equals(Object obj) { return this.getMutableMap().equals(obj); } protected MutableMap getMutableMap() { return (MutableMap) this.delegate; } public RichIterable keysView() { return LazyIterate.adapt(this.keySet()); } public RichIterable valuesView() { return LazyIterate.adapt(this.values()); } public RichIterable> keyValuesView() { return LazyIterate.adapt(this.entrySet()).collect(AbstractImmutableEntry.getPairFunction()); } public ImmutableMap toImmutable() { return Maps.immutable.withAll(this); } public MutableMap collectValues(Function2 function) { return this.getMutableMap().collectValues(function); } public MutableMap collect(Function2> function) { return this.getMutableMap().collect(function); } public MutableMap select(Predicate2 predicate) { return this.getMutableMap().select(predicate); } public MutableMap reject(Predicate2 predicate) { return this.getMutableMap().reject(predicate); } public Pair detect(Predicate2 predicate) { return this.getMutableMap().detect(predicate); } public boolean allSatisfy(Predicate predicate) { return this.getMutableMap().allSatisfy(predicate); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableMap().allSatisfyWith(predicate, parameter); } public boolean noneSatisfy(Predicate predicate) { return this.getMutableMap().noneSatisfy(predicate); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableMap().noneSatisfyWith(predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return this.getMutableMap().anySatisfy(predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableMap().anySatisfyWith(predicate, parameter); } public void appendString(Appendable appendable) { this.getMutableMap().appendString(appendable); } public void appendString(Appendable appendable, String separator) { this.getMutableMap().appendString(appendable, separator); } public void appendString(Appendable appendable, String start, String separator, String end) { this.getMutableMap().appendString(appendable, start, separator, end); } public MutableBag toBag() { return this.getMutableMap().toBag(); } public MutableSortedBag toSortedBag() { return this.getMutableMap().toSortedBag(); } public MutableSortedBag toSortedBag(Comparator comparator) { return this.getMutableMap().toSortedBag(comparator); } public > MutableSortedBag toSortedBagBy(Function function) { return this.getMutableMap().toSortedBagBy(function); } public LazyIterable asLazy() { return this.getMutableMap().asLazy(); } public MutableList toList() { return this.getMutableMap().toList(); } public MutableMap toMap( Function keyFunction, Function valueFunction) { return this.getMutableMap().toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return this.getMutableMap().toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Comparator comparator, Function keyFunction, Function valueFunction) { return this.getMutableMap().toSortedMap(comparator, keyFunction, valueFunction); } public MutableSet toSet() { return this.getMutableMap().toSet(); } public MutableList toSortedList() { return this.getMutableMap().toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.getMutableMap().toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.getMutableMap().toSortedListBy(function); } public MutableSortedSet toSortedSet() { return this.getMutableMap().toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.getMutableMap().toSortedSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return this.getMutableMap().toSortedSetBy(function); } public RichIterable> chunk(int size) { return this.getMutableMap().chunk(size); } public > C collect(Function function, C target) { return this.getMutableMap().collect(function, target); } public > C collectIf(Predicate predicate, Function function, C target) { return this.getMutableMap().collectIf(predicate, function, target); } public MutableBag collectWith(Function2 function, P parameter) { return this.getMutableMap().collectWith(function, parameter); } public > C collectWith(Function2 function, P parameter, C targetCollection) { return this.getMutableMap().collectWith(function, parameter, targetCollection); } public boolean contains(Object object) { return this.containsValue(object); } public boolean containsAllArguments(Object... elements) { return this.getMutableMap().containsAllArguments(elements); } public boolean containsAllIterable(Iterable source) { return this.getMutableMap().containsAllIterable(source); } public boolean containsAll(Collection source) { return this.containsAllIterable(source); } public int count(Predicate predicate) { return this.getMutableMap().count(predicate); } public

int countWith(Predicate2 predicate, P parameter) { return this.getMutableMap().countWith(predicate, parameter); } public V detect(Predicate predicate) { return this.getMutableMap().detect(predicate); } public

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

V detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return this.getMutableMap().detectWithIfNone(predicate, parameter, function); } public > C flatCollect(Function> function, C target) { return this.getMutableMap().flatCollect(function, target); } public V getFirst() { return this.getMutableMap().getFirst(); } public V getLast() { return this.getMutableMap().getLast(); } public MutableBagMultimap groupBy(Function function) { return this.getMutableMap().groupBy(function); } public > C groupBy(Function function, C target) { return this.getMutableMap().groupBy(function, target); } public MutableBagMultimap groupByEach(Function> function) { return this.getMutableMap().groupByEach(function); } public > C groupByEach(Function> function, C target) { return this.getMutableMap().groupByEach(function, target); } public MutableMap groupByUniqueKey(Function function) { return this.getMutableMap().groupByUniqueKey(function); } public > R groupByUniqueKey(Function function, R target) { return this.getMutableMap().groupByUniqueKey(function, target); } public IV injectInto(IV injectedValue, Function2 function) { return this.getMutableMap().injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.getMutableMap().injectInto(injectedValue, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.getMutableMap().injectInto(injectedValue, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.getMutableMap().injectInto(injectedValue, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.getMutableMap().injectInto(injectedValue, function); } public long sumOfInt(IntFunction function) { return this.getMutableMap().sumOfInt(function); } public double sumOfFloat(FloatFunction function) { return this.getMutableMap().sumOfFloat(function); } public long sumOfLong(LongFunction function) { return this.getMutableMap().sumOfLong(function); } public double sumOfDouble(DoubleFunction function) { return this.getMutableMap().sumOfDouble(function); } public ObjectLongMap sumByInt(Function groupBy, IntFunction function) { return this.getMutableMap().sumByInt(groupBy, function); } public ObjectDoubleMap sumByFloat(Function groupBy, FloatFunction function) { return this.getMutableMap().sumByFloat(groupBy, function); } public ObjectLongMap sumByLong(Function groupBy, LongFunction function) { return this.getMutableMap().sumByLong(groupBy, function); } public ObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction function) { return this.getMutableMap().sumByDouble(groupBy, function); } public String makeString() { return this.getMutableMap().makeString(); } public String makeString(String separator) { return this.getMutableMap().makeString(separator); } public String makeString(String start, String separator, String end) { return this.getMutableMap().makeString(start, separator, end); } public V max() { return this.getMutableMap().max(); } public V max(Comparator comparator) { return this.getMutableMap().max(comparator); } public > V maxBy(Function function) { return this.getMutableMap().maxBy(function); } public V min() { return this.getMutableMap().min(); } public V min(Comparator comparator) { return this.getMutableMap().min(comparator); } public > V minBy(Function function) { return this.getMutableMap().minBy(function); } public Object[] toArray() { return this.getMutableMap().toArray(); } public T[] toArray(T[] a) { return this.getMutableMap().toArray(a); } public >> R zip(Iterable that, R target) { return this.getMutableMap().zip(that, target); } public >> R zipWithIndex(R target) { return this.getMutableMap().zipWithIndex(target); } public MutableBag collect(Function function) { return this.getMutableMap().collect(function); } public MutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { return this.getMutableMap().collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.getMutableMap().collectBoolean(booleanFunction, target); } public MutableByteBag collectByte(ByteFunction byteFunction) { return this.getMutableMap().collectByte(byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return this.getMutableMap().collectByte(byteFunction, target); } public MutableCharBag collectChar(CharFunction charFunction) { return this.getMutableMap().collectChar(charFunction); } public R collectChar(CharFunction charFunction, R target) { return this.getMutableMap().collectChar(charFunction, target); } public MutableDoubleBag collectDouble(DoubleFunction doubleFunction) { return this.getMutableMap().collectDouble(doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.getMutableMap().collectDouble(doubleFunction, target); } public MutableFloatBag collectFloat(FloatFunction floatFunction) { return this.getMutableMap().collectFloat(floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return this.getMutableMap().collectFloat(floatFunction, target); } public MutableIntBag collectInt(IntFunction intFunction) { return this.getMutableMap().collectInt(intFunction); } public R collectInt(IntFunction intFunction, R target) { return this.getMutableMap().collectInt(intFunction, target); } public MutableLongBag collectLong(LongFunction longFunction) { return this.getMutableMap().collectLong(longFunction); } public R collectLong(LongFunction longFunction, R target) { return this.getMutableMap().collectLong(longFunction, target); } public MutableShortBag collectShort(ShortFunction shortFunction) { return this.getMutableMap().collectShort(shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return this.getMutableMap().collectShort(shortFunction, target); } public MutableBag collectIf(Predicate predicate, Function function) { return this.getMutableMap().collectIf(predicate, function); } public MutableBag flatCollect(Function> function) { return this.getMutableMap().flatCollect(function); } public MutableBag select(Predicate predicate) { return this.getMutableMap().select(predicate); } public > R select(Predicate predicate, R target) { return this.getMutableMap().select(predicate, target); } public

MutableBag selectWith(Predicate2 predicate, P parameter) { return this.getMutableMap().selectWith(predicate, parameter); } public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.getMutableMap().selectWith(predicate, parameter, targetCollection); } public MutableBag reject(Predicate predicate) { return this.getMutableMap().reject(predicate); } public > R reject(Predicate predicate, R target) { return this.getMutableMap().reject(predicate, target); } public

MutableBag rejectWith(Predicate2 predicate, P parameter) { return this.getMutableMap().rejectWith(predicate, parameter); } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.getMutableMap().rejectWith(predicate, parameter, targetCollection); } public MutableBag selectInstancesOf(Class clazz) { return this.getMutableMap().selectInstancesOf(clazz); } public PartitionMutableBag partition(Predicate predicate) { return this.getMutableMap().partition(predicate); } public

PartitionMutableBag partitionWith(Predicate2 predicate, P parameter) { return this.getMutableMap().partitionWith(predicate, parameter); } /** * @deprecated in 6.0. Use {@link OrderedIterable#zip(Iterable)} instead. */ @Deprecated public MutableBag> zip(Iterable that) { return this.getMutableMap().zip(that); } /** * @deprecated in 6.0. Use {@link OrderedIterable#zipWithIndex()} instead. */ @Deprecated public MutableSet> zipWithIndex() { return this.getMutableMap().zipWithIndex(); } public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { return this.getMutableMap().aggregateInPlaceBy(groupBy, zeroValueFactory, mutatingAggregator); } public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { return this.getMutableMap().aggregateBy(groupBy, zeroValueFactory, nonMutatingAggregator); } }