bookmarkDB cleanup

(preparation for tagCache)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1951 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 19 years ago
parent e82899ba57
commit 330eb9c74f

@ -210,7 +210,7 @@ public class bookmarksDB {
public void setTagsTable(Tag tag){
try {
if(tag.size() >0){
bookmarksDB.this.tagsTable.set(tag.getTagHash(), tag.mem);
bookmarksDB.this.tagsTable.set(tag.getTagHash(), tag.getMap());
}else{
bookmarksDB.this.tagsTable.remove(tag.getTagHash());
}
@ -218,7 +218,7 @@ public class bookmarksDB {
}
public String addTag(Tag tag){
try {
tagsTable.set(tag.getTagName(), tag.mem);
tagsTable.set(tag.getTagName(), tag.getMap());
return tag.getTagName();
} catch (IOException e) {
return null;
@ -288,12 +288,12 @@ public class bookmarksDB {
String tagHash=tagHash(oldName);
Tag tag=getTag(tagHash);
if (tag != null) {
ArrayList urlHashes = tag.getUrlHashes();
HashSet urlHashes = tag.getUrlHashes();
try {
tagsTable.remove(tagHash(oldName));
} catch (IOException e) {
}
tag=new Tag(tagHash(newName), tag.mem);
tag=new Tag(tagHash(newName), tag.getMap());
tag.tagHash = tagHash(newName);
setTagsTable(tag);
Iterator it = urlHashes.iterator();
@ -350,7 +350,7 @@ public class bookmarksDB {
TreeSet set=new TreeSet(new bookmarkComparator(true));
String tagHash=tagHash(tagName);
Tag tag=getTag(tagHash);
ArrayList hashes=new ArrayList();
HashSet hashes=new HashSet();
if(tag != null){
hashes=getTag(tagHash).getUrlHashes();
}
@ -521,23 +521,34 @@ public class bookmarksDB {
public static final String TAG_NAME="tagName";
private String tagHash;
private Map mem;
private HashSet urlHashes;
public Tag(String hash, Map map){
tagHash=hash;
mem=map;
if(mem.containsKey(URL_HASHES))
urlHashes=listManager.string2hashset((String) mem.get(URL_HASHES));
else
urlHashes=new HashSet();
}
public Tag(String name, ArrayList entries){
public Tag(String name, HashSet entries){
tagHash=tagHash(name);
mem=new HashMap();
mem.put(URL_HASHES, listManager.arraylist2string(entries));
//mem.put(URL_HASHES, listManager.arraylist2string(entries));
urlHashes=entries;
mem.put(TAG_NAME, name);
}
public Tag(String name){
tagHash=tagHash(name);
mem=new HashMap();
mem.put(URL_HASHES, "");
//mem.put(URL_HASHES, "");
urlHashes=new HashSet();
mem.put(TAG_NAME, name);
}
public Map getMap(){
mem.put(URL_HASHES, listManager.hashset2string(this.urlHashes));
return mem;
}
/**
* get the lowercase Tagname
*/
@ -565,8 +576,8 @@ public class bookmarksDB {
}
return "notagname";
}
public ArrayList getUrlHashes(){
return listManager.string2arraylist((String)this.mem.get(URL_HASHES));
public HashSet getUrlHashes(){
return urlHashes;
}
public boolean hasPublicItems(){
Iterator it=getBookmarksIterator(this.getTagName(), false);
@ -576,34 +587,13 @@ public class bookmarksDB {
return false;
}
public void add(String urlHash){
String urlHashes = (String)mem.get(URL_HASHES);
ArrayList list;
if(urlHashes != null && !urlHashes.equals("")){
list=listManager.string2arraylist(urlHashes);
}else{
list=new ArrayList();
}
if(!list.contains(urlHash) && !urlHash.equals("")){
list.add(urlHash);
}
this.mem.put(URL_HASHES, listManager.arraylist2string(list));
/*if(urlHashes!=null && !urlHashes.equals("") ){
if(urlHashes.indexOf(urlHash) <0){
this.mem.put(URL_HASHES, urlHashes+","+urlHash);
}
}else{
this.mem.put(URL_HASHES, urlHash);
}*/
urlHashes.add(urlHash);
}
public void delete(String urlHash){
ArrayList list=listManager.string2arraylist((String) this.mem.get(URL_HASHES));
if(list.contains(urlHash)){
list.remove(urlHash);
}
this.mem.put(URL_HASHES, listManager.arraylist2string(list));
urlHashes.remove(urlHash);
}
public int size(){
return listManager.string2arraylist(((String)this.mem.get(URL_HASHES))).size();
return urlHashes.size();
}
}
public class bookmarksDate{

@ -54,6 +54,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Vector;
@ -289,6 +290,34 @@ public class listManager {
}
return ret;
}
public static String hashset2string(HashSet hashset){
StringBuffer ret=new StringBuffer();
if(hashset!=null){
Iterator it=hashset.iterator();
if(it.hasNext()){
ret.append((String)it.next());
while(it.hasNext()){
ret.append(",").append((String)it.next());
}
}
}
return ret.toString();
}
public static HashSet string2hashset(String string){
HashSet ret=new HashSet();
String[] hashes=string.split(",");
if(string.indexOf(",") > -1){
for(int i=0;i<hashes.length;i++){
ret.add(hashes[i]);
}
}else{
ret = new HashSet();
if(!string.equals("")){
ret.add(string);
}
}
return ret;
}
//=============Blacklist specific================

Loading…
Cancel
Save