Collection<V> () { if (values != null) { return values; } values = new AbstractCollection<V>() { @Override public @NotNull Iterator<V> iterator() { return new Iterator<V>() { private final Iterator<Collection<V>> mapIterator = myMap.values().iterator(); private Iterator<V> itr = Collections.emptyIterator(); @Override public boolean hasNext() { do { if (itr.hasNext()) return true; if (!mapIterator.hasNext()) return false; itr = mapIterator.next().iterator(); } while (true); } @Override public V next() { do { if (itr.hasNext()) return itr.next(); if (!mapIterator.hasNext()) throw new NoSuchElementException(); itr = mapIterator.next().iterator(); } while (true); } @Override public void remove() { itr.remove(); } }; } @Override public int size() { int res = 0; for (Collection<V> vs : myMap.values()) { res += vs.size(); } return res; } // Don't remove this method!!! @Override public boolean contains(Object o) { for (Collection<V> vs : myMap.values()) { if (vs.contains(o)) return true; } return false; } }; return values; }