View Javadoc

1   /*
2    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3    * 
4    * This software is open source. 
5    * See the bottom of this file for the licence.
6    * 
7    * $Id: SingleIterator.java,v 1.7 2004/06/25 08:03:41 maartenc Exp $
8    */
9   
10  package org.dom4j.tree;
11  
12  import java.util.Iterator;
13  
14  /*** <p><code>SingleIterator</code> is an {@link Iterator} over a single 
15    * object instance.</p>
16    *
17    * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
18    * @version $Revision: 1.7 $
19    */
20  public class SingleIterator implements Iterator {
21  
22      private boolean first = true;
23      private Object object;
24      
25      public SingleIterator(Object object) {
26          this.object = object;
27      }
28  
29      public boolean hasNext() {
30          return first;
31      }
32  
33      public Object next() {
34          Object answer = object;
35          object = null;
36          first = false;
37          return answer;
38      }
39  
40      public void remove() {
41          throw new UnsupportedOperationException( "remove() is not supported by this iterator" );
42      }
43  
44  }
45  
46  
47  
48  
49  /*
50   * Redistribution and use of this software and associated documentation
51   * ("Software"), with or without modification, are permitted provided
52   * that the following conditions are met:
53   *
54   * 1. Redistributions of source code must retain copyright
55   *    statements and notices.  Redistributions must also contain a
56   *    copy of this document.
57   *
58   * 2. Redistributions in binary form must reproduce the
59   *    above copyright notice, this list of conditions and the
60   *    following disclaimer in the documentation and/or other
61   *    materials provided with the distribution.
62   *
63   * 3. The name "DOM4J" must not be used to endorse or promote
64   *    products derived from this Software without prior written
65   *    permission of MetaStuff, Ltd.  For written permission,
66   *    please contact dom4j-info@metastuff.com.
67   *
68   * 4. Products derived from this Software may not be called "DOM4J"
69   *    nor may "DOM4J" appear in their names without prior written
70   *    permission of MetaStuff, Ltd. DOM4J is a registered
71   *    trademark of MetaStuff, Ltd.
72   *
73   * 5. Due credit should be given to the DOM4J Project - 
74   *    http://www.dom4j.org
75   *
76   * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
77   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
78   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
79   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
80   * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
81   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
82   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
83   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
85   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
86   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
87   * OF THE POSSIBILITY OF SUCH DAMAGE.
88   *
89   * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
90   *
91   * $Id: SingleIterator.java,v 1.7 2004/06/25 08:03:41 maartenc Exp $
92   */