Example usage for java.util AbstractCollection AbstractCollection

List of usage examples for java.util AbstractCollection AbstractCollection

Introduction

In this page you can find the example usage for java.util AbstractCollection AbstractCollection.

Prototype

protected AbstractCollection() 

Source Link

Document

Sole constructor.

Usage

From source file:jahspotify.storage.statistics.MongoDBHistoricalStorage.java

@Override
public Collection<TrackHistory> getHistory(final int index, final int count,
        final HistoryCriteria... historyCriterias) {
    final DBCollection tracks = _db.getCollection("history");

    final DBCursor dbObjects = tracks.find();
    dbObjects.skip(index);//  ww  w. j  a v  a  2s  . c o m
    dbObjects.limit(count);
    final BasicDBObject orderBy = new BasicDBObject();
    orderBy.put("startTime", -1);
    dbObjects.sort(orderBy);

    return new AbstractCollection<TrackHistory>() {
        @Override
        public Iterator<TrackHistory> iterator() {
            return new MongoDBHistoryCursor(dbObjects);
        }

        @Override
        public int size() {
            return dbObjects.size();
        }
    };
}

From source file:com.wrmsr.wava.util.collect.MoreMultimaps.java

public static <K, V> Multimap<K, V> unmodifiableMultimapView(Map<K, Collection<V>> collectionMap) {
    // checkArgument(collectionMap.values().stream().allMatch(coll -> !coll.isEmpty()));
    return new Multimap<K, V>() {
        private OptionalInt size = OptionalInt.empty();

        private int cachedSize() {
            if (!size.isPresent()) {
                size = OptionalInt.of(collectionMap.values().stream().mapToInt(coll -> {
                    checkState(!coll.isEmpty());
                    return coll.size();
                }).sum());// w w  w.  ja v a2 s. c om
            }
            return size.getAsInt();
        }

        @Override
        public int size() {
            return cachedSize();
        }

        @Override
        public boolean isEmpty() {
            return !collectionMap.isEmpty();
        }

        @Override
        public boolean containsKey(@Nullable Object key) {
            return collectionMap.containsKey(key);
        }

        @Override
        public boolean containsValue(@Nullable Object value) {
            return collectionMap.values().stream().anyMatch(coll -> coll.contains(value));
        }

        @Override
        public boolean containsEntry(@Nullable Object key, @Nullable Object value) {
            return collectionMap.getOrDefault(key, ImmutableList.of()).contains(value);
        }

        @Override
        public boolean put(@Nullable K key, @Nullable V value) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean remove(@Nullable Object key, @Nullable Object value) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean putAll(@Nullable K key, Iterable<? extends V> values) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Collection<V> replaceValues(@Nullable K key, Iterable<? extends V> values) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Collection<V> removeAll(@Nullable Object key) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void clear() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Collection<V> get(@Nullable K key) {
            return collectionMap.getOrDefault(key, ImmutableList.of());
        }

        @Override
        public Set<K> keySet() {
            return collectionMap.keySet();
        }

        @Override
        public Multiset<K> keys() {
            // FIXME
            throw new UnsupportedOperationException();
        }

        @Override
        public Collection<V> values() {
            return new AbstractCollection<V>() {
                @Override
                public Iterator<V> iterator() {
                    return Iterators.concat(collectionMap.values().stream().map(Iterable::iterator).iterator());
                }

                @Override
                public int size() {
                    return cachedSize();
                }
            };
        }

        @Override
        public Collection<Map.Entry<K, V>> entries() {
            return new AbstractCollection<Map.Entry<K, V>>() {
                @Override
                public Iterator<Map.Entry<K, V>> iterator() {
                    return Iterators.concat(collectionMap.entrySet().stream()
                            .map(entry -> entry.getValue().stream()
                                    .map(value -> ImmutablePair.of(entry.getKey(), value)).iterator())
                            .iterator());
                }

                @Override
                public int size() {
                    return cachedSize();
                }
            };
        }

        @Override
        public Map<K, Collection<V>> asMap() {
            return collectionMap;
        }
    };
}

From source file:com.tussle.script.StackedBindings.java

public Collection<Object> values() {
    if (values == null)
        values = new AbstractCollection<Object>() {
            public Iterator<Object> iterator() {
                return IteratorUtils.transformedIterator(bindingMap.values().iterator(), Deque::peek);
            }/* ww w . ja  v a 2 s  .  c  o m*/

            public int size() {
                return bindingMap.size();
            }
        };
    return values;
}

From source file:com.github.helenusdriver.driver.impl.PersistedMap.java

/**
 * {@inheritDoc}//from   www.j a va 2  s  .com
 *
 * @author paouelle
 *
 * @see java.util.Map#values()
 */
@Override
public Collection<T> values() {
    if (vcol == null) {
        final Collection<PersistedValue<T, PT>> vcol = map.values();

        this.vcol = new AbstractCollection<T>() {
            @Override
            public int size() {
                return vcol.size();
            }

            @Override
            public boolean isEmpty() {
                return vcol.isEmpty();
            }

            @Override
            public Iterator<T> iterator() {
                return new TransformIterator<PersistedValue<T, PT>, T>(vcol.iterator()) {
                    @Override
                    protected T transform(PersistedValue<T, PT> pv) {
                        return pv.getDecodedValue();
                    }
                };
            }

            @Override
            public Stream<T> stream() {
                return vcol.stream().map(pv -> pv.getDecodedValue());
            }

            @Override
            public Stream<T> parallelStream() {
                return vcol.parallelStream().map(pv -> pv.getDecodedValue());
            }

            @Override
            public void clear() {
                vcol.clear();
            }

            @Override
            public String toString() {
                return vcol.toString();
            }
        };
    }
    return vcol;
}

