List of usage examples for java.util AbstractCollection AbstractCollection
protected AbstractCollection()
From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java
protected <T> Collection<T> getDimension(final Collection<DimensionBean> beans, final DimBeanExec<T> ctr) { return new AbstractCollection<T>() { @Override//from w w w . j av a 2s . co m public Iterator<T> iterator() { return new Iterator<T>() { private Iterator<DimensionBean> beanIt = beans.iterator(); @Override public boolean hasNext() { return beanIt.hasNext(); } @Override public T next() { return ctr.exec(beanIt.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } @Override public int size() { return beans.size(); } }; }
From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java
protected <T> Collection<T> getAccumulation(final Collection<DimensionBean> beans, final DimBeanExec<T> ctr) { return new AbstractCollection<T>() { @Override/*from w ww . ja va 2s .co m*/ public Iterator<T> iterator() { return new Iterator<T>() { private Iterator<DimensionBean> beanIt = beans.iterator(); @Override public boolean hasNext() { return beanIt.hasNext(); } @Override public T next() { return ctr.exec(beanIt.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } @Override public int size() { return beans.size(); } }; }
From source file:SequencedHashMap.java
/** * Implements {@link Map#values()}.// w w w . j a v a 2 s . co m */ public Collection values() { return new AbstractCollection() { // required impl public Iterator iterator() { return new OrderedIterator(VALUE); } public boolean remove(Object value) { // do null comparison outside loop so we only need to do it once. This // provides a tighter, more efficient loop at the expense of slight // code duplication. if (value == null) { for (Entry pos = sentinel.next; pos != sentinel; pos = pos.next) { if (pos.getValue() == null) { SequencedHashMap.this.removeImpl(pos.getKey()); return true; } } } else { for (Entry pos = sentinel.next; pos != sentinel; pos = pos.next) { if (value.equals(pos.getValue())) { SequencedHashMap.this.removeImpl(pos.getKey()); return true; } } } return false; } // more efficient impls than abstract collection public void clear() { SequencedHashMap.this.clear(); } public int size() { return SequencedHashMap.this.size(); } public boolean isEmpty() { return SequencedHashMap.this.isEmpty(); } public boolean contains(Object o) { return SequencedHashMap.this.containsValue(o); } }; }
From source file:com.baobao.utils.cache.SequencedHashMap.java
/** * Implements {@link Map#values()}./*from w w w . ja v a 2 s .c o m*/ */ public Collection values() { return new AbstractCollection() { // required impl public Iterator iterator() { return new OrderedIterator(VALUE); } public boolean remove(Object value) { // do null comparison outside loop so we only need to do it once. This // provides a tighter, more efficient loop at the expense of slight // code duplication. if (value == null) { for (Entry pos = sentinel.next; pos != sentinel; pos = pos.next) { if (pos.getValue() == null) { SequencedHashMap.this.removeImpl(pos.getKey()); return true; } } } else { for (Entry pos = sentinel.next; pos != sentinel; pos = pos.next) { if (value.equals(pos.getValue())) { SequencedHashMap.this.removeImpl(pos.getKey()); return true; } } } return false; } // more efficient impls than abstract collection public void clear() { SequencedHashMap.this.clear(); } public int size() { return SequencedHashMap.this.size(); } public boolean isEmpty() { return SequencedHashMap.this.isEmpty(); } public boolean contains(Object o) { return SequencedHashMap.this.containsValue(o); } }; }
From source file:SoftValuedHashMap.java
public Collection<V> values() { if (this.values == null) { this.values = new AbstractCollection<V>() { public Iterator iterator() { return createHashIterator(WeakIdentityMap.VALUES); }//w ww . java2 s . c o m public int size() { return ReferencedValueHashMap.this.count; } public boolean contains(Object o) { return containsValue(o); } public void clear() { ReferencedValueHashMap.this.clear(); } public String toString() { return WeakIdentityMap.toString(this); } }; } return this.values; }
From source file:com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.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 ww w. ja v a 2 s. com*/ public Collection values() { Collection vs = values; if (vs != null) { return vs; } else { return values = new AbstractCollection() { public Iterator iterator() { return new ValueIterator(); } public int size() { return AbstractConcurrentReadCache.this.size(); } public boolean contains(Object o) { return AbstractConcurrentReadCache.this.containsValue(o); } public void clear() { AbstractConcurrentReadCache.this.clear(); } }; } }
From source file:hudson.model.Fingerprint.java
/** * Gets the associated {@link FingerprintFacet}s. * * <p>/* w ww .j a va2 s.c om*/ * This method always return a non-empty collection, which is a synthetic collection. * It contains persisted {@link FingerprintFacet}s (those that are added explicitly, like * {@code fingerprint.getFacets().add(x)}), as well those {@linkplain TransientFingerprintFacetFactory that are transient}. * * <p> * Mutation to this collection will manipulate persisted set of {@link FingerprintFacet}s, and therefore regardless * of what you do, this collection will always contain a set of {@link FingerprintFacet}s that are added * by {@link TransientFingerprintFacetFactory}s. * * @since 1.421 */ public @Nonnull Collection<FingerprintFacet> getFacets() { if (transientFacets == null) { List<FingerprintFacet> transientFacets = new ArrayList<FingerprintFacet>(); for (TransientFingerprintFacetFactory fff : TransientFingerprintFacetFactory.all()) { fff.createFor(this, transientFacets); } this.transientFacets = ImmutableList.copyOf(transientFacets); } return new AbstractCollection<FingerprintFacet>() { @Override public Iterator<FingerprintFacet> iterator() { return Iterators.sequence(facets.iterator(), transientFacets.iterator()); } @Override public boolean add(FingerprintFacet e) { facets.add(e); return true; } @Override public boolean remove(Object o) { return facets.remove(o); } @Override public boolean contains(Object o) { return facets.contains(o) || transientFacets.contains(o); } @Override public int size() { return facets.size() + transientFacets.size(); } }; }
From source file:org.apache.ojb.broker.util.ReferenceMap.java
/** * Returns a collection view of this map's values. * * @return a collection view of this map's values. *//*from ww w . j a v a 2s . c om*/ public Collection values() { if (values != null) return values; values = new AbstractCollection() { public int size() { return size; } public void clear() { ReferenceMap.this.clear(); } public Iterator iterator() { return new ValueIterator(); } }; return values; }
From source file:org.apache.openjpa.util.AbstractLRSProxyMap.java
public Collection<V> values() { return new AbstractCollection<V>() { public int size() { return AbstractLRSProxyMap.this.size(); }/*w ww . j ava 2 s .c o m*/ public Iterator<V> iterator() { return AbstractLRSProxyMap.this.iterator(MODE_VALUE); } }; }
From source file:org.briljantframework.data.vector.Vectors.java
/** * <p>// www .j a v a2s.com * Split {@code vector} into {@code chunks}. Handles the case when {@code vector.size()} is not * evenly dividable by chunks by making some chunks larger. * </p> * * <p> * This implementation is lazy, i.e. chunking is done 'on-the-fly'. To get a list, {@code new * ArrayList<>(Vectors.split(vec, 10))} * </p> * * <p> * Ensures that {@code vector.getType()} is preserved. * </p> * * @param vector the vector * @param chunks the number of chunks * @return a collection of {@code chunk} chunks */ public static Collection<Vector> split(Vector vector, int chunks) { Check.argument(vector.size() >= chunks, "size must be shorter than chunks"); if (vector.size() == chunks) { return Collections.singleton(vector); } int bin = vector.size() / chunks; int remainder = vector.size() % chunks; return new AbstractCollection<Vector>() { @Override public Iterator<Vector> iterator() { return new Iterator<Vector>() { private int current = 0; private int remainders = 0; @Override public boolean hasNext() { return current < vector.size(); } @Override public Vector next() { int binSize = bin; if (remainders < remainder) { remainders++; binSize += 1; } Vector.Builder builder = vector.newBuilder(); for (int i = 0; i < binSize; i++) { builder.add(vector, current++); } return builder.build(); } }; } @Override public int size() { return chunks; } }; }