*) adding iterator to userDB

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@819 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 20 years ago
parent a3bb20ca88
commit 19648702cc

@ -48,6 +48,8 @@ package de.anomic.data;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import de.anomic.kelondro.kelondroDyn;
@ -60,7 +62,7 @@ public class userDB {
public static final int USERNAME_MAX_LENGTH = 128;
public static final int USERNAME_MIN_LENGTH = 4;
private kelondroMap userTable;
kelondroMap userTable;
private File userTableFile;
private int bufferkb;
@ -89,7 +91,7 @@ public class userDB {
return userTable.cacheFillStatus();
}
private void resetDatabase() {
void resetDatabase() {
// deletes the database and creates a new one
if (userTable != null) try {
userTable.close();
@ -119,11 +121,11 @@ public class userDB {
} catch (IOException e) {}
}
public Entry getEntry(String hostName) {
public Entry getEntry(String userName) {
try {
Map record = userTable.get(hostName);
Map record = userTable.get(userName);
if (record == null) return null;
return new Entry(hostName, record);
return new Entry(userName, record);
} catch (IOException e) {
return null;
}
@ -207,5 +209,50 @@ public class userDB {
}
public Iterator iterator(boolean up) {
// enumerates users
try {
return new userIterator(up);
} catch (IOException e) {
return new HashSet().iterator();
}
}
public class userIterator implements Iterator {
// the iterator iterates all userNames
kelondroDyn.dynKeyIterator userIter;
userDB.Entry nextEntry;
public userIterator(boolean up) throws IOException {
this.userIter = userDB.this.userTable.keys(up, false);
this.nextEntry = null;
}
public boolean hasNext() {
try {
return this.userIter.hasNext();
} catch (kelondroException e) {
resetDatabase();
return false;
}
}
public Object next() {
try {
return getEntry((String) this.userIter.next());
} catch (kelondroException e) {
resetDatabase();
return null;
}
}
public void remove() {
if (this.nextEntry != null) {
try {
Object userName = this.nextEntry.getUserName();
if (userName != null) removeEntry((String) userName);
} catch (kelondroException e) {
resetDatabase();
}
}
}
}
}

Loading…
Cancel
Save