@Override protected int getSize() { // to compute the size, just iterate: the iterator will take care of // caching final Iterator<Resource> it = createIterator(); int size = 0; while (it.hasNext()) { it.next(); size++; } return size; }
@Override public boolean hasNext() { if (ended) { return false; } while (next == null) { if (!it.hasNext()) { ended = true; return false; } next = it.next(); if (filterResource(next)) { next = null; } } return true; }
/** * Learn whether to cache collections. Default is <code>true</code>. * @return boolean cache flag. */ public synchronized boolean isCache() { return w.isCache(); }
/** * Set whether to cache collections. * @param b boolean cache flag. */ public synchronized void setCache(boolean b) { w.setCache(b); }
/** * Add the ResourceCollection. * @param c the ResourceCollection to add. */ public synchronized void add(ResourceCollection c) { if (isReference()) { throw noChildrenAllowed(); } if (c == null) { return; } w.add(c); setChecked(false); }
/** * Fulfill the ResourceCollection contract. * @return whether this is a filesystem-only resource collection. */ @Override public synchronized boolean isFilesystemOnly() { if (isReference()) { return getCheckedRef().isFilesystemOnly(); } dieOnCircularReference(); return w.isFilesystemOnly(); }
/** * Fulfill the ResourceCollection contract. * @return an Iterator of Resources. */ @Override public final synchronized Iterator<Resource> iterator() { if (isReference()) { return getCheckedRef().iterator(); } dieOnCircularReference(); return w.iterator(); }
/** * Format this Restrict collection as a String. * @return the String value of this collection. */ @Override public synchronized String toString() { if (isReference()) { return getCheckedRef().toString(); } dieOnCircularReference(); return w.toString(); }
/** * Fulfill the ResourceCollection contract. * @return number of elements as int. */ @Override public synchronized int size() { if (isReference()) { return getCheckedRef().size(); } dieOnCircularReference(); return w.size(); }
@Override protected Iterator<Resource> createIterator() { if (isCache()) { if (filteringIterator == null) { // no worry of thread safety here, see function's contract filteringIterator = filteringIteratorSupplier.get(); } return new CachedIterator(filteringIterator); } return filteringIteratorSupplier.get(); }