using ArrayList instead of Vector

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

@ -48,8 +48,8 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector;
import de.anomic.data.bookmarksDB; import de.anomic.data.bookmarksDB;
import de.anomic.data.listManager; import de.anomic.data.listManager;
@ -103,7 +103,7 @@ public class Bookmarks {
if(tagsString.equals("")){ if(tagsString.equals("")){
tagsString="unsorted"; //defaulttag tagsString="unsorted"; //defaulttag
} }
Vector tags=listManager.string2vector(tagsString); ArrayList tags=listManager.string2arraylist(tagsString);
bookmarksDB.Bookmark bookmark = switchboard.bookmarksDB.createBookmark(url); bookmarksDB.Bookmark bookmark = switchboard.bookmarksDB.createBookmark(url);
if(bookmark != null){ if(bookmark != null){
@ -220,7 +220,7 @@ public class Bookmarks {
count++; count++;
} }
count=0; count=0;
Vector tags; ArrayList tags;
Iterator tagsIt; Iterator tagsIt;
int tagCount; int tagCount;
while(count<max_count && it.hasNext()){ while(count<max_count && it.hasNext()){
@ -232,7 +232,7 @@ public class Bookmarks {
prop.put("bookmarks_"+count+"_public", (bookmark.getPublic()? 1:0)); prop.put("bookmarks_"+count+"_public", (bookmark.getPublic()? 1:0));
//List Tags. //List Tags.
tags=bookmark.getTagsVector(); tags=bookmark.getTagsList();
tagsIt=tags.iterator(); tagsIt=tags.iterator();
tagCount=0; tagCount=0;
while(tagsIt.hasNext()){ while(tagsIt.hasNext()){

@ -48,6 +48,7 @@ import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
@ -56,7 +57,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -288,7 +288,7 @@ 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) {
Vector urlHashes = tag.getUrlHashes(); ArrayList urlHashes = tag.getUrlHashes();
try { try {
tagsTable.remove(tagHash(oldName)); tagsTable.remove(tagHash(oldName));
} catch (IOException e) { } catch (IOException e) {
@ -298,10 +298,10 @@ public class bookmarksDB {
setTagsTable(tag); setTagsTable(tag);
Iterator it = urlHashes.iterator(); Iterator it = urlHashes.iterator();
Bookmark bookmark; Bookmark bookmark;
Vector tags; ArrayList tags;
while (it.hasNext()) { while (it.hasNext()) {
bookmark = getBookmark((String) it.next()); bookmark = getBookmark((String) it.next());
tags = listManager.string2vector(bookmark.getTags()); tags = listManager.string2arraylist(bookmark.getTags());
tags.remove(oldName); //this will fail, if upper/lowercase is not matching tags.remove(oldName); //this will fail, if upper/lowercase is not matching
tags.add(newName); tags.add(newName);
bookmark.setTags(tags, true); bookmark.setTags(tags, true);
@ -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);
Vector hashes=new Vector(); ArrayList hashes=new ArrayList();
if(tag != null){ if(tag != null){
hashes=getTag(tagHash).getUrlHashes(); hashes=getTag(tagHash).getUrlHashes();
} }
@ -416,7 +416,7 @@ public class bookmarksDB {
return new HashSet().iterator(); return new HashSet().iterator();
} }
} }
public void addBookmark(String url, String title, Vector tags){ public void addBookmark(String url, String title, ArrayList tags){
} }
public void importFromBookmarks(URL baseURL, String input, String tag, boolean importPublic){ public void importFromBookmarks(URL baseURL, String input, String tag, boolean importPublic){
@ -424,7 +424,7 @@ public class bookmarksDB {
Iterator it; Iterator it;
String url,title; String url,title;
Bookmark bm; Bookmark bm;
Vector tags=listManager.string2vector(tag); //this allow multiple default tags ArrayList tags=listManager.string2arraylist(tag); //this allow multiple default tags
try { try {
//load the links //load the links
htmlFilterContentScraper scraper = new htmlFilterContentScraper(baseURL); htmlFilterContentScraper scraper = new htmlFilterContentScraper(baseURL);
@ -487,13 +487,13 @@ public class bookmarksDB {
if(attributes.getNamedItem("time")!=null){ if(attributes.getNamedItem("time")!=null){
time=attributes.getNamedItem("time").getNodeValue(); time=attributes.getNamedItem("time").getNodeValue();
} }
Vector tags=new Vector(); ArrayList tags=new ArrayList();
if(title != null){ if(title != null){
bm.setProperty(Bookmark.BOOKMARK_TITLE, title); bm.setProperty(Bookmark.BOOKMARK_TITLE, title);
} }
if(tagsString!=null){ if(tagsString!=null){
tags = listManager.string2vector(tagsString.replace(' ', ',')); tags = listManager.string2arraylist(tagsString.replace(' ', ','));
} }
bm.setTags(tags, true); bm.setTags(tags, true);
if(time != null){ if(time != null){
@ -526,10 +526,10 @@ public class bookmarksDB {
tagHash=hash; tagHash=hash;
mem=map; mem=map;
} }
public Tag(String name, Vector entries){ public Tag(String name, ArrayList entries){
tagHash=tagHash(name); tagHash=tagHash(name);
mem=new HashMap(); mem=new HashMap();
mem.put(URL_HASHES, listManager.vector2string(entries)); mem.put(URL_HASHES, listManager.arraylist2string(entries));
mem.put(TAG_NAME, name); mem.put(TAG_NAME, name);
} }
public Tag(String name){ public Tag(String name){
@ -565,8 +565,8 @@ public class bookmarksDB {
} }
return "notagname"; return "notagname";
} }
public Vector getUrlHashes(){ public ArrayList getUrlHashes(){
return listManager.string2vector((String)this.mem.get(URL_HASHES)); return listManager.string2arraylist((String)this.mem.get(URL_HASHES));
} }
public boolean hasPublicItems(){ public boolean hasPublicItems(){
Iterator it=getBookmarksIterator(this.getTagName(), false); Iterator it=getBookmarksIterator(this.getTagName(), false);
@ -577,16 +577,16 @@ public class bookmarksDB {
} }
public void add(String urlHash){ public void add(String urlHash){
String urlHashes = (String)mem.get(URL_HASHES); String urlHashes = (String)mem.get(URL_HASHES);
Vector list; ArrayList list;
if(urlHashes != null && !urlHashes.equals("")){ if(urlHashes != null && !urlHashes.equals("")){
list=listManager.string2vector(urlHashes); list=listManager.string2arraylist(urlHashes);
}else{ }else{
list=new Vector(); list=new ArrayList();
} }
if(!list.contains(urlHash) && !urlHash.equals("")){ if(!list.contains(urlHash) && !urlHash.equals("")){
list.add(urlHash); list.add(urlHash);
} }
this.mem.put(URL_HASHES, listManager.vector2string(list)); this.mem.put(URL_HASHES, listManager.arraylist2string(list));
/*if(urlHashes!=null && !urlHashes.equals("") ){ /*if(urlHashes!=null && !urlHashes.equals("") ){
if(urlHashes.indexOf(urlHash) <0){ if(urlHashes.indexOf(urlHash) <0){
this.mem.put(URL_HASHES, urlHashes+","+urlHash); this.mem.put(URL_HASHES, urlHashes+","+urlHash);
@ -596,14 +596,14 @@ public class bookmarksDB {
}*/ }*/
} }
public void delete(String urlHash){ public void delete(String urlHash){
Vector list=listManager.string2vector((String) this.mem.get(URL_HASHES)); ArrayList list=listManager.string2arraylist((String) this.mem.get(URL_HASHES));
if(list.contains(urlHash)){ if(list.contains(urlHash)){
list.remove(urlHash); list.remove(urlHash);
} }
this.mem.put(URL_HASHES, listManager.vector2string(list)); this.mem.put(URL_HASHES, listManager.arraylist2string(list));
} }
public int size(){ public int size(){
return listManager.string2vector(((String)this.mem.get(URL_HASHES))).size(); return listManager.string2arraylist(((String)this.mem.get(URL_HASHES))).size();
} }
} }
public class bookmarksDate{ public class bookmarksDate{
@ -619,23 +619,23 @@ public class bookmarksDB {
date=mydate; date=mydate;
mem=map; mem=map;
} }
public bookmarksDate(String mydate, Vector entries){ public bookmarksDate(String mydate, ArrayList entries){
date=mydate; date=mydate;
mem=new HashMap(); mem=new HashMap();
mem.put(URL_HASHES, listManager.vector2string(entries)); mem.put(URL_HASHES, listManager.arraylist2string(entries));
} }
public void add(String urlHash){ public void add(String urlHash){
String urlHashes = (String)mem.get(URL_HASHES); String urlHashes = (String)mem.get(URL_HASHES);
Vector list; ArrayList list;
if(urlHashes != null && !urlHashes.equals("")){ if(urlHashes != null && !urlHashes.equals("")){
list=listManager.string2vector(urlHashes); list=listManager.string2arraylist(urlHashes);
}else{ }else{
list=new Vector(); list=new ArrayList();
} }
if(!list.contains(urlHash) && !urlHash.equals("")){ if(!list.contains(urlHash) && !urlHash.equals("")){
list.add(urlHash); list.add(urlHash);
} }
this.mem.put(URL_HASHES, listManager.vector2string(list)); this.mem.put(URL_HASHES, listManager.arraylist2string(list));
/*if(urlHashes!=null && !urlHashes.equals("") ){ /*if(urlHashes!=null && !urlHashes.equals("") ){
if(urlHashes.indexOf(urlHash) <0){ if(urlHashes.indexOf(urlHash) <0){
this.mem.put(URL_HASHES, urlHashes+","+urlHash); this.mem.put(URL_HASHES, urlHashes+","+urlHash);
@ -645,11 +645,11 @@ public class bookmarksDB {
}*/ }*/
} }
public void delete(String urlHash){ public void delete(String urlHash){
Vector list=listManager.string2vector((String) this.mem.get(URL_HASHES)); ArrayList list=listManager.string2arraylist((String) this.mem.get(URL_HASHES));
if(list.contains(urlHash)){ if(list.contains(urlHash)){
list.remove(urlHash); list.remove(urlHash);
} }
this.mem.put(URL_HASHES, listManager.vector2string(list)); this.mem.put(URL_HASHES, listManager.arraylist2string(list));
} }
public void setDatesTable(){ public void setDatesTable(){
try { try {
@ -664,7 +664,7 @@ public class bookmarksDB {
return date; return date;
} }
public int size(){ public int size(){
return listManager.string2vector(((String)this.mem.get(URL_HASHES))).size(); return listManager.string2arraylist(((String)this.mem.get(URL_HASHES))).size();
} }
} }
/** /**
@ -730,8 +730,8 @@ public class bookmarksDB {
} }
return ""; return "";
} }
public Vector getTagsVector(){ public ArrayList getTagsList(){
return listManager.string2vector(this.getTags()); return listManager.string2arraylist(this.getTags());
} }
public String getDescription(){ public String getDescription(){
if(this.mem.containsKey(BOOKMARK_DESCRIPTION)){ if(this.mem.containsKey(BOOKMARK_DESCRIPTION)){
@ -764,29 +764,29 @@ public class bookmarksDB {
//setBookmarksTable(); //setBookmarksTable();
} }
public void addTag(String tag){ public void addTag(String tag){
Vector tags; ArrayList tags;
if(!mem.containsKey(BOOKMARK_TAGS)){ if(!mem.containsKey(BOOKMARK_TAGS)){
tags=new Vector(); tags=new ArrayList();
}else{ }else{
tags=(Vector)mem.get(BOOKMARK_TAGS); tags=listManager.string2arraylist((String) mem.get(BOOKMARK_TAGS));
} }
tags.add(tag); tags.add(tag);
this.setTags(tags, true); this.setTags(tags, true);
} }
/** /**
* set the Tags of the bookmark, and write them into the tags table. * set the Tags of the bookmark, and write them into the tags table.
* @param tags a vector with the tags * @param tags a ArrayList with the tags
*/ */
public void setTags(Vector tags){ public void setTags(ArrayList tags){
setTags(tags, true); setTags(tags, true);
} }
/** /**
* set the Tags of the bookmark * set the Tags of the bookmark
* @param tags Vector with the tagnames * @param tags ArrayList with the tagnames
* @param local sets, whether the updated tags should be stored to tagsDB * @param local sets, whether the updated tags should be stored to tagsDB
*/ */
public void setTags(Vector tags, boolean local){ public void setTags(ArrayList tags, boolean local){
mem.put(BOOKMARK_TAGS, listManager.vector2string(tags)); mem.put(BOOKMARK_TAGS, listManager.arraylist2string(tags));
Iterator it=tags.iterator(); Iterator it=tags.iterator();
while(it.hasNext()){ while(it.hasNext()){
String tagName=(String) it.next(); String tagName=(String) it.next();

@ -236,6 +236,32 @@ public class listManager {
} }
return resultList; return resultList;
} }
public static String arraylist2string(ArrayList list){
Iterator it=list.iterator();
String ret="";
if(it.hasNext()){
ret=(String) it.next();
while(it.hasNext()){
ret+=","+(String)it.next();
}
}
return ret;
}
public static ArrayList string2arraylist(String string){
ArrayList ret=new ArrayList();
String[] hashes=string.split(",");
if(string.indexOf(",") > -1){
for(int i=0;i<hashes.length;i++){
ret.add(hashes[i]);
}
}else{
ret = new ArrayList();
if(!string.equals("")){
ret.add(string);
}
}
return ret;
}
public static String vector2string(Vector vector){ public static String vector2string(Vector vector){
Iterator it=vector.iterator(); Iterator it=vector.iterator();
String ret=""; String ret="";

Loading…
Cancel
Save