Hmmm
* Ordered
* No duplicates
* Max Size
<icky>
Buffer boundedBuffer = new BoundedFifoBuffer(10);
Predicate uniqueness = new UniquePredicate();
Buffer buffer = new PredicatedBuffer( boundedBuffer, uniqueness );
</icky>
Then you can iterate over the content's of the Buffer. But, that might
not work exactly as you want it because the Bounded FIFO buffer will
discard things, but the UniquePredicate won't allow duplicates into the
List. You could write your own Predicate that looks at the contents of
the Buffer on each add(), only succesfully adding if
So,
public class UniqueInCollection implements Predicate {
private Collection collection;
public UniqueInCollection(Collection collection) {
this.collection = collection;
}
public void evaluate(Object o) {
return !collection.contains( o );
}
}
Buffer boundedBuffer = new BoundedFifoBuffer( 10 );
Predicate uniqueness = new UniqueInCollection( boundedBuffer );
Buffer buffer = new PredicatedBuffer( boundedBuffer, uniqueness );
// add stuff to it, buffer will take care of discarding stuff automagically
Then to iterate, do what you would normally do, buffer.iterator();
Wendy Smoak wrote:
I'm looking through the Collections API, but not finding exactly what
I want... hoping someone who's more familiar with it can point me in
the right direction.
What I'm trying to do is more or less what you see on catalog sites
where they'll list the most recent items you've looked at, newest on
top. So it's ordered (List), but has no duplicates (Set), and I need
to have a max size.
ListOrderedSet is almost there, except that it retains the 'old'
position if you add the same item again. (And has no max length.)
So... before I either write it myself or extend ListOrderedSet to make
it do what I want, does anyone have another suggestion? And what
would _you_ call it?
Thanks,
Wendy Smoak
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]