You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yacy_search_server/source/de/anomic/kelondro/kelondroCloneableSetIterato...

79 lines
2.2 KiB

// 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);
}
}