You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Morgan Delagrange <md...@yahoo.com> on 2002/02/14 23:56:06 UTC

[Collections] Comment on LRUMap.removeLRU()

Seems like an odd method (besides the fact that it didn't actually work
until this week ;)  It returns the key of the Object that was removed from
the Map.  Don't you think it should return both the key and the value,
perhaps as an Object[] array?  After all, you have no way to use that key;
the value is already gone.

Technically, there's nothing we can do about it until Collections 2.x, but
maybe in the Javadocs we should announce an intention to deprecate it for a
more appropriate call?

- Morgan


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [Collections] Comment on LRUMap.removeLRU()

Posted by Michael Smith <mi...@iammichael.org>.
> Someone could have fixed it locally.  It's only a 2 character change.

good point.

> > Another option that might be useful is to add a protected 
> method, taking
> > both the key and value as arguments, that's called when an 
> element is
> > removed.  Rather than having subclasses override the 
> "removeLRU" method,
> > they would override this method and process it appropriately.
> >
> > For example:
> >
> > protected void processRemovedLRU(Object key, Object value) {
> > }
> >
> > This might actually be safer for subclasses since they 
> don't actually need
> > to do the remove.
> 
> That's a possibility.  You would still need to provide a 
> replacement for the
> public method, unless it's no longer necessary.  Personally I 
> didn't see a
> need for it except in subclassing, once I patched the class to use
> removeLRU() internally.

public Map.Entry getLeastRecentlyUsed() {
...
}

public Object getLeastRecentlyUsedKey() {
...
}

That should be enough to allow a "public" replacement:

map.remove(map.getLeastRecentlyUsedKey());

or

Map.Entry lru = map.getLeastRecentlyUsed();
map.remove(lru.getKey());

If you want to maintain that particular API:

public Object removeLRU() {
  // use this, or a smarter implementation that uses the internals.
  Map.Entry lru = this.getLeastRecentlyUsed();
  this.remove(lru.getKey());

  // return the key as per current impl
  return lru.getKey();

  // or return the Map.Entry which makes more sense
  //return lru;
}

regards,
michael


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Collections] Comment on LRUMap.removeLRU()

Posted by Morgan Delagrange <md...@yahoo.com>.
----- Original Message -----
From: "Michael A. Smith" <mi...@iammichael.org>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>;
"Morgan Delagrange" <mo...@apache.org>
Sent: Thursday, February 14, 2002 5:12 PM
Subject: Re: [Collections] Comment on LRUMap.removeLRU()


> On Thu, 14 Feb 2002, Morgan Delagrange wrote:
>
> > ----- Original Message -----
> > From: "Morgan Delagrange" <md...@yahoo.com>
> > To: "Jakarta Commons Developers" <co...@jakarta.apache.org>
> > Sent: Thursday, February 14, 2002 4:56 PM
> > Subject: [Collections] Comment on LRUMap.removeLRU()
> >
> >
> > > Seems like an odd method (besides the fact that it didn't actually
work
> > > until this week ;)  It returns the key of the Object that was removed
from
> > > the Map.  Don't you think it should return both the key and the value,
> > > perhaps as an Object[] array?  After all, you have no way to use that
key;
> > > the value is already gone.
>
> Why not Map.Entry?  :)

Oh yeah, that probably works.  :)

>
> > >
> > > Technically, there's nothing we can do about it until Collections 2.x,
but
> > > maybe in the Javadocs we should announce an intention to deprecate it
for
> > a
> > > more appropriate call?
> > >
> >
> > Correction.  We could actually deprecate it now and provide an
alternative
> > for the 1.1 release.  Any reason not to?
>
> Don't think so, as long as the deprecated method remains supported through
> 1.x.  Although if it didn't work until this week, I doubt anyone was
> using/relying on it in the first place.

Someone could have fixed it locally.  It's only a 2 character change.

