parent
136b514f52
commit
c04bfaa51b
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* ByteOrder
|
||||
* (C) 2008 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* first published 10.01.2008 on http://yacy.net
|
||||
*
|
||||
* $LastChangedDate$
|
||||
* $LastChangedRevision$
|
||||
* $LastChangedBy$
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.order;
|
||||
|
||||
|
||||
public interface ByteOrder extends Order<byte[]> {
|
||||
|
||||
@Override
|
||||
public boolean wellformed(byte[] a);
|
||||
|
||||
public boolean wellformed(byte[] a, int start, int len);
|
||||
|
||||
@Override
|
||||
public int compare(byte[] a, byte[] b);
|
||||
|
||||
public int compare(byte[] a, byte[] b, int len);
|
||||
|
||||
public int compare(byte[] a, int astart, byte[] b, int bstart, int len);
|
||||
|
||||
@Override
|
||||
public boolean equal(final byte[] a, final byte[] b);
|
||||
|
||||
public boolean equal(final byte[] a, int astart, final byte[] b, int bstart, int length);
|
||||
|
||||
public long cardinal(final byte[] a, int off, int len);
|
||||
|
||||
public byte[] smallest(byte[] a, byte[] b);
|
||||
|
||||
public byte[] largest(byte[] a, byte[] b);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* ByteOrder
|
||||
* (C) 2008 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* first published 10.01.2008 on http://yacy.net
|
||||
*
|
||||
* $LastChangedDate$
|
||||
* $LastChangedRevision$
|
||||
* $LastChangedBy$
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.order;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface CloneableIterator<E> extends Iterator<E> {
|
||||
|
||||
// clone the iterator using a modifier
|
||||
// the modifier can be i.e. a re-start position
|
||||
public CloneableIterator<E> clone(Object modifier);
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* ByteOrder
|
||||
* (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* first published 25.04.2007 on http://yacy.net
|
||||
*
|
||||
* $LastChangedDate$
|
||||
* $LastChangedRevision$
|
||||
* $LastChangedBy$
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.order;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
|
||||
public class CloneableMapIterator<E> implements CloneableIterator<E> {
|
||||
|
||||
TreeMap<E, ?> map;
|
||||
E next, last;
|
||||
Object start;
|
||||
Iterator<E> iter;
|
||||
|
||||
|
||||
public CloneableMapIterator(final TreeMap<E, ?> map, final E start) {
|
||||
// map must contain eiter a byte[]/Object or a String/Object mapping.
|
||||
// start must be either of type byte[] or String
|
||||
// this iterator iterates then only the key elements of the map
|
||||
this.map = map;
|
||||
this.start = start;
|
||||
this.iter = map.keySet().iterator();
|
||||
if (this.start == null) {
|
||||
if (this.iter.hasNext()) this.next = this.iter.next(); else this.next = null;
|
||||
} else while (this.iter.hasNext()) {
|
||||
this.next = this.iter.next();
|
||||
if (map.comparator().compare(this.next, start) > 1) break;
|
||||
}
|
||||
this.last = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public CloneableMapIterator<E> clone(final Object modifier) {
|
||||
return new CloneableMapIterator<E>(this.map, (E) modifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.next != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E next() {
|
||||
// returns key-elements, not entry-elements
|
||||
this.last = this.next;
|
||||
if (this.iter.hasNext()) {
|
||||
this.next = this.iter.next();
|
||||
} else {
|
||||
this.next = null;
|
||||
}
|
||||
return this.last;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
this.map.remove(this.last);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* RatingOrder.java
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 25.08.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package net.yacy.cora.order;
|
||||
|
||||
import net.yacy.cora.sorting.Rating;
|
||||
|
||||
|
||||
|
||||
public class RatingOrder<A> extends AbstractOrder<Rating<A>> implements Order<Rating<A>> {
|
||||
|
||||
Order<A> ordering;
|
||||
|
||||
public RatingOrder(final Order<A> ordering) {
|
||||
this.ordering = ordering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(final Rating<A> a, final Rating<A> b) {
|
||||
return this.ordering.compare(a.getObject(), b.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wellformed(final Rating<A> a) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String signature() {
|
||||
return "RA";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long cardinal(final Rating<A> key) {
|
||||
return key.getScore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equal(final Rating<A> a, final Rating<A> b) {
|
||||
return this.ordering.compare(a.getObject(), b.getObject()) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order<Rating<A>> clone() {
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
// RatingOrder.java
|
||||
// -----------------------
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://yacy.net
|
||||
// Frankfurt, Germany, 2011
|
||||
// created 25.08.2011
|
||||
//
|
||||
// $LastChangedDate: 2011-03-08 02:51:51 +0100 (Di, 08 Mrz 2011) $
|
||||
// $LastChangedRevision: 7567 $
|
||||
// $LastChangedBy: low012 $
|
||||
//
|
||||
// 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 net.yacy.cora.ranking;
|
||||
|
||||
|
||||
public class RatingOrder<A> extends AbstractOrder<Rating<A>> implements Order<Rating<A>> {
|
||||
|
||||
Order<A> ordering;
|
||||
|
||||
public RatingOrder(final Order<A> ordering) {
|
||||
this.ordering = ordering;
|
||||
}
|
||||
|
||||
public int compare(final Rating<A> a, final Rating<A> b) {
|
||||
return this.ordering.compare(a.getObject(), b.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wellformed(final Rating<A> a) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String signature() {
|
||||
return "RA";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long cardinal(final Rating<A> key) {
|
||||
return key.getScore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equal(final Rating<A> a, final Rating<A> b) {
|
||||
return this.ordering.compare(a.getObject(), b.getObject()) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order<Rating<A>> clone() {
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,29 +1,28 @@
|
||||
// AbstractMapStore.java
|
||||
// (C) 2011 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 16.11.2011 on http://yacy.net
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
// 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
|
||||
/**
|
||||
* AbstractMapStore
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 16.12.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package net.yacy.kelondro.blob;
|
||||
package net.yacy.cora.storage;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collection;
|
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* MapStore
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 16.12.2011 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2011-04-14 00:04:23 +0200 (Do, 14 Apr 2011) $
|
||||
* $LastChangedRevision: 7653 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package net.yacy.cora.storage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.yacy.cora.order.ByteOrder;
|
||||
import net.yacy.cora.order.CloneableIterator;
|
||||
|
||||
/**
|
||||
* this is a placeholder interface
|
||||
* for the complex expressionMap<byte[], Map<String, byte[]>>
|
||||
*
|
||||
*/
|
||||
public interface MapStore extends Map<byte[], Map<String, byte[]>>, Iterable<Map.Entry<byte[], Map<String, byte[]>>> {
|
||||
|
||||
/**
|
||||
* the map should have an ordering on the key elements
|
||||
* @return a byte order on the key elements
|
||||
*/
|
||||
public ByteOrder getOrdering();
|
||||
|
||||
/**
|
||||
* the keys of the map should be iterable
|
||||
* @return an iterator on the map keys
|
||||
*/
|
||||
public CloneableIterator<byte[]> keyIterator();
|
||||
|
||||
/**
|
||||
* most of the MapMap implementations are file-based, so we should consider a close method
|
||||
*/
|
||||
public void close();
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
// MapMap.java
|
||||
// (C) 2011 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 16.11.2011 on http://yacy.net
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
// 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 net.yacy.kelondro.blob;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.yacy.kelondro.order.ByteOrder;
|
||||
import net.yacy.kelondro.order.CloneableIterator;
|
||||
|
||||
/**
|
||||
* this is a placeholder interface
|
||||
* for the complex expressionMap<byte[], Map<String, byte[]>>
|
||||
*
|
||||
*/
|
||||
public interface MapStore extends Map<byte[], Map<String, byte[]>>, Iterable<Map.Entry<byte[], Map<String, byte[]>>> {
|
||||
|
||||
/**
|
||||
* the map should have an ordering on the key elements
|
||||
* @return a byte order on the key elements
|
||||
*/
|
||||
public ByteOrder getOrdering();
|
||||
|
||||
/**
|
||||
* the keys of the map should be iterable
|
||||
* @return an iterator on the map keys
|
||||
*/
|
||||
public CloneableIterator<byte[]> keyIterator();
|
||||
|
||||
/**
|
||||
* most of the MapMap implementations are file-based, so we should consider a close method
|
||||
*/
|
||||
public void close();
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
// ByteOrder.java
|
||||
// -----------------------------
|
||||
// (C) 2008 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 10.01.2008 on http://yacy.net
|
||||
//
|
||||
// This is a part of YaCy, a peer-to-peer based web search engine
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
// 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 net.yacy.kelondro.order;
|
||||
|
||||
import net.yacy.cora.ranking.Order;
|
||||
|
||||
|
||||
public interface ByteOrder extends Order<byte[]> {
|
||||
|
||||
public boolean wellformed(byte[] a);
|
||||
|
||||
public boolean wellformed(byte[] a, int start, int len);
|
||||
|
||||
public int compare(byte[] a, byte[] b);
|
||||
|
||||
public int compare(byte[] a, byte[] b, int len);
|
||||
|
||||
public int compare(byte[] a, int astart, byte[] b, int bstart, int len);
|
||||
|
||||
public boolean equal(final byte[] a, final byte[] b);
|
||||
|
||||
public boolean equal(final byte[] a, int astart, final byte[] b, int bstart, int length);
|
||||
|
||||
public long cardinal(final byte[] a, int off, int len);
|
||||
|
||||
public byte[] smallest(byte[] a, byte[] b);
|
||||
|
||||
public byte[] largest(byte[] a, byte[] b);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// CloneableIterator.java
|
||||
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 08.03.2007 on http://www.anomic.de
|
||||
//
|
||||
// This is a part of YaCy, a peer-to-peer based web search engine
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
// 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 net.yacy.kelondro.order;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface CloneableIterator<E> extends Iterator<E> {
|
||||
|
||||
// clone the iterator using a modifier
|
||||
// the modifier can be i.e. a re-start position
|
||||
public CloneableIterator<E> clone(Object modifier);
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
// CloneableMapIterator.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$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
// 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 net.yacy.kelondro.order;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
public class CloneableMapIterator<E> implements CloneableIterator<E> {
|
||||
|
||||
TreeMap<E, ?> map;
|
||||
E next, last;
|
||||
Object start;
|
||||
Iterator<E> iter;
|
||||
|
||||
|
||||
public CloneableMapIterator(final TreeMap<E, ?> map, final E start) {
|
||||
// map must contain eiter a byte[]/Object or a String/Object mapping.
|
||||
// start must be either of type byte[] or String
|
||||
// this iterator iterates then only the key elements of the map
|
||||
this.map = map;
|
||||
this.start = start;
|
||||
this.iter = map.keySet().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 (map.comparator().compare(next, start) > 1) break;
|
||||
}
|
||||
this.last = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CloneableMapIterator<E> clone(final Object modifier) {
|
||||
return new CloneableMapIterator<E>(map, (E) modifier);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return this.next != null;
|
||||
}
|
||||
|
||||
public E next() {
|
||||
// returns key-elements, not entry-elements
|
||||
this.last = this.next;
|
||||
if (this.iter.hasNext()) {
|
||||
this.next = this.iter.next();
|
||||
} else {
|
||||
this.next = null;
|
||||
}
|
||||
return this.last;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
this.map.remove(this.last);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue