private Iterable<Metric> _getMetrics( E environment, String name, Interval interval ) { log.debug( "Performing fetch for metric " + name + " for " + interval.toString() ); Optional<List<Metric>> metricsFromCache = environment.metricCache().getValues( name, interval ); if( metricsFromCache.isPresent() ) { if( !metricsFromCache.get().isEmpty() && metricsFromCache.get().get( 0 ).timestamp() <= interval.start() ) { log.debug( "Got all results we want from cache." ); return metricsFromCache.get(); } else { log.debug( "Got some results from cache, but need to get the rest from the database" ); long refetchEnd = metricsFromCache.get().isEmpty() ? interval.end() : metricsFromCache.get().get( 0 ).timestamp(); return new IteratorIterable<>( new IteratorChain<>( environment.cassandraAccessLayer().loadMetrics( name, new Interval( interval.start(), refetchEnd ) ).iterator(), metricsFromCache.get().iterator() ) ); } } else { log.debug( "Got no results from cache, need to hit the database." ); return environment.cassandraAccessLayer().loadMetrics( name, interval ); } }
@Override public Iterator<V> iterator() { final IteratorChain<V> chain = new IteratorChain<V>(); for (final K k : keySet()) { chain.addIterator(new ValuesIterator(k)); } return chain; }
/** * Gets an iterator over all the sets in this composite. * <p> * This implementation uses an <code>IteratorChain</code>. * * @return an <code>IteratorChain</code> instance which supports * <code>remove()</code>. Iteration occurs over contained collections in * the order they were added, but this behavior should not be relied upon. * @see IteratorChain */ public Iterator<E> iterator() { if (all.isEmpty()) { return EmptyIterator.<E>emptyIterator(); } final IteratorChain<E> chain = new IteratorChain<E>(); for (final Set<E> item : all) { chain.addIterator(item.iterator()); } return chain; }
/** * Gets an iterator over all the collections in this composite. * <p> * This implementation uses an <code>IteratorChain</code>. * * @return an <code>IteratorChain</code> instance which supports * <code>remove()</code>. Iteration occurs over contained collections in * the order they were added, but this behavior should not be relied upon. * @see IteratorChain */ @Override public Iterator<E> iterator() { if (all.isEmpty()) { return EmptyIterator.<E>emptyIterator(); } final IteratorChain<E> chain = new IteratorChain<E>(); for (final Collection<E> item : all) { chain.addIterator(item.iterator()); } return chain; }
/** * @inheritDoc */ public Enumeration getAttributeNames() { Set<String> nonPortableAttributeNames = m_nonPortalSession.getAllAttributes().keySet(); IteratorChain ic = new IteratorChain(m_attributes.keySet().iterator(),nonPortableAttributeNames.iterator()); return new IteratorEnumeration(ic); }
/** * Enumerates all types by prepending "pub" and "dyn" to the security * domain. Thus, this method only works if the security domain is also * enumerable. */ public Iterator<TypeView<Level>> enumerate() { final TypeDomain<Level> self = this; Iterator<TypeView<Level>> secLevels = new TransformIterator<>(this.secDomain.enumerate(), new Transformer<Level, TypeView<Level>>() { @Override public TypeView<Level> transform(Level level) { return self.level(level); } }); return new IteratorChain<>(Arrays.asList(this.pub(), this.dyn()).iterator(), secLevels); }
/** * @inheritDoc */ public Enumeration getAttributeNames() { IteratorChain ic = new IteratorChain(m_attributes.keySet().iterator(),m_nonPortalSession.getAllAttributes().keySet().iterator()); return new IteratorEnumeration(ic); }
@Override public Iterator<E> iterator() { return UnmodifiableIterator.decorate(new IteratorChain(Arrays.asList(used.iterator(),unused.iterator()))); }
/** * Gets an iterator that iterates through two {@link Iterator}s * one after another. * * @param <E> the element type * @param iterator1 the first iterator to use, not null * @param iterator2 the second iterator to use, not null * @return a combination iterator over the iterators * @throws NullPointerException if either iterator is null */ public static <E> Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { // keep a version with two iterators to avoid the following warning in client code (Java 5 & 6) // "A generic array of E is created for a varargs parameter" return new IteratorChain<E>(iterator1, iterator2); }
/** * Gets an iterator that iterates through an array of {@link Iterator}s * one after another. * * @param <E> the element type * @param iterators the iterators to use, not null or empty or contain nulls * @return a combination iterator over the iterators * @throws NullPointerException if iterators array is null or contains a null */ public static <E> Iterator<E> chainedIterator(final Iterator<? extends E>... iterators) { return new IteratorChain<E>(iterators); }
/** * Gets an iterator that iterates through a collections of {@link Iterator}s * one after another. * * @param <E> the element type * @param iterators the iterators to use, not null or empty or contain nulls * @return a combination iterator over the iterators * @throws NullPointerException if iterators collection is null or contains a null * @throws ClassCastException if the iterators collection contains the wrong object type */ public static <E> Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators) { return new IteratorChain<E>(iterators); }