01: // kelondroRotateIterator.java
02: // (C) 2007 by Michael Peter Christen; mc@anomic.de, Frankfurt a. M., Germany
03: // first published 08.03.2007 on http://www.anomic.de
04: //
05: // This is a part of YaCy, a peer-to-peer based web search engine
06: //
07: // $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
08: // $LastChangedRevision: 1986 $
09: // $LastChangedBy: orbiter $
10: //
11: // LICENSE
12: //
13: // This program is free software; you can redistribute it and/or modify
14: // it under the terms of the GNU General Public License as published by
15: // the Free Software Foundation; either version 2 of the License, or
16: // (at your option) any later version.
17: //
18: // This program is distributed in the hope that it will be useful,
19: // but WITHOUT ANY WARRANTY; without even the implied warranty of
20: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: // GNU General Public License for more details.
22: //
23: // You should have received a copy of the GNU General Public License
24: // along with this program; if not, write to the Free Software
25: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26:
27: package de.anomic.kelondro;
28:
29: public class kelondroRotateIterator<E> implements
30: kelondroCloneableIterator<E> {
31:
32: kelondroCloneableIterator<E> a, clone;
33: Object modifier;
34: boolean nempty;
35: int terminationCount;
36:
37: public kelondroRotateIterator(kelondroCloneableIterator<E> a,
38: Object modifier, int terminationCount) {
39: // this works currently only for String-type key iterations
40: this .a = a;
41: this .modifier = modifier;
42: this .terminationCount = terminationCount;
43: this .clone = (kelondroCloneableIterator<E>) a.clone(modifier);
44: this .nempty = this .clone.hasNext();
45: }
46:
47: public kelondroRotateIterator<E> clone(Object modifier) {
48: return new kelondroRotateIterator<E>(a, modifier,
49: terminationCount - 1);
50: }
51:
52: public boolean hasNext() {
53: return (terminationCount > 0) && (this .nempty);
54: }
55:
56: public E next() {
57: // attention: this iterator has no termination - on purpose.
58: // it must be taken care that a calling method has a termination predicate different
59: // from the hasNext() method
60: if (!(a.hasNext())) {
61: a = (kelondroCloneableIterator<E>) clone.clone(modifier);
62: assert a.hasNext();
63: }
64: terminationCount--;
65: return a.next();
66: }
67:
68: public void remove() {
69: a.remove();
70: }
71:
72: }
|