>
> Another option that might be useful is to add a protected method, taking
> both the key and value as arguments, that's called when an element is
> removed.  Rather than having subclasses override the "removeLRU" method,
> they would override this method and process it appropriately.
>
> For example:
>
> protected void processRemovedLRU(Object key, Object value) {
> }
>
> This might actually be safer for subclasses since they don't actually need
> to do the remove.

That's a possibility.  You would still need to provide a replacement for the
public method, unless it's no longer necessary.  Personally I didn't see a
need for it except in subclassing, once I patched the class to use
removeLRU() internally.

> Aaron Smuts has a similar method in his LRU cache in Stratum, but his only
> takes one argument (an Object, but it looks like the object that is passed
> in is an ILRUElement, which is very similar to a Map.Entry).  He named his
> "waterfall".
>
>
http://cvs.apache.org/viewcvs.cgi/jakarta-turbine-stratum/src/java/org/apach
e/stratum/util/lru/LRUStore.java?rev=1.1&content-type=text/vnd.viewcvs-marku
p
>
>
> regards,
> Michael
>
>



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Collections] Comment on LRUMap.removeLRU()

Posted by "Michael A. Smith" <mi...@iammichael.org>.
On Thu, 14 Feb 2002, Morgan Delagrange wrote:

> ----- Original Message -----
> From: "Morgan Delagrange" <md...@yahoo.com>
> To: "Jakarta Commons Developers" <co...@jakarta.apache.org>
> Sent: Thursday, February 14, 2002 4:56 PM
> Subject: [Collections] Comment on LRUMap.removeLRU()
> 
> 
> > Seems like an odd method (besides the fact that it didn't actually work
> > until this week ;)  It returns the key of the Object that was removed from
> > the Map.  Don't you think it should return both the key and the value,
> > perhaps as an Object[] array?  After all, you have no way to use that key;
> > the value is already gone.

Why not Map.Entry?  :)

> >
> > Technically, there's nothing we can do about it until Collections 2.x, but
> > maybe in the Javadocs we should announce an intention to deprecate it for
> a
> > more appropriate call?
> >
> 
> Correction.  We could actually deprecate it now and provide an alternative
> for the 1.1 release.  Any reason not to?

Don't think so, as long as the deprecated method remains supported through 
1.x.  Although if it didn't work until this week, I doubt anyone was 
using/relying on it in the first place.  


Another option that might be useful is to add a protected method, taking
both the key and value as arguments, that's called when an element is
removed.  Rather than having subclasses override the "removeLRU" method, 
they would override this method and process it appropriately.  

For example:

protected void processRemovedLRU(Object key, Object value) {
}

This might actually be safer for subclasses since they don't actually need 
to do the remove.  

Aaron Smuts has a similar method in his LRU cache in Stratum, but his only
takes one argument (an Object, but it looks like the object that is passed
in is an ILRUElement, which is very similar to a Map.Entry).  He named his
"waterfall".

http://cvs.apache.org/viewcvs.cgi/jakarta-turbine-stratum/src/java/org/apache/stratum/util/lru/LRUStore.java?rev=1.1&content-type=text/vnd.viewcvs-markup


regards,
Michael


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Collections] Comment on LRUMap.removeLRU()

Posted by Morgan Delagrange <md...@yahoo.com>.
----- Original Message -----
From: "Morgan Delagrange" <md...@yahoo.com>
To: "Jakarta Commons Developers" <co...@jakarta.apache.org>
Sent: Thursday, February 14, 2002 4:56 PM
Subject: [Collections] Comment on LRUMap.removeLRU()


> Seems like an odd method (besides the fact that it didn't actually work
> until this week ;)  It returns the key of the Object that was removed from
> the Map.  Don't you think it should return both the key and the value,
> perhaps as an Object[] array?  After all, you have no way to use that key;
> the value is already gone.
>
> Technically, there's nothing we can do about it until Collections 2.x, but
> maybe in the Javadocs we should announce an intention to deprecate it for
a
> more appropriate call?
>

Correction.  We could actually deprecate it now and provide an alternative
for the 1.1 release.  Any reason not to?

- Morgan


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>