more generics

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4417 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent 0856cabb37
commit 7d875290b2

@ -293,6 +293,7 @@ public class bookmarksDB {
} }
return set.iterator(); return set.iterator();
} }
public Iterator<String> getBookmarksIterator(String tagName, boolean priv){ public Iterator<String> getBookmarksIterator(String tagName, boolean priv){
TreeSet<String> set=new TreeSet<String>(new bookmarkComparator(true)); TreeSet<String> set=new TreeSet<String>(new bookmarkComparator(true));
String tagHash=tagHash(tagName); String tagHash=tagHash(tagName);
@ -324,11 +325,13 @@ public class bookmarksDB {
public int tagsSize(){ // TODO: shouldn't this be public int tagSize() public int tagsSize(){ // TODO: shouldn't this be public int tagSize()
return tagSize(false); return tagSize(false);
} }
public int tagSize(boolean flushed){ public int tagSize(boolean flushed){
if(flushed) if(flushed)
flushTagCache(); flushTagCache();
return tagsTable.size(); return tagsTable.size();
} }
/** /**
* load/retrieve an object of type Tag from the tagsTable (also save it in tagCache) * load/retrieve an object of type Tag from the tagsTable (also save it in tagCache)
* @param hash an object of type String, containing a tagHash * @param hash an object of type String, containing a tagHash
@ -343,6 +346,7 @@ public class bookmarksDB {
} }
return ret; return ret;
} }
/** /**
* retrieve an object of type Tag from the the tagCache, if object is not cached return loadTag(hash) * retrieve an object of type Tag from the the tagCache, if object is not cached return loadTag(hash)
* @param hash an object of type String, containing a tagHash * @param hash an object of type String, containing a tagHash
@ -370,25 +374,28 @@ public class bookmarksDB {
* save a Tag in tagCache; see also flushTagCache(), addTag(), loadTag() * save a Tag in tagCache; see also flushTagCache(), addTag(), loadTag()
* @param tag an object of type Tag to be saved in tagCache * @param tag an object of type Tag to be saved in tagCache
*/ */
public void saveTag(Tag tag){ public void saveTag(Tag tag) {
if(tag!=null){ if(tag!=null){
tagCache.put(tag.getTagHash(), tag); tagCache.put(tag.getTagHash(), tag);
} }
} }
public void flushTagCache(){
public void flushTagCache() {
Iterator<String> it=tagCache.keySet().iterator(); Iterator<String> it=tagCache.keySet().iterator();
while(it.hasNext()){ while(it.hasNext()){
storeTag(tagCache.get(it.next())); storeTag(tagCache.get(it.next()));
} }
tagCache=new HashMap<String, Tag>(); tagCache=new HashMap<String, Tag>();
} }
public String addTag(Tag tag){ // TODO: is addTag() really needed - check storeTag() and saveTag()
public String addTag(Tag tag) { // TODO: is addTag() really needed - check storeTag() and saveTag()
//tagsTable.set(tag.getTagName(), tag.getMap()); //tagsTable.set(tag.getTagName(), tag.getMap());
//tagCache.put(tag.getTagHash(), tag); //tagCache.put(tag.getTagHash(), tag);
saveTag(tag); saveTag(tag);
return tag.getTagName(); return tag.getTagName();
} }
public void removeTag(String hash){
public void removeTag(String hash) {
try { try {
if(tagCache.containsKey(hash)){ if(tagCache.containsKey(hash)){
tagCache.remove(hash); tagCache.remove(hash);
@ -396,22 +403,25 @@ public class bookmarksDB {
tagsTable.remove(hash); tagsTable.remove(hash);
} catch (IOException e) {} } catch (IOException e) {}
} }
public Iterator tagIterator(boolean up){
public Iterator<Tag> tagIterator(boolean up) {
try { try {
return new tagIterator(up); return new tagIterator(up);
} catch (IOException e) { } catch (IOException e) {
return new HashSet().iterator(); return new HashSet<Tag>().iterator();
} }
} }
public Iterator<Tag> getTagIterator(boolean priv){
public Iterator<Tag> getTagIterator(boolean priv) {
return getTagIterator(priv,1); return getTagIterator(priv,1);
} }
public Iterator<Tag> getTagIterator(boolean priv, int c){
Comparator comp; public Iterator<Tag> getTagIterator(boolean priv, int c) {
Comparator<Tag> comp;
if (c == SORT_SIZE) comp = new tagSizeComparator(); if (c == SORT_SIZE) comp = new tagSizeComparator();
else comp = new tagComparator(); else comp = new tagComparator();
TreeSet<Tag> set=new TreeSet<Tag>(comp); TreeSet<Tag> set=new TreeSet<Tag>(comp);
Iterator it=tagIterator(true); Iterator<Tag> it = tagIterator(true);
Tag tag; Tag tag;
while(it.hasNext()){ while(it.hasNext()){
tag=(Tag) it.next(); tag=(Tag) it.next();
@ -421,6 +431,7 @@ public class bookmarksDB {
} }
return set.iterator(); return set.iterator();
} }
public Iterator<Tag> getTagIterator(boolean priv, int comp, int max){ public Iterator<Tag> getTagIterator(boolean priv, int comp, int max){
if (max==SHOW_ALL) if (max==SHOW_ALL)
return getTagIterator(priv, comp); return getTagIterator(priv, comp);
@ -433,11 +444,13 @@ public class bookmarksDB {
} }
return set.iterator(); return set.iterator();
} }
public Iterator<Tag> getTagIterator(String tagName, boolean priv){ public Iterator<Tag> getTagIterator(String tagName, boolean priv){
return getTagIterator(tagName, priv, 1); return getTagIterator(tagName, priv, 1);
} }
public Iterator<Tag> getTagIterator(String tagName, boolean priv, int comp){ public Iterator<Tag> getTagIterator(String tagName, boolean priv, int comp){
Comparator c; Comparator<Tag> c;
if (comp == SORT_SIZE) c = new tagSizeComparator(); if (comp == SORT_SIZE) c = new tagSizeComparator();
else c = new tagComparator(); else c = new tagComparator();
TreeSet<Tag> set=new TreeSet<Tag>(c); TreeSet<Tag> set=new TreeSet<Tag>(c);
@ -459,6 +472,7 @@ public class bookmarksDB {
} }
return set.iterator(); return set.iterator();
} }
public Iterator<Tag> getTagIterator(String tagName, boolean priv, int comp, int max){ public Iterator<Tag> getTagIterator(String tagName, boolean priv, int comp, int max){
if (max==SHOW_ALL) if (max==SHOW_ALL)
return getTagIterator(priv, comp); return getTagIterator(priv, comp);
@ -475,7 +489,7 @@ public class bookmarksDB {
// rebuilds the tagsDB from the bookmarksDB // rebuilds the tagsDB from the bookmarksDB
public void rebuildTags(){ public void rebuildTags(){
serverLog.logInfo("BOOKMARKS", "rebuilding tags.db from bookmarks.db..."); serverLog.logInfo("BOOKMARKS", "rebuilding tags.db from bookmarks.db...");
Iterator it=bookmarkIterator(true); Iterator<Bookmark> it = bookmarkIterator(true);
Bookmark bookmark; Bookmark bookmark;
Tag tag; Tag tag;
String[] tags; String[] tags;
@ -509,7 +523,7 @@ public class bookmarksDB {
// rebuilds the datesDB from the bookmarksDB // rebuilds the datesDB from the bookmarksDB
public void rebuildDates(){ public void rebuildDates(){
serverLog.logInfo("BOOKMARKS", "rebuilding dates.db from bookmarks.db..."); serverLog.logInfo("BOOKMARKS", "rebuilding dates.db from bookmarks.db...");
Iterator it=bookmarkIterator(true); Iterator<Bookmark> it=bookmarkIterator(true);
Bookmark bookmark; Bookmark bookmark;
String date; String date;
bookmarksDate bmDate; bookmarksDate bmDate;
@ -533,12 +547,12 @@ public class bookmarksDB {
public boolean renameTag(String oldName, String newName){ public boolean renameTag(String oldName, String newName){
String oldHash=tagHash(oldName); String oldHash=tagHash(oldName);
String newHash=tagHash(newName); //String newHash=tagHash(newName);
Tag tag=getTag(oldHash); // set tag to oldHash Tag tag=getTag(oldHash); // set tag to oldHash
if (tag != null) { if (tag != null) {
Set urlHashes = tag.getUrlHashes(); // preserve urlHashes of tag Set<String> urlHashes = tag.getUrlHashes(); // preserve urlHashes of tag
removeTag(oldHash); removeTag(oldHash);
Iterator it = urlHashes.iterator(); Iterator<String> it = urlHashes.iterator();
Bookmark bookmark; Bookmark bookmark;
Set<String> tags = new HashSet<String>(); Set<String> tags = new HashSet<String>();
String tagsString; String tagsString;
@ -558,17 +572,13 @@ public class bookmarksDB {
return false; return false;
} }
public void addBookmark(String url, String title, ArrayList tags){
}
// -------------------------------------- // --------------------------------------
// bookmarksDB's Import/Export functions // bookmarksDB's Import/Export functions
// -------------------------------------- // --------------------------------------
public int importFromBookmarks(yacyURL baseURL, String input, String tag, boolean importPublic){ public int importFromBookmarks(yacyURL baseURL, String input, String tag, boolean importPublic){
try { try {
// convert string to inputstream // convert string to input stream
ByteArrayInputStream byteIn = new ByteArrayInputStream(input.getBytes("UTF-8")); ByteArrayInputStream byteIn = new ByteArrayInputStream(input.getBytes("UTF-8"));
InputStreamReader reader = new InputStreamReader(byteIn,"UTF-8"); InputStreamReader reader = new InputStreamReader(byteIn,"UTF-8");
@ -578,12 +588,12 @@ public class bookmarksDB {
return 0; return 0;
} }
} }
public int importFromBookmarks(yacyURL baseURL, InputStreamReader input, String tag, boolean importPublic){ public int importFromBookmarks(yacyURL baseURL, InputStreamReader input, String tag, boolean importPublic){
int importCount = 0; int importCount = 0;
HashMap links=new HashMap(); Map<yacyURL, String> links = new HashMap<yacyURL, String>();
Iterator it;
String title; String title;
yacyURL url; yacyURL url;
Bookmark bm; Bookmark bm;
@ -595,12 +605,11 @@ public class bookmarksDB {
Writer writer= new htmlFilterWriter(null,null,scraper, null, false); Writer writer= new htmlFilterWriter(null,null,scraper, null, false);
serverFileUtils.copy(input,writer); serverFileUtils.copy(input,writer);
writer.close(); writer.close();
links = (HashMap) scraper.getAnchors(); links = scraper.getAnchors();
} catch (IOException e) {} } catch (IOException e) {}
it=links.keySet().iterator(); Iterator<yacyURL> it = links.keySet().iterator();
while(it.hasNext()){ while (it.hasNext()) {
// url=(String) it.next(); url= it.next();
url= (yacyURL) it.next();
title=(String) links.get(url); title=(String) links.get(url);
serverLog.logInfo("BOOKMARKS", "links.get(url)"); serverLog.logInfo("BOOKMARKS", "links.get(url)");
if(title.equals("")){//cannot be displayed if(title.equals("")){//cannot be displayed
@ -619,9 +628,10 @@ public class bookmarksDB {
return importCount; return importCount;
} }
public int importFromXML(String input, boolean importPublic){ public int importFromXML(String input, boolean importPublic){
try { try {
// convert string to inputstream // convert string to input stream
ByteArrayInputStream byteIn = new ByteArrayInputStream(input.getBytes("UTF-8")); ByteArrayInputStream byteIn = new ByteArrayInputStream(input.getBytes("UTF-8"));
// import stream // import stream
@ -630,6 +640,7 @@ public class bookmarksDB {
return 0; return 0;
} }
} }
public int importFromXML(InputStream input, boolean importPublic){ public int importFromXML(InputStream input, boolean importPublic){
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
factory.setValidating(false); factory.setValidating(false);
@ -646,6 +657,7 @@ public class bookmarksDB {
return 0; return 0;
} }
public int parseXMLimport(Node doc, boolean importPublic){ public int parseXMLimport(Node doc, boolean importPublic){
int importCount = 0; int importCount = 0;
if(doc.getNodeName()=="post"){ if(doc.getNodeName()=="post"){
@ -870,7 +882,7 @@ public class bookmarksDB {
/** /**
* Subclass of bookmarksDB, which provides the Bookmark object-type * Subclass of bookmarksDB, which provides the Bookmark object-type
*/ */
public class Bookmark extends kelondroObjectsMapEntry{ public class Bookmark extends kelondroObjectsMapEntry {
public static final String BOOKMARK_URL="bookmarkUrl"; public static final String BOOKMARK_URL="bookmarkUrl";
public static final String BOOKMARK_TITLE="bookmarkTitle"; public static final String BOOKMARK_TITLE="bookmarkTitle";
public static final String BOOKMARK_DESCRIPTION="bookmarkDesc"; public static final String BOOKMARK_DESCRIPTION="bookmarkDesc";
@ -882,7 +894,8 @@ public class bookmarksDB {
private String urlHash; private String urlHash;
private Set<String> tags; private Set<String> tags;
private long timestamp; private long timestamp;
public Bookmark(String urlHash, HashMap map){
public Bookmark(String urlHash, HashMap<String, String> map) {
super(map); super(map);
this.urlHash=urlHash; this.urlHash=urlHash;
if(map.containsKey(BOOKMARK_TAGS)) if(map.containsKey(BOOKMARK_TAGS))
@ -891,6 +904,7 @@ public class bookmarksDB {
tags=new HashSet<String>(); tags=new HashSet<String>();
loadTimestamp(); loadTimestamp();
} }
public Bookmark(String url){ public Bookmark(String url){
super(); super();
if(!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")){ if(!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")){
@ -916,14 +930,16 @@ public class bookmarksDB {
removeBookmark(this.urlHash); //prevent empty tags removeBookmark(this.urlHash); //prevent empty tags
} }
public Bookmark(String urlHash, yacyURL url){
public Bookmark(String urlHash, yacyURL url) {
super(); super();
this.urlHash=urlHash; this.urlHash=urlHash;
entry.put(BOOKMARK_URL, url.toNormalform(false, true)); entry.put(BOOKMARK_URL, url.toNormalform(false, true));
tags=new HashSet<String>(); tags=new HashSet<String>();
timestamp=System.currentTimeMillis(); timestamp=System.currentTimeMillis();
} }
public Bookmark(String urlHash, String url){
public Bookmark(String urlHash, String url) {
super(); super();
this.urlHash=urlHash; this.urlHash=urlHash;
entry.put(BOOKMARK_URL, url); entry.put(BOOKMARK_URL, url);
@ -935,25 +951,30 @@ public class bookmarksDB {
this((new yacyURL((String)map.map().get(BOOKMARK_URL), null)).hash(), map.map()); this((new yacyURL((String)map.map().get(BOOKMARK_URL), null)).hash(), map.map());
} }
private Map<String, String> toMap(){ private Map<String, String> toMap() {
entry.put(BOOKMARK_TAGS, listManager.collection2string(tags)); entry.put(BOOKMARK_TAGS, listManager.collection2string(tags));
entry.put(BOOKMARK_TIMESTAMP, String.valueOf(this.timestamp)); entry.put(BOOKMARK_TIMESTAMP, String.valueOf(this.timestamp));
return entry; return entry;
} }
private void loadTimestamp(){
private void loadTimestamp() {
if(entry.containsKey(BOOKMARK_TIMESTAMP)) if(entry.containsKey(BOOKMARK_TIMESTAMP))
this.timestamp=Long.parseLong(entry.get(BOOKMARK_TIMESTAMP)); this.timestamp=Long.parseLong(entry.get(BOOKMARK_TIMESTAMP));
} }
public String getUrlHash(){
public String getUrlHash() {
return urlHash; return urlHash;
} }
public String getUrl(){
public String getUrl() {
return entry.get(BOOKMARK_URL); return entry.get(BOOKMARK_URL);
} }
public Set<String> getTags(){
public Set<String> getTags() {
return tags; return tags;
} }
public String getTagsString(){
public String getTagsString() {
String s[] = listManager.collection2string(getTags()).split(","); String s[] = listManager.collection2string(getTags()).split(",");
String tagsString=""; String tagsString="";
for (int i=0; i<s.length; i++){ for (int i=0; i<s.length; i++){
@ -963,6 +984,7 @@ public class bookmarksDB {
} }
return tagsString; return tagsString;
} }
public String getFoldersString(){ public String getFoldersString(){
String s[] = listManager.collection2string(getTags()).split(","); String s[] = listManager.collection2string(getTags()).split(",");
String foldersString=""; String foldersString="";
@ -973,39 +995,46 @@ public class bookmarksDB {
} }
return foldersString; return foldersString;
} }
public String getDescription(){ public String getDescription(){
if(entry.containsKey(BOOKMARK_DESCRIPTION)){ if(entry.containsKey(BOOKMARK_DESCRIPTION)){
return entry.get(BOOKMARK_DESCRIPTION); return entry.get(BOOKMARK_DESCRIPTION);
} }
return ""; return "";
} }
public String getTitle(){ public String getTitle(){
if(entry.containsKey(BOOKMARK_TITLE)){ if(entry.containsKey(BOOKMARK_TITLE)){
return entry.get(BOOKMARK_TITLE); return entry.get(BOOKMARK_TITLE);
} }
return entry.get(BOOKMARK_URL); return entry.get(BOOKMARK_URL);
} }
public String getOwner(){ public String getOwner(){
if(entry.containsKey(BOOKMARK_OWNER)){ if(entry.containsKey(BOOKMARK_OWNER)){
return entry.get(BOOKMARK_OWNER); return entry.get(BOOKMARK_OWNER);
} }
return null; //null means admin return null; //null means admin
} }
public void setOwner(String owner){ public void setOwner(String owner){
entry.put(BOOKMARK_OWNER, owner); entry.put(BOOKMARK_OWNER, owner);
} }
public boolean getPublic(){ public boolean getPublic(){
if(entry.containsKey(BOOKMARK_PUBLIC)){ if(entry.containsKey(BOOKMARK_PUBLIC)){
return entry.get(BOOKMARK_PUBLIC).equals("public"); return entry.get(BOOKMARK_PUBLIC).equals("public");
} }
return false; return false;
} }
public boolean getFeed(){ public boolean getFeed(){
if(entry.containsKey(BOOKMARK_IS_FEED)){ if(entry.containsKey(BOOKMARK_IS_FEED)){
return entry.get(BOOKMARK_IS_FEED).equals("true"); return entry.get(BOOKMARK_IS_FEED).equals("true");
} }
return false; return false;
} }
public void setPublic(boolean isPublic){ public void setPublic(boolean isPublic){
if(isPublic){ if(isPublic){
entry.put(BOOKMARK_PUBLIC, "public"); entry.put(BOOKMARK_PUBLIC, "public");
@ -1013,6 +1042,7 @@ public class bookmarksDB {
entry.put(BOOKMARK_PUBLIC, "private"); entry.put(BOOKMARK_PUBLIC, "private");
} }
} }
public void setFeed(boolean isFeed){ public void setFeed(boolean isFeed){
if(isFeed){ if(isFeed){
entry.put(BOOKMARK_IS_FEED, "true"); entry.put(BOOKMARK_IS_FEED, "true");
@ -1020,13 +1050,16 @@ public class bookmarksDB {
entry.put(BOOKMARK_IS_FEED, "false"); entry.put(BOOKMARK_IS_FEED, "false");
} }
} }
public void setProperty(String name, String value){ public void setProperty(String name, String value){
entry.put(name, value); entry.put(name, value);
//setBookmarksTable(); //setBookmarksTable();
} }
public void addTag(String tag){ public void addTag(String tag){
tags.add(tag); tags.add(tag);
} }
/** /**
* 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 tags2 a ArrayList with the tags * @param tags2 a ArrayList with the tags
@ -1034,6 +1067,7 @@ public class bookmarksDB {
public void setTags(Set<String> tags2){ public void setTags(Set<String> tags2){
setTags(tags2, true); setTags(tags2, true);
} }
/** /**
* set the Tags of the bookmark * set the Tags of the bookmark
* @param tags ArrayList with the tagnames * @param tags ArrayList with the tagnames
@ -1060,6 +1094,7 @@ public class bookmarksDB {
public long getTimeStamp(){ public long getTimeStamp(){
return timestamp; return timestamp;
} }
public void setTimeStamp(long ts){ public void setTimeStamp(long ts){
this.timestamp=ts; this.timestamp=ts;
} }
@ -1070,11 +1105,13 @@ public class bookmarksDB {
public class tagIterator implements Iterator<Tag> { public class tagIterator implements Iterator<Tag> {
kelondroCloneableIterator<String> tagIter; kelondroCloneableIterator<String> tagIter;
bookmarksDB.Tag nextEntry; bookmarksDB.Tag nextEntry;
public tagIterator(boolean up) throws IOException { public tagIterator(boolean up) throws IOException {
flushTagCache(); //XXX: This costs performace :-(( flushTagCache(); //XXX: This costs performace :-((
this.tagIter = bookmarksDB.this.tagsTable.keys(up, false); this.tagIter = bookmarksDB.this.tagsTable.keys(up, false);
this.nextEntry = null; this.nextEntry = null;
} }
public boolean hasNext() { public boolean hasNext() {
try { try {
return this.tagIter.hasNext(); return this.tagIter.hasNext();
@ -1083,6 +1120,7 @@ public class bookmarksDB {
return false; return false;
} }
} }
public Tag next() { public Tag next() {
try { try {
return getTag(this.tagIter.next()); return getTag(this.tagIter.next());
@ -1091,6 +1129,7 @@ public class bookmarksDB {
return null; return null;
} }
} }
public void remove() { public void remove() {
if (this.nextEntry != null) { if (this.nextEntry != null) {
try { try {
@ -1102,17 +1141,19 @@ public class bookmarksDB {
} }
} }
} }
/** /**
* Subclass of bookmarksDB, which provides the bookmarkIterator object-type * Subclass of bookmarksDB, which provides the bookmarkIterator object-type
*/ */
public class bookmarkIterator implements Iterator<Bookmark> { public class bookmarkIterator implements Iterator<Bookmark> {
Iterator bookmarkIter; Iterator<String> bookmarkIter;
bookmarksDB.Bookmark nextEntry; bookmarksDB.Bookmark nextEntry;
public bookmarkIterator(boolean up) throws IOException { public bookmarkIterator(boolean up) throws IOException {
//flushBookmarkCache(); //XXX: this will cost performance //flushBookmarkCache(); //XXX: this will cost performance
this.bookmarkIter = bookmarksDB.this.bookmarksTable.keys(up, false); this.bookmarkIter = bookmarksDB.this.bookmarksTable.keys(up, false);
this.nextEntry = null; this.nextEntry = null;
} }
public boolean hasNext() { public boolean hasNext() {
try { try {
return this.bookmarkIter.hasNext(); return this.bookmarkIter.hasNext();
@ -1121,6 +1162,7 @@ public class bookmarksDB {
return false; return false;
} }
} }
public Bookmark next() { public Bookmark next() {
try { try {
return getBookmark((String) this.bookmarkIter.next()); return getBookmark((String) this.bookmarkIter.next());
@ -1129,6 +1171,7 @@ public class bookmarksDB {
return null; return null;
} }
} }
public void remove() { public void remove() {
if (this.nextEntry != null) { if (this.nextEntry != null) {
try { try {
@ -1140,21 +1183,24 @@ public class bookmarksDB {
} }
} }
} }
/** /**
* Comparator to sort objects of type Bookmark according to their timestamps * Comparator to sort objects of type Bookmark according to their timestamps
*/ */
public class bookmarkComparator implements Comparator { public class bookmarkComparator implements Comparator<String> {
private boolean newestFirst; private boolean newestFirst;
/** /**
* @param newestFirst newest first, or oldest first? * @param newestFirst newest first, or oldest first?
*/ */
public bookmarkComparator(boolean newestFirst){ public bookmarkComparator(boolean newestFirst){
this.newestFirst=newestFirst; this.newestFirst=newestFirst;
} }
public int compare(Object obj1, Object obj2){
Bookmark bm1=getBookmark((String)obj1); public int compare(String obj1, String obj2) {
Bookmark bm2=getBookmark((String)obj2); Bookmark bm1=getBookmark(obj1);
Bookmark bm2=getBookmark(obj2);
if(bm1==null || bm2==null) if(bm1==null || bm2==null)
return 0; //XXX: i think this should not happen? maybe this needs further tracing of the bug return 0; //XXX: i think this should not happen? maybe this needs further tracing of the bug
if(this.newestFirst){ if(this.newestFirst){
@ -1165,21 +1211,25 @@ public class bookmarksDB {
return -1; return -1;
} }
} }
/** /**
* Comparator to sort objects of type Tag according to their names * Comparator to sort objects of type Tag according to their names
*/ */
public class tagComparator implements Comparator{ public class tagComparator implements Comparator<Tag> {
public int compare(Object obj1, Object obj2){
return ((Tag)obj1).getTagName().compareTo(((Tag)obj2).getTagName()); public int compare(Tag obj1, Tag obj2){
return obj1.getTagName().compareTo(obj2.getTagName());
} }
} }
public class tagSizeComparator implements Comparator{
public int compare(Object obj1, Object obj2){ public class tagSizeComparator implements Comparator<Tag> {
Tag t1 = (Tag)obj1;
Tag t2 = (Tag)obj2; public int compare(Tag obj1, Tag obj2) {
if (t1.size()<t2.size()) return 1; if (obj1.size() < obj2.size()) return 1;
else if (t1.getTagName().equals(t2.getTagName())) return 0; else if (obj1.getTagName().equals(obj2.getTagName())) return 0;
else return -1; else return -1;
} }
} }
} }

@ -147,19 +147,18 @@ public class kelondroMergeIterator<E> implements kelondroCloneableIterator<E> {
throw new java.lang.UnsupportedOperationException("merge does not support remove"); throw new java.lang.UnsupportedOperationException("merge does not support remove");
} }
public static <A> kelondroCloneableIterator<A> cascade(Set<kelondroCloneableIterator<A>> /*of*/ iterators, kelondroOrder<A> c, Method merger, boolean up) { public static <A> kelondroCloneableIterator<A> cascade(Set<kelondroCloneableIterator<A>> iterators, kelondroOrder<A> c, Method merger, boolean up) {
// this extends the ability to combine two iterators // this extends the ability to combine two iterators
// to the abiliy of combining a set of iterators // to the ability of combining a set of iterators
if (iterators == null) return null; if (iterators == null) return null;
if (iterators.size() == 0) return null; if (iterators.size() == 0) return null;
return cascade((Set<kelondroCloneableIterator<A>>) iterators.iterator(), c, merger, up); return cascade(iterators.iterator(), c, merger, up);
} }
@SuppressWarnings("unchecked") private static <A> kelondroCloneableIterator<A> cascade(Iterator<kelondroCloneableIterator<A>> iiterators, kelondroOrder<A> c, Method merger, boolean up) {
private static <A> kelondroCloneableIterator<A> cascade(Iterator<A> /*of*/ iiterators, kelondroOrder<A> c, Method merger, boolean up) {
if (iiterators == null) return null; if (iiterators == null) return null;
if (!(iiterators.hasNext())) return null; if (!(iiterators.hasNext())) return null;
kelondroCloneableIterator<A> one = (kelondroCloneableIterator<A>) iiterators.next(); kelondroCloneableIterator<A> one = iiterators.next();
if (!(iiterators.hasNext())) return one; if (!(iiterators.hasNext())) return one;
return new kelondroMergeIterator<A>(one, cascade(iiterators, c, merger, up), c, merger, up); return new kelondroMergeIterator<A>(one, cascade(iiterators, c, merger, up), c, merger, up);
} }

@ -48,7 +48,6 @@ package de.anomic.plasma;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import de.anomic.kelondro.kelondroAttrSeq; import de.anomic.kelondro.kelondroAttrSeq;
import de.anomic.kelondro.kelondroBase64Order; import de.anomic.kelondro.kelondroBase64Order;
@ -355,12 +354,10 @@ public class plasmaRankingCRProcess {
cr_UDate = cr_entry.getAttr("UDate", 0); cr_UDate = cr_entry.getAttr("UDate", 0);
// loop over all anchors // loop over all anchors
Iterator j = cr_entry.getSeqSet().iterator(); Iterator<String> j = cr_entry.getSeqSet().iterator();
Map.Entry entry;
while (j.hasNext()) { while (j.hasNext()) {
// get domain of anchors // get domain of anchors
entry = (Map.Entry) j.next(); anchor = j.next();
anchor = (String) entry.getKey();
if (anchor.length() == 6) anchorDom = anchor; else anchorDom = anchor.substring(6); if (anchor.length() == 6) anchorDom = anchor; else anchorDom = anchor.substring(6);
// update domain-specific entry // update domain-specific entry
@ -401,22 +398,22 @@ public class plasmaRankingCRProcess {
int size = seq.size(); int size = seq.size();
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
long l; long l;
final Iterator i = seq.keycollections(null, null, false); final Iterator<Object[]> i = seq.keycollections(null, null, false);
Object[] keycollection; Object[] keycollection;
String referee, refereeDom, anchor, anchorDom; String referee, refereeDom, anchor, anchorDom;
kelondroRowSet cr_entry, rci_entry; kelondroRowSet cr_entry, rci_entry;
while (i.hasNext()) { while (i.hasNext()) {
keycollection = (Object[]) i.next(); keycollection = i.next();
referee = new String((byte[]) keycollection[0]); referee = new String((byte[]) keycollection[0]);
if (referee.length() == 6) refereeDom = referee; else refereeDom = referee.substring(6); if (referee.length() == 6) refereeDom = referee; else refereeDom = referee.substring(6);
cr_entry = (kelondroRowSet) keycollection[1]; cr_entry = (kelondroRowSet) keycollection[1];
// loop over all anchors // loop over all anchors
Iterator j = cr_entry.rows(); Iterator<kelondroRow.Entry> j = cr_entry.rows();
kelondroRow.Entry entry; kelondroRow.Entry entry;
while (j.hasNext()) { while (j.hasNext()) {
// get domain of anchors // get domain of anchors
entry = (kelondroRow.Entry) j.next(); entry = j.next();
anchor = (String) entry.getColString(0, null); anchor = (String) entry.getColString(0, null);
if (anchor.length() == 6) anchorDom = anchor; else anchorDom = anchor.substring(6); if (anchor.length() == 6) anchorDom = anchor; else anchorDom = anchor.substring(6);

@ -64,19 +64,19 @@ public class plasmaRankingRCIEvaluation {
public static int[] rcieval(kelondroAttrSeq rci) { public static int[] rcieval(kelondroAttrSeq rci) {
// collect information about which entry has how many references // collect information about which entry has how many references
// the output is a reference-count:occurrences relation // the output is a reference-count:occurrences relation
HashMap counts = new HashMap(); HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
Iterator i = rci.keys(); Iterator<String> i = rci.keys();
String key; String key;
kelondroAttrSeq.Entry entry; kelondroAttrSeq.Entry entry;
Integer count_key, count_count; Integer count_key, count_count;
int c, maxcount = 0; int c, maxcount = 0;
while (i.hasNext()) { while (i.hasNext()) {
key = (String) i.next(); key = i.next();
entry = rci.getEntry(key); entry = rci.getEntry(key);
c = entry.getSeqSet().size(); c = entry.getSeqSet().size();
if (c > maxcount) maxcount = c; if (c > maxcount) maxcount = c;
count_key = new Integer(c); count_key = new Integer(c);
count_count = (Integer) counts.get(count_key); count_count = counts.get(count_key);
if (count_count == null) { if (count_count == null) {
count_count = new Integer(1); count_count = new Integer(1);
} else { } else {
@ -86,7 +86,7 @@ public class plasmaRankingRCIEvaluation {
} }
int[] ctable = new int[maxcount + 1]; int[] ctable = new int[maxcount + 1];
for (int j = 0; j <= maxcount; j++) { for (int j = 0; j <= maxcount; j++) {
count_count = (Integer) counts.get(new Integer(j)); count_count = counts.get(new Integer(j));
if (count_count == null) { if (count_count == null) {
ctable[j] = 0; ctable[j] = 0;
} else { } else {
@ -153,10 +153,11 @@ public class plasmaRankingRCIEvaluation {
return partition.length - 1; return partition.length - 1;
} }
public static TreeSet[] genRankingTable(kelondroAttrSeq rci, int[] partition) { @SuppressWarnings("unchecked")
TreeSet[] ranked = new TreeSet[partition.length]; public static TreeSet<String>[] genRankingTable(kelondroAttrSeq rci, int[] partition) {
for (int i = 0; i < partition.length; i++) ranked[i] = new TreeSet(kelondroBase64Order.enhancedComparator); TreeSet<String>[] ranked = new TreeSet[partition.length];
Iterator i = rci.keys(); for (int i = 0; i < partition.length; i++) ranked[i] = new TreeSet<String>(kelondroBase64Order.enhancedComparator);
Iterator<String> i = rci.keys();
String key; String key;
kelondroAttrSeq.Entry entry; kelondroAttrSeq.Entry entry;
while (i.hasNext()) { while (i.hasNext()) {
@ -167,13 +168,13 @@ public class plasmaRankingRCIEvaluation {
return ranked; return ranked;
} }
public static HashMap genReverseDomHash(File domlist) { public static HashMap<String, String> genReverseDomHash(File domlist) {
HashSet domset = serverFileUtils.loadList(domlist); HashSet<String> domset = serverFileUtils.loadList(domlist);
HashMap dommap = new HashMap(); HashMap<String, String> dommap = new HashMap<String, String>();
Iterator i = domset.iterator(); Iterator<String> i = domset.iterator();
String dom; String dom;
while (i.hasNext()) { while (i.hasNext()) {
dom = (String) i.next(); dom = i.next();
if (dom.startsWith("www.")) dom = dom.substring(4); if (dom.startsWith("www.")) dom = dom.substring(4);
try { try {
dommap.put((new yacyURL("http://" + dom, null)).hash().substring(6), dom); dommap.put((new yacyURL("http://" + dom, null)).hash().substring(6), dom);
@ -183,7 +184,7 @@ public class plasmaRankingRCIEvaluation {
return dommap; return dommap;
} }
public static void storeRankingTable(TreeSet[] ranking, File tablePath) throws IOException { public static void storeRankingTable(TreeSet<String>[] ranking, File tablePath) throws IOException {
String filename; String filename;
if (!(tablePath.exists())) tablePath.mkdirs(); if (!(tablePath.exists())) tablePath.mkdirs();
for (int i = 0; i < ranking.length - 1; i++) { for (int i = 0; i < ranking.length - 1; i++) {
@ -218,7 +219,7 @@ public class plasmaRankingRCIEvaluation {
System.out.println("sum of all references: " + sum); System.out.println("sum of all references: " + sum);
// create ranking // create ranking
TreeSet[] ranked = genRankingTable(rci, partition); TreeSet<String>[] ranked = genRankingTable(rci, partition);
storeRankingTable(ranked, new File(root_path, "ranking/YBR")); storeRankingTable(ranked, new File(root_path, "ranking/YBR"));
long seconds = java.lang.Math.max(1, (System.currentTimeMillis() - start) / 1000); long seconds = java.lang.Math.max(1, (System.currentTimeMillis() - start) / 1000);
System.out.println("Finished YBR generation in " + seconds + " seconds."); System.out.println("Finished YBR generation in " + seconds + " seconds.");
@ -230,7 +231,7 @@ public class plasmaRankingRCIEvaluation {
plasmaSearchRankingProcess.loadYBR(new File(root_path, "ranking/YBR"), 16); plasmaSearchRankingProcess.loadYBR(new File(root_path, "ranking/YBR"), 16);
// load domain list and generate hash index for domains // load domain list and generate hash index for domains
HashMap dommap = genReverseDomHash(new File(root_path, "domlist.txt")); HashMap<String, String> dommap = genReverseDomHash(new File(root_path, "domlist.txt"));
// print out the table // print out the table
String hash, dom; String hash, dom;
@ -238,7 +239,7 @@ public class plasmaRankingRCIEvaluation {
System.out.print("YBR-" + i + ": "); System.out.print("YBR-" + i + ": ");
for (int j = 0; j < plasmaSearchRankingProcess.ybrTables[i].size(); j++) { for (int j = 0; j < plasmaSearchRankingProcess.ybrTables[i].size(); j++) {
hash = new String(plasmaSearchRankingProcess.ybrTables[i].get(j)); hash = new String(plasmaSearchRankingProcess.ybrTables[i].get(j));
dom = (String) dommap.get(hash); dom = dommap.get(hash);
if (dom == null) System.out.print("[" + hash + "], "); else System.out.print(dom + ", "); if (dom == null) System.out.print("[" + hash + "], "); else System.out.print(dom + ", ");
} }
System.out.println(); System.out.println();

Loading…
Cancel
Save