sorted by timestamps

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

@ -37,7 +37,7 @@ Tagged with #[tags]#. <br />
#(/next-page)#
&nbsp;
</td>
<td>
<td valign="top">
<a href="Bookmarks_p.html">All</a><br />
#{tags}#
<a href="Bookmarks_p.html?tag=#[name]#">#[name]#</a><br />

@ -82,6 +82,7 @@ public class Bookmarks_p {
if(bookmark != null){
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_TITLE, title);
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_PUBLIC, (String) post.get("public"));
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
bookmark.setTags(tags);
bookmark.setBookmarksTable();
}else{
@ -107,18 +108,10 @@ public class Bookmarks_p {
}
prop.put("tags", count);
count=0;
boolean viewTag=false;
if(!tag.equals("")){
tagUrlHashes=switchboard.bookmarksDB.getTag(tag).getUrlHashes();
if(tagUrlHashes != null){
it=tagUrlHashes.iterator();
viewTag=true;
}else{ //tag does not exist
//TODO: Errorpage?
it=switchboard.bookmarksDB.bookmarkIterator(true);
}
it=switchboard.bookmarksDB.getBookmarksIterator(tag);
}else{
it=switchboard.bookmarksDB.bookmarkIterator(true);
it=switchboard.bookmarksDB.getBookmarksIterator();
}
bookmarksDB.Bookmark bookmark;
//skip the first entries (display next page)
@ -129,11 +122,7 @@ public class Bookmarks_p {
}
count=0;
while(count<MAX_COUNT && it.hasNext()){
if(viewTag){
bookmark=switchboard.bookmarksDB.getBookmark((String)it.next());
}else{
bookmark=(Bookmark) it.next();
}
bookmark=switchboard.bookmarksDB.getBookmark((String)it.next());
if(bookmark!=null){
prop.put("bookmarks_"+count+"_link", bookmark.getUrl());
prop.put("bookmarks_"+count+"_title", bookmark.getTitle());

@ -44,10 +44,13 @@ package de.anomic.data;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import de.anomic.kelondro.kelondroDyn;
@ -161,6 +164,22 @@ public class bookmarksDB {
return null;
}
}
public Iterator getBookmarksIterator(){
TreeSet set=new TreeSet(new bookmarkComparator());
Iterator it=bookmarkIterator(true);
Bookmark bm;
while(it.hasNext()){
bm=(Bookmark)it.next();
set.add(bm.getUrlHash());
}
return set.iterator();
}
public Iterator getBookmarksIterator(String tag){
TreeSet set=new TreeSet(new bookmarkComparator());
Vector hashes=getTag(tag).getUrlHashes();
set.addAll(hashes);
return set.iterator();
}
public void removeBookmark(String urlHash){
Bookmark bookmark = getBookmark(urlHash);
if(bookmark == null) return; //does not exist
@ -250,9 +269,16 @@ public class bookmarksDB {
}
public void setTagsTable(){
try {
bookmarksDB.this.tagsTable.set(getTagName(), mem);
if(this.size() >0){
bookmarksDB.this.tagsTable.set(getTagName(), mem);
}else{
bookmarksDB.this.tagsTable.remove(getTagName());
}
} catch (IOException e) {}
}
public int size(){
return ((String)this.mem.get(URL_HASHES)).length();
}
}
/**
* Subclass, which stores the bookmark
@ -263,6 +289,7 @@ public class bookmarksDB {
public static final String BOOKMARK_TITLE="bookmarkTitle";
public static final String BOOKMARK_TAGS="bookmarkTags";
public static final String BOOKMARK_PUBLIC="bookmarkPublic";
public static final String BOOKMARK_TIMESTAMP="bookmarkTimestamp";
private String urlHash;
private Map mem;
public Bookmark(String urlHash, Map map){
@ -337,6 +364,13 @@ public class bookmarksDB {
bookmarksDB.this.bookmarksTable.set(getUrlHash(), mem);
} catch (IOException e) {}
}
public long getTimeStamp(){
if(mem.containsKey(BOOKMARK_TIMESTAMP)){
return Long.parseLong((String)mem.get(BOOKMARK_TIMESTAMP));
}else{
return 0;
}
}
}
public class tagIterator implements Iterator{
kelondroDyn.dynKeyIterator tagIter;
@ -406,4 +440,15 @@ public class bookmarksDB {
}
}
}
/**
* Comparator to sort the Bookmarks with Timestamps
*/
public class bookmarkComparator implements Comparator{
public int compare(Object obj1, Object obj2){
Bookmark bm1=getBookmark((String)obj1);
Bookmark bm2=getBookmark((String)obj2);
//TODO: what happens, if there is a big difference? (to much for int)
return (new Long(bm1.getTimeStamp() - bm2.getTimeStamp())).intValue();
}
}
}

Loading…
Cancel
Save