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

@ -54,6 +54,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
@ -289,6 +290,34 @@ public class listManager {
} }
return ret; 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================ //=============Blacklist specific================

Loading…
Cancel
Save