com.google.common.collect.ForwardingCollection Java Examples
The following examples show how to use
com.google.common.collect.ForwardingCollection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectUriResourceMap.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override public Collection<Resource> values() { if (localContents.isEmpty()) { return Collections.emptyList(); } // Nasty ... we have to support values().iterator().remove() Collection<Resource> base = super.values(); Collection<Resource> delegate = Collections2.filter(base, resource -> localContents.contains(resource.getURI())); return new ForwardingCollection<>() { @Override protected Collection<Resource> delegate() { return delegate; } @Override public Iterator<Resource> iterator() { Iterator<URI> delegateIterator = localContents.iterator(); Iterator<Resource> resourceIterator = Iterators.transform(delegateIterator, globalMap::get); return new ForwardingIterator<>() { private URI prev = null; @Override protected Iterator<Resource> delegate() { return resourceIterator; } public Resource next() { Resource result = super.next(); prev = result.getURI(); return result; } public void remove() { super.remove(); globalMap.remove(prev); } }; } }; }