commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <ja...@carmanconsulting.com>
Subject RE: [collections] reference counting
Date Thu, 07 Jul 2005 18:58:58 GMT
Nope.  The remove(Object o) method removes ALL occurrences of the object
from the Bag.  There is a remove(Object o, int nCopies) method available
that you might want to try (using a value of 1 of course).  Hope that helps.

-----Original Message-----
From: Torsten Curdt [mailto:tcurdt@apache.org] 
Sent: Thursday, July 07, 2005 2:57 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] reference counting

Torsten Curdt wrote:
>>Are you thinking of a Bag?
> 
> 
> Doh! That's it ...thanks :)

Hm...

    org.apache.commons.collections.bag.HashBag bag
     = new org.apache.commons.collections.bag.HashBag();
    bag.add("a");
    System.out.println(bag.getCount("a"));
    bag.add("a");
    System.out.println(bag.getCount("a"));
    bag.remove("a");
    System.out.println(bag.getCount("a"));
    bag.remove("a");
    System.out.println(bag.getCount("a"));

gives

1
2
0
0

but I'd expect

1
2
1
0

this is because the remove(obj) is not
delegating to a remove(obj,1) but is
a full remove. ...so I have to extend
that class.

IMO having

 remove(obj) -> remove(obj,1)
 removeAll(obj)
 removeAll()

would make more sense.

My 2 cents

cheers
--
Torsten


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message