diff --git a/source/de/anomic/kelondro/kelondroCloneableSetIterator.java b/source/de/anomic/kelondro/kelondroCloneableSetIterator.java new file mode 100644 index 000000000..4dc0094a7 --- /dev/null +++ b/source/de/anomic/kelondro/kelondroCloneableSetIterator.java @@ -0,0 +1,78 @@ +// kelondroCloneableSetIterator.java +// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany +// first published 25.04.2007 on http://yacy.net +// +// This is a part of YaCy, a peer-to-peer based web search engine +// +// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $ +// $LastChangedRevision: 1986 $ +// $LastChangedBy: orbiter $ +// +// LICENSE +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +package de.anomic.kelondro; + +import java.util.Iterator; +import java.util.TreeSet; + +public class kelondroCloneableSetIterator implements kelondroCloneableIterator { + + TreeSet set; + Object next, last; + Object start; + Iterator iter; + + + public kelondroCloneableSetIterator(TreeSet set, Object start) { + // set must contain byte[] elements or String elements. + // start must be either of type byte[] or String + this.set = set; + this.start = start; + this.iter = set.iterator(); + if (this.start == null) { + if (iter.hasNext()) this.next = iter.next(); else this.next = null; + } else while (iter.hasNext()) { + this.next = iter.next(); + if (set.comparator().compare(next, start) > 1) break; + } + this.last = null; + } + + public Object clone(Object modifier) { + return new kelondroCloneableSetIterator(set, modifier); + } + + public boolean hasNext() { + return this.next != null; + } + + public Object next() { + this.last = this.next; + if (this.iter.hasNext()) { + this.next = this.iter.next(); + } else { + this.next = null; + } + return this.last; + } + + public void remove() { + this.set.remove(this.last); + } + +}