Example usage for com.google.common.collect ForwardingMapEntry ForwardingMapEntry

List of usage examples for com.google.common.collect ForwardingMapEntry ForwardingMapEntry

Introduction

In this page you can find the example usage for com.google.common.collect ForwardingMapEntry ForwardingMapEntry.

Prototype

protected ForwardingMapEntry() 

Source Link

Document

Constructor for use by subclasses.

Usage

From source file:com.github.benmanes.caffeine.guava.CaffeinatedGuavaCache.java

@Override
public ConcurrentMap<K, V> asMap() {
    return new ForwardingConcurrentMap<K, V>() {
        @Override//from  www . java 2 s.  co m
        public boolean containsKey(Object key) {
            return (key != null) && delegate().containsKey(key);
        }

        @Override
        public boolean containsValue(Object value) {
            return (value != null) && delegate().containsValue(value);
        }

        @Override
        public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
            delegate().replaceAll(function);
        }

        @Override
        public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
            return delegate().computeIfAbsent(key, mappingFunction);
        }

        @Override
        public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
            return delegate().computeIfPresent(key, remappingFunction);
        }

        @Override
        public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
            return delegate().compute(key, remappingFunction);
        }

        @Override
        public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
            return delegate().merge(key, value, remappingFunction);
        }

        @Override
        public Set<K> keySet() {
            return new ForwardingSet<K>() {
                @Override
                public boolean removeIf(Predicate<? super K> filter) {
                    return delegate().removeIf(filter);
                }

                @Override
                public boolean remove(Object o) {
                    return (o != null) && delegate().remove(o);
                }

                @Override
                protected Set<K> delegate() {
                    return cache.asMap().keySet();
                }
            };
        }

        @Override
        public Collection<V> values() {
            return new ForwardingCollection<V>() {
                @Override
                public boolean removeIf(Predicate<? super V> filter) {
                    return delegate().removeIf(filter);
                }

                @Override
                public boolean remove(Object o) {
                    return (o != null) && delegate().remove(o);
                }

                @Override
                protected Collection<V> delegate() {
                    return cache.asMap().values();
                }
            };
        }

        @Override
        public Set<Entry<K, V>> entrySet() {
            return new ForwardingSet<Entry<K, V>>() {
                @Override
                public boolean add(Entry<K, V> entry) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public boolean addAll(Collection<? extends Entry<K, V>> entry) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public boolean removeIf(Predicate<? super Entry<K, V>> filter) {
                    return delegate().removeIf(filter);
                }

                @Override
                public Iterator<Entry<K, V>> iterator() {
                    Iterator<Entry<K, V>> iterator = delegate().iterator();
                    return new ForwardingIterator<Entry<K, V>>() {
                        @Override
                        public Entry<K, V> next() {
                            Entry<K, V> entry = delegate().next();
                            return new ForwardingMapEntry<K, V>() {
                                @Override
                                public V setValue(V value) {
                                    throw new UnsupportedOperationException();
                                }

                                @Override
                                protected Entry<K, V> delegate() {
                                    return entry;
                                }
                            };
                        }

                        @Override
                        protected Iterator<Entry<K, V>> delegate() {
                            return iterator;
                        }
                    };
                }

                @Override
                protected Set<Entry<K, V>> delegate() {
                    return cache.asMap().entrySet();
                }
            };
        }

        @Override
        protected ConcurrentMap<K, V> delegate() {
            return cache.asMap();
        }
    };
}