FileDocCategorySizeDatePackage
FailFast.javaAPI DocApache Ant 1.703786Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.types.resources

FailFast

public class FailFast extends Object implements Iterator
Helper class for ResourceCollections to return Iterators that fail on changes to the object.
since
Ant 1.7

Fields Summary
private static final WeakHashMap
MAP
private Object
parent
private Iterator
wrapped
Constructors Summary
FailFast(Object o, Iterator i)
Construct a new FailFast Iterator wrapping the specified Iterator and dependent upon the specified parent Object.

param
o the parent Object.
param
i the wrapped Iterator.

        if (o == null) {
            throw new IllegalArgumentException("parent object is null");
        }
        if (i == null) {
            throw new IllegalArgumentException("cannot wrap null iterator");
        }
        parent = o;
        if (i.hasNext()) {
            wrapped = i;
            add(this);
        }
    
Methods Summary
private static synchronized voidadd(org.apache.tools.ant.types.resources.FailFast f)

        Set s = (Set) (MAP.get(f.parent));
        if (s == null) {
            s = new HashSet();
            MAP.put(f.parent, s);
        }
        s.add(f);
    
private static synchronized voidfailFast(org.apache.tools.ant.types.resources.FailFast f)

        Set s = (Set) (MAP.get(f.parent));
        if (!s.contains(f)) {
            throw new ConcurrentModificationException();
        }
    
public booleanhasNext()
Fulfill the Iterator contract.

return
true if there are more elements.

        if (wrapped == null) {
            return false;
        }
        failFast(this);
        return wrapped.hasNext();
    
static synchronized voidinvalidate(java.lang.Object o)
Invalidate any in-use Iterators from the specified Object.

param
o the parent Object.


                      
         
        Set s = (Set) (MAP.get(o));
        if (s != null) {
            s.clear();
        }
    
public java.lang.Objectnext()
Fulfill the Iterator contract.

return
the next element.
throws
NoSuchElementException if no more elements.

        if (wrapped == null || !wrapped.hasNext()) {
            throw new NoSuchElementException();
        }
        failFast(this);
        try {
            return wrapped.next();
        } finally {
            if (!wrapped.hasNext()) {
                wrapped = null;
                remove(this);
            }
        }
    
private static synchronized voidremove(org.apache.tools.ant.types.resources.FailFast f)

        Set s = (Set) (MAP.get(f.parent));
        if (s != null) {
            s.remove(f);
        }
    
public voidremove()
Fulfill the Iterator contract.

throws
UnsupportedOperationException always.

        throw new UnsupportedOperationException();