From source file:Cache.java

public synchronized Collection<V> values() {
    // First, clear all entries that have been in cache longer than the
    // maximum defined age.
    deleteExpiredEntries();// ww  w.  ja  v a 2s  .c  om

    return Collections.unmodifiableCollection(new AbstractCollection<V>() {
        Collection<CacheObject<V>> values = map.values();

        public Iterator<V> iterator() {
            return new Iterator<V>() {
                Iterator<CacheObject<V>> it = values.iterator();

                public boolean hasNext() {
                    return it.hasNext();
                }

                public V next() {
                    return it.next().object;
                }

                public void remove() {
                    it.remove();
                }
            };
        }

        public int size() {
            return values.size();
        }
    });
}

From source file:WeakValueHashMap.java

/**
 * Returns a <code>Collection</code> view of the values contained
 * in this map.<p>// w  ww  .  j ava 2  s .c om
 * @return a <code>Collection</code> view of the values contained
 * in this map.
 */
public Collection values() {
    // delegates to entrySet, because super method returns
    // WeakValues instead of value objects
    if (values == null) {
        values = new AbstractCollection() {
            public Iterator iterator() {
                return new Iterator() {
                    private Iterator i = entrySet().iterator();

                    public boolean hasNext() {
                        return i.hasNext();
                    }

                    public Object next() {
                        return ((Entry) i.next()).getValue();
                    }

                    public void remove() {
                        i.remove();
                    }
                };
            }

            public int size() {
                return WeakValueHashMap.this.size();
            }

            public boolean contains(Object v) {
                return WeakValueHashMap.this.containsValue(v);
            }
        };
    }
    return values;
}

From source file:IntHashMap.java

/**
 * Returns a collection view of the values contained in this map.  The
 * collection is backed by the map, so changes to the map are reflected in
 * the collection, and vice-versa.  The collection supports element
 * removal, which removes the corresponding mapping from this map, via the
 * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
 * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
 * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
 *
 * @return a collection view of the values contained in this map.
 *///from  w  w  w .ja  v a2 s . c  o m
public Collection<V> values() {
    if (values == null) {
        values = new AbstractCollection<V>() {
            public Iterator iterator() {
                return (Iterator) new IntHashIterator(VALUES);
            }

            public int size() {
                return count;
            }

            public boolean contains(Object o) {
                return containsValue(o);
            }

            public void clear() {
                IntHashMap.this.clear();
            }
        };
    }
    return values;
}

From source file:WeakIdentityMap.java

public Collection<V> values() {
    if (this.values == null) {
        this.values = new AbstractCollection<V>() {
            public Iterator<V> iterator() {
                return createHashIterator(VALUES);
            }//from   ww w. j  a  v  a2 s  .com

            public int size() {
                return WeakIdentityMap.this.count;
            }

            public boolean contains(Object o) {
                return containsValue(o);
            }

            public void clear() {
                WeakIdentityMap.this.clear();
            }

            public String toString() {
                return WeakIdentityMap.this.toString(this);
            }
        };
    }
    return this.values;
}

From source file:IntHashMap.java

/**
 * Returns a collection view of the values contained in this map. The
 * collection is backed by the map, so changes to the map are reflected in
 * the collection, and vice-versa. The collection supports element removal,
 * which removes the corresponding mapping from this map, via the
 * <code>Iterator.remove</code>, <code>Collection.remove</code>,
 * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code>
 * operations. It does not support the <code>add</code> or
 * <code>addAll</code> operations.
 *
 * @return a collection view of the values contained in this map.
 *//*from   w  w w .  j  av  a2s . c  o  m*/
@Override
public Collection values() {
    if (values == null) {
        values = new AbstractCollection() {
            @Override
            public Iterator iterator() {
                return new IntHashIterator(VALUES);
            }

            @Override
            public int size() {
                return count;
            }

            @Override
            public boolean contains(Object o) {
                return containsValue(o);
            }

            @Override
            public void clear() {
                IntHashMap.this.clear();
            }
        };
    }
    return values;
}

From source file:IdentityHashMap.java

/**
 * Returns a collection view of the values contained in this map.  The
 * collection is backed by the map, so changes to the map are reflected in
 * the collection, and vice-versa.  The collection supports element
 * removal, which removes the corresponding mapping from this map, via the
 * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
 * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
 * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
 *
 * @return a collection view of the values contained in this map.
 *///  w  w w.  ja va 2s.  co m
public Collection values() {
    if (values == null) {
        values = new AbstractCollection() {
            public Iterator iterator() {
                return getHashIterator(VALUES);
            }

            public int size() {
                return count;
            }

            public boolean contains(Object o) {
                return containsValue(o);
            }

            public void clear() {
                IdentityHashMap.this.clear();
            }
        };
    }
    return values;
}