On Tuesday 28 October 2008 17:41, [EMAIL PROTECTED] wrote: > Author: xor > Date: 2008-10-28 17:41:52 +0000 (Tue, 28 Oct 2008) > New Revision: 23153 > > Modified: > trunk/plugins/FMSPlugin/FMSBoard.java > Log: > Implementation. > > Modified: trunk/plugins/FMSPlugin/FMSBoard.java > =================================================================== > --- trunk/plugins/FMSPlugin/FMSBoard.java 2008-10-28 13:41:14 UTC (rev 23152) > +++ trunk/plugins/FMSPlugin/FMSBoard.java 2008-10-28 17:41:52 UTC (rev 23153) > @@ -3,14 +3,27 @@ > * http://www.gnu.org/ for further details of the GPL. */ > package plugins.FMSPlugin; > > +import java.util.Collections; > +import java.util.Hashtable; > import java.util.Iterator; > +import java.util.LinkedList; > +import java.util.NoSuchElementException; > > +import freenet.keys.FreenetURI; > + > /** > * @author xor > * > */ > public class FMSBoard { > > + private final FMSBoard self = this; > + /* > + * FIXME: We need a datastructure which is a HashTable and a LinkedList which is sorted by Date of the messages. > + * java.util.LinkedHashSet is the right thing but it does not provide sorting. > + */ > + private final Hashtable<FreenetURI, FMSMessage> mMessages = new HashTable<FreenetURI, FMSMessage>(); > + private final LinkedList<FMSMessage> mMessagesSorted = new LinkedList<FMSMessage>();
Does LinkedList? Only because you add stuff at the right end. LinkedHashSet
can do the same thing, and can be used to implement LRU's for example. Read
the docs more carefully.
> private final FMSMessageManager mMessageManager;
> private final String mName;
> private String mDescription;
> @@ -19,6 +32,7 @@
> if(newName==null || newName.isEmpty())
> throw new IllegalArgumentException("Empty board name.");
>
> +
> assert(newMessageManager != null);
> mMessageManager = newMessageManager;
> // FIXME: Remove anything dangerous from name and description.
> @@ -53,8 +67,32 @@
> * @param identity The identity viewing the board.
> * @return An iterator of the message which the identity will see
> (based
on its trust levels).
> */
> - public Iterator<FMSMessage> messageIterator(FMSOwnIdentity identity) {
> - return mMessageManager.messageIterator(identity);
> + public synchronized Iterator<FMSMessage> messageIterator(final
FMSOwnIdentity identity) {
> + return new Iterator<FMSMessage>() {
> + private final FMSOwnIdentity mIdentity = identity;
> + private Iterator<FMSMessage> iter =
> self.mMessagesSorted.iterator();
> + private FMSMessage next = iter.hasNext() ? iter.next()
> : null;
> +
> + public boolean hasNext() {
> + for(; next != null; next = iter.hasNext() ?
> iter.next() : null)
> + {
> +
> if(mIdentity.wantsMessagesFrom(identity))
> + return true;
> + }
> + return false;
> + }
> +
> + public FMSMessage next() {
> + FMSMessage result = hasNext() ? next : null;
> + next = iter.hasNext() ? iter.next() : null;
> + return result;
> + }
> +
> + public void remove() {
> + throw new UnsupportedOperationException();
> + }
> +
> + }
> }
>
> }
>
> _______________________________________________
> cvs mailing list
> [EMAIL PROTECTED]
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>
>
pgpTR4eDT1Qey.pgp
Description: PGP signature
_______________________________________________ Devl mailing list [email protected] http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl
