1 /*
2 ORDI - Ontology Repository and Data Integration
3
4 Copyright (c) 2004-2007, OntoText Lab. / SIRMA
5
6 This library is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the Free
8 Software Foundation; either version 2.1 of the License, or (at your option)
9 any later version.
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 details.
14 You should have received a copy of the GNU Lesser General Public License along
15 with this library; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 package com.ontotext.ordi.iterator;
19
20 import java.util.Iterator;
21 import java.util.NoSuchElementException;
22
23 public class CloseableIteratorImpl<E> implements CloseableIterator<E> {
24
25 private boolean isClosed = false;
26 private Iterator<E> iter;
27
28 public CloseableIteratorImpl(Iterator<E> iter) {
29 if (iter == null) {
30 throw new IllegalArgumentException();
31 }
32 this.iter = iter;
33 }
34
35 public void close() {
36 isClosed = true;
37 iter = null;
38 }
39
40 public boolean hasNext() {
41 return !isClosed && iter != null && iter.hasNext();
42 }
43
44 public E next() {
45 if (!isClosed)
46 throw new NoSuchElementException("Iterator is closed!");
47 return iter.next();
48 }
49
50 public void remove() {
51 if (!isClosed)
52 throw new NoSuchElementException("Iterator is closed!");
53 iter.remove();
54 }
55
56 }