1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }