
org.eclipse.collections.impl.map.mutable.UnmodifiableMutableMap Maven / Gradle / Ivy
/*
* Copyright (c) 2022 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.mutable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.eclipse.collections.api.BooleanIterable;
import org.eclipse.collections.api.ByteIterable;
import org.eclipse.collections.api.CharIterable;
import org.eclipse.collections.api.DoubleIterable;
import org.eclipse.collections.api.FloatIterable;
import org.eclipse.collections.api.IntIterable;
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.LongIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.ShortIterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.primitive.MutableBooleanBag;
import org.eclipse.collections.api.bag.primitive.MutableByteBag;
import org.eclipse.collections.api.bag.primitive.MutableCharBag;
import org.eclipse.collections.api.bag.primitive.MutableDoubleBag;
import org.eclipse.collections.api.bag.primitive.MutableFloatBag;
import org.eclipse.collections.api.bag.primitive.MutableIntBag;
import org.eclipse.collections.api.bag.primitive.MutableLongBag;
import org.eclipse.collections.api.bag.primitive.MutableShortBag;
import org.eclipse.collections.api.bag.sorted.MutableSortedBag;
import org.eclipse.collections.api.bimap.MutableBiMap;
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.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.IntObjectToIntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.LongObjectToLongFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
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.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.collection.primitive.MutableBooleanCollection;
import org.eclipse.collections.api.collection.primitive.MutableByteCollection;
import org.eclipse.collections.api.collection.primitive.MutableCharCollection;
import org.eclipse.collections.api.collection.primitive.MutableDoubleCollection;
import org.eclipse.collections.api.collection.primitive.MutableFloatCollection;
import org.eclipse.collections.api.collection.primitive.MutableIntCollection;
import org.eclipse.collections.api.collection.primitive.MutableLongCollection;
import org.eclipse.collections.api.collection.primitive.MutableShortCollection;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MapIterable;
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.map.sorted.MutableSortedMap;
import org.eclipse.collections.api.multimap.MutableMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.multimap.set.MutableSetMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.bag.PartitionMutableBag;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.UnmodifiableIteratorAdapter;
import org.eclipse.collections.impl.UnmodifiableMap;
import org.eclipse.collections.impl.tuple.AbstractImmutableEntry;
import org.eclipse.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-Eclipse-Collections 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));
}
@Override
public MutableMap newEmpty()
{
return this.getMutableMap().newEmpty();
}
@Override
public boolean notEmpty()
{
return this.getMutableMap().notEmpty();
}
@Override
public void forEachValue(Procedure super V> procedure)
{
this.getMutableMap().forEachValue(procedure);
}
@Override
public void forEachKey(Procedure super K> procedure)
{
this.getMutableMap().forEachKey(procedure);
}
@Override
public void forEachKeyValue(Procedure2 super K, ? super V> procedure)
{
this.getMutableMap().forEachKeyValue(procedure);
}
@Override
public MutableMap flipUniqueValues()
{
return this.getMutableMap().flipUniqueValues();
}
@Override
public MutableMap collectKeysAndValues(
Iterable iterable,
Function super E, ? extends K> keyFunction,
Function super E, ? extends V> valueFunction)
{
throw new UnsupportedOperationException("Cannot call collectKeysAndValues() on " + this.getClass().getSimpleName());
}
@Override
public V removeKey(K key)
{
throw new UnsupportedOperationException("Cannot call removeKey() on " + this.getClass().getSimpleName());
}
@Override
public boolean removeAllKeys(Set extends K> keys)
{
throw new UnsupportedOperationException("Cannot call removeAllKeys() on " + this.getClass().getSimpleName());
}
@Override
public boolean removeIf(Predicate2 super K, ? super V> predicate)
{
throw new UnsupportedOperationException("Cannot call removeIf() on " + this.getClass().getSimpleName());
}
@Override
public V updateValue(K key, Function0 extends V> factory, Function super V, ? extends V> function)
{
throw new UnsupportedOperationException("Cannot call updateValue() on " + this.getClass().getSimpleName());
}
@Override
public V updateValueWith(
K key,
Function0 extends V> factory,
Function2 super V, ? super P, ? extends V> function,
P parameter)
{
throw new UnsupportedOperationException("Cannot call updateValueWith() on " + this.getClass().getSimpleName());
}
@Override
public V getIfAbsentPut(K key, Function0 extends V> function)
{
V result = this.get(key);
if (this.isAbsent(result, key))
{
throw new UnsupportedOperationException("Cannot mutate " + this.getClass().getSimpleName());
}
return result;
}
@Override
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;
}
@Override
public V getIfAbsentPutWithKey(K key, Function super K, ? extends V> function)
{
return this.getIfAbsentPutWith(key, function, key);
}
@Override
public
V getIfAbsentPutWith(
K key,
Function super P, ? extends V> function,
P parameter)
{
V result = this.get(key);
if (this.isAbsent(result, key))
{
throw new UnsupportedOperationException("Cannot mutate " + this.getClass().getSimpleName());
}
return result;
}
@Override
public V getIfAbsent(K key, Function0 extends V> function)
{
return this.getMutableMap().getIfAbsent(key, function);
}
@Override
public V getIfAbsentValue(K key, V value)
{
return this.getMutableMap().getIfAbsentValue(key, value);
}
@Override
public