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

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

Introduction

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

Prototype

protected ForwardingCollection() 

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 ww w  . j a  va2s. c o 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();
        }
    };
}

From source file:org.apache.flex.compiler.internal.targets.FlexLibrarySWFTarget.java

@Override
protected void waitForCompilationUnitToFinish(final ICompilationUnit cu,
        final Collection<ICompilerProblem> problems) throws InterruptedException {
    Collection<ICompilerProblem> problemsWithFilter = problems;

    // We we are externally linking a SWC into another SWC,
    // we need to filter out resource bundle not found problems
    // like the Flex 4.6.X compiler did.
    ////from   w w w . j a  va2 s .c o m
    // In an ideal world we would not need to do this
    // or we'd know we need to do it forever.  If we don't
    // need this filtering in the future, we can rip out this code.
    // If we continue to need this filter we should defer creation
    // of these problems until link time.
    if (getLinkageChecker().isExternal(cu)) {
        // Collection implementation that drops
        // ICompilerProblems on the floor if they are instances of
        // ResourceBundleNotFoundProblem or
        // ResourceBundleNotFoundForLocaleProblem.
        problemsWithFilter = new ForwardingCollection<ICompilerProblem>() {
            @Override
            protected final Collection<ICompilerProblem> delegate() {
                return problems;
            }

            @Override
            public final boolean add(ICompilerProblem element) {
                if (element instanceof ResourceBundleNotFoundProblem)
                    return false;
                if (element instanceof ResourceBundleNotFoundForLocaleProblem)
                    return false;
                return super.add(element);
            }

            @Override
            public final boolean addAll(Collection<? extends ICompilerProblem> collection) {
                boolean result = false;
                for (ICompilerProblem problem : collection) {
                    if (add(problem))
                        result = true;
                }
                return result;
            }
        };
    }
    super.waitForCompilationUnitToFinish(cu, problemsWithFilter);
}