From f503df04f85a78a0494957b197e1bef2ffff47f0 Mon Sep 17 00:00:00 2001 From: allo Date: Fri, 17 Feb 2006 18:14:11 +0000 Subject: [PATCH] sort the Bookmarks with newest First. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1686 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/data/bookmarksDB.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java index ceab097ce..5809c8368 100644 --- a/source/de/anomic/data/bookmarksDB.java +++ b/source/de/anomic/data/bookmarksDB.java @@ -327,7 +327,7 @@ public class bookmarksDB { } } public Iterator getBookmarksIterator(boolean priv){ - TreeSet set=new TreeSet(new bookmarkComparator()); + TreeSet set=new TreeSet(new bookmarkComparator(true)); Iterator it=bookmarkIterator(true); Bookmark bm; while(it.hasNext()){ @@ -339,7 +339,7 @@ public class bookmarksDB { return set.iterator(); } public Iterator getBookmarksIterator(String tagName, boolean priv){ - TreeSet set=new TreeSet(new bookmarkComparator()); + TreeSet set=new TreeSet(new bookmarkComparator(true)); String tagHash=tagHash(tagName); Tag tag=getTag(tagHash); Vector hashes=new Vector(); @@ -843,11 +843,23 @@ public class bookmarksDB { * Comparator to sort the Bookmarks with Timestamps */ public class bookmarkComparator implements Comparator{ + + private boolean newestFirst; + /** + * @param newestFirst newest first, or oldest first? + */ + public bookmarkComparator(boolean newestFirst){ + this.newestFirst=newestFirst; + } 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(); + //XXX: what happens, if there is a big difference? (to much for int) + if(this.newestFirst){ + return (new Long(bm2.getTimeStamp() - bm1.getTimeStamp())).intValue(); + }else{ + return (new Long(bm1.getTimeStamp() - bm2.getTimeStamp())).intValue(); + } } } /**