Copyright© 2008-2022 Sitevision AB, all rights reserved.
public interface ExceptionSuppressingIterator extends Iterator<ExceptionSuppressingProxy>
ExceptionSuppressingProxy
s in order to ensure that no
invocation will throw an exception.
This iterator is of type ExceptionSuppressingProxy
that is an implementation of a Dynamic proxy so not all
methods can be directly invoked on objects retrieved by the next
method. See ExceptionSuppressingCollection
for an example of how this iterator can be used easily from Velocity and how to invoke methods not declared in an interface.
See ExceptionSuppressingProxy
for more information about dynamic proxies.
Important note! This interface is intended to be used only in contexts where exceptions thrown during iteration will cause serious trouble if they arise and the context doesn't provide proper exception handling (e.g. when executing a Velocity template). Suppressing exceptions is generally a bad idea and using this iterator will affect performance. Hence, this interface should only be used where the upsides with suppressing exceptions far outweighs the downsides. This interface should be used only as a temporary patch/solution until the "real" problem causing the exception has been solved.
An instance of the Sitevision class implementing this interface can be obtained directly via
Utils.getExceptionSuppressingIterator(java.util.Iterator)
or indirectly via Utils.getExceptionSuppressingCollection(java.util.Collection)
.
You would typically use the latter if you should iterate a collection with the Velocity #foreach loop.
See Utils
for how to obtain an instance of the Utils
interface.
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Returns
true if decorated iterator has more elements. |
ExceptionSuppressingProxy |
next()
Returns a proxy for the next element of the decorated iterator.
|
void |
remove()
Tries to remove from the underlying collection the last element returned by decorated iterator (optional operation).
|
forEachRemaining
boolean hasNext()
true
if decorated iterator has more elements. (In other words, returns true
if next
would return an element rather than throwing an exception.)
This method will never throw an exception
hasNext
in interface Iterator<ExceptionSuppressingProxy>
true
if the decorated iterator has more elements, false
if not or if an exception is thrown
by the decorated iteratorExceptionSuppressingProxy next()
hasNext()
method
returns false
will return each element in the underlying collection exactly once.
Note! The returned element will be embedded in an ExceptionSuppressingProxy
that will be reused for
all next() invocations on this iterator. In other words, the proxied item of the returned element will change,
but never the returned element itself. This implies that you shouldn't keep references to an item retrieved from a next()
invocation during iteration. If you do, don't be surprised if the element contains something else than it did when you set the reference...
This method will never throw an exception.
Note! Be aware of null
items since they're never proxied. If the underlying collection contains a
null
item, this iterator will just return null
, not a proxy. In other words: even though this method
won't throw any exceptions, invoking a method on the returned object might throw a NullPointerException
.
next
in interface Iterator<ExceptionSuppressingProxy>
null
if an exception is thrown.void remove()
next
. The behavior of an iterator is unspecified if
the underlying collection is modified while the iteration is in progress in any way other than by calling this method.
This method will never throw an exception.
Note! Since exceptions are suppressed, you can never tell if the remove operation actually succeeded
or if the underlying collection doesn't support removal (i.e. UnsupportedOperationException
thrown by the
decorated iterator is catched by this iterator).
remove
in interface Iterator<ExceptionSuppressingProxy>
Sitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2022 Sitevision AB, all rights reserved.