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

com.gs.collections.impl.map.mutable.MapAdapter 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 2012 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.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.map.ImmutableMap;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.impl.factory.Maps;
import com.gs.collections.impl.utility.Iterate;
import com.gs.collections.impl.utility.MapIterate;

/**
 * This class provides a MutableMap wrapper around a JDK Collections Map interface instance.  All of the MutableMap
 * interface methods are supported in addition to the JDK Map interface methods.
 * 

* To create a new wrapper around an existing Map instance, use the {@link #adapt(Map)} factory method. */ public class MapAdapter extends AbstractMutableMap implements Serializable { private static final long serialVersionUID = 1L; protected final Map delegate; protected MapAdapter(Map newDelegate) { if (newDelegate == null) { throw new NullPointerException("MapAdapter may not wrap null"); } this.delegate = newDelegate; } public static MutableMap adapt(Map map) { return map instanceof MutableMap ? (MutableMap) map : new MapAdapter(map); } @Override public String toString() { return this.delegate.toString(); } @Override public MutableMap clone() { return UnifiedMap.newMap(this.delegate); } @Override public MutableMap newEmpty(int capacity) { return UnifiedMap.newMap(capacity); } public int size() { return this.delegate.size(); } @Override public boolean isEmpty() { return this.delegate.isEmpty(); } @Override public Iterator iterator() { return this.delegate.values().iterator(); } public V remove(Object key) { return this.delegate.remove(key); } public Set keySet() { return this.delegate.keySet(); } public Collection values() { return this.delegate.values(); } public Set> entrySet() { return this.delegate.entrySet(); } public void clear() { this.delegate.clear(); } public MutableMap newEmpty() { return UnifiedMap.newMap(); } public void forEachKeyValue(Procedure2 procedure) { MapIterate.forEachKeyValue(this.delegate, procedure); } public V get(Object key) { return this.delegate.get(key); } public V put(K key, V value) { return this.delegate.put(key, value); } public void putAll(Map map) { this.delegate.putAll(map); } public MutableMap collectKeysAndValues( Iterable iterable, Function keyFunction, Function valueFunction) { Iterate.addToMap(iterable, keyFunction, valueFunction, this.delegate); return this; } public V removeKey(K key) { return this.delegate.remove(key); } public boolean containsKey(Object key) { return this.delegate.containsKey(key); } public boolean containsValue(Object value) { return this.delegate.containsValue(value); } @Override public boolean equals(Object o) { return this.delegate.equals(o); } @Override public int hashCode() { return this.delegate.hashCode(); } @Override public ImmutableMap toImmutable() { return Maps.immutable.ofMap(this); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy