001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.collections4.splitmap; 018 019import java.util.Collection; 020import java.util.Map; 021import java.util.Set; 022 023import org.apache.commons.collections4.IterableGet; 024import org.apache.commons.collections4.MapIterator; 025import org.apache.commons.collections4.map.EntrySetToMapIteratorAdapter; 026 027/** 028 * {@link IterableGet} that uses a {@link Map}<K, V> for the 029 * {@link org.apache.commons.collections4.Get Get}<K, V> implementation. 030 * 031 * @since 4.0 032 * @version $Id: AbstractIterableGetMapDecorator.html 972421 2015-11-14 20:00:04Z tn $ 033 */ 034public class AbstractIterableGetMapDecorator<K, V> implements IterableGet<K, V> { 035 036 /** The map to decorate */ 037 transient Map<K, V> map; 038 039 /** 040 * Create a new AbstractSplitMapDecorator. 041 * @param decorated the Map to decorate 042 */ 043 public AbstractIterableGetMapDecorator(final Map<K, V> decorated) { 044 this.map = decorated; 045 } 046 047 /** 048 * Constructor only used in deserialization, do not use otherwise. 049 */ 050 protected AbstractIterableGetMapDecorator() { 051 super(); 052 } 053 054 /** 055 * Gets the map being decorated. 056 * 057 * @return the decorated map 058 */ 059 protected Map<K, V> decorated() { 060 return map; 061 } 062 063 public boolean containsKey(final Object key) { 064 return decorated().containsKey(key); 065 } 066 067 public boolean containsValue(final Object value) { 068 return decorated().containsValue(value); 069 } 070 071 public Set<Map.Entry<K, V>> entrySet() { 072 return decorated().entrySet(); 073 } 074 075 public V get(final Object key) { 076 return decorated().get(key); 077 } 078 079 public V remove(final Object key) { 080 return decorated().remove(key); 081 } 082 083 public boolean isEmpty() { 084 return decorated().isEmpty(); 085 } 086 087 public Set<K> keySet() { 088 return decorated().keySet(); 089 } 090 091 public int size() { 092 return decorated().size(); 093 } 094 095 public Collection<V> values() { 096 return decorated().values(); 097 } 098 099 /** 100 * Get a MapIterator over this Get. 101 * @return MapIterator<K, V> 102 */ 103 public MapIterator<K, V> mapIterator() { 104 return new EntrySetToMapIteratorAdapter<K, V>(entrySet()); 105 } 106 107 @Override 108 public boolean equals(final Object object) { 109 if (object == this) { 110 return true; 111 } 112 return decorated().equals(object); 113 } 114 115 @Override 116 public int hashCode() { 117 return decorated().hashCode(); 118 } 119 120 @Override 121 public String toString() { 122 return decorated().toString(); 123 } 124 125}