001/*
002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
003 * 
004 * This software is open source. 
005 * See the bottom of this file for the licence.
006 * 
007 * $Id: SingleIterator.java,v 1.3 2001/07/03 10:14:06 jstrachan Exp $
008 */
009
010package org.dom4j.tree;
011
012import java.util.Iterator;
013
014import org.dom4j.Element;
015
016/** <p><code>SingleIterator</code> is an {@link Iterator} over a single 
017  * object instance.</p>
018  *
019  * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
020  * @version $Revision: 1.3 $
021  */
022public class SingleIterator implements Iterator {
023
024    private boolean first = true;
025    private Object object;
026    
027    public SingleIterator(Object object) {
028        this.object = object;
029    }
030
031    public boolean hasNext() {
032        return first;
033    }
034
035    public Object next() {
036        Object answer = object;
037        object = null;
038        first = false;
039        return answer;
040    }
041
042    public void remove() {
043        throw new UnsupportedOperationException( "remove() is not supported by this iterator" );
044    }
045
046}
047
048
049
050
051/*
052 * Redistribution and use of this software and associated documentation
053 * ("Software"), with or without modification, are permitted provided
054 * that the following conditions are met:
055 *
056 * 1. Redistributions of source code must retain copyright
057 *    statements and notices.  Redistributions must also contain a
058 *    copy of this document.
059 *
060 * 2. Redistributions in binary form must reproduce the
061 *    above copyright notice, this list of conditions and the
062 *    following disclaimer in the documentation and/or other
063 *    materials provided with the distribution.
064 *
065 * 3. The name "DOM4J" must not be used to endorse or promote
066 *    products derived from this Software without prior written
067 *    permission of MetaStuff, Ltd.  For written permission,
068 *    please contact dom4j-info@metastuff.com.
069 *
070 * 4. Products derived from this Software may not be called "DOM4J"
071 *    nor may "DOM4J" appear in their names without prior written
072 *    permission of MetaStuff, Ltd. DOM4J is a registered
073 *    trademark of MetaStuff, Ltd.
074 *
075 * 5. Due credit should be given to the DOM4J Project
076 *    (http://dom4j.org/).
077 *
078 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
079 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
080 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
081 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
082 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
083 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
084 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
085 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
086 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
087 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
088 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
089 * OF THE POSSIBILITY OF SUCH DAMAGE.
090 *
091 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
092 *
093 * $Id: SingleIterator.java,v 1.3 2001/07/03 10:14:06 jstrachan Exp $
094 */