Re: BitSet Class Implementation
- From: dagon@xxxxxxxxx (Mark Rafn)
- Date: Sun, 19 Nov 2006 20:18:58 -0800
Erick Crouse <crouse@xxxxxxxxxxxxxx> wrote:
I need a question answered concerning the BitSet class. The problem is
that the public methods which manipulate a set of bits requires a
BitSet object as both the caller and argument to the method...
private BitSet A = new BitSet(16),
private BitSet B = new BitSet(16),
// do some manipulations with BitSet... and then...
A.and(B); // Results in a different A (B is unchanged)
A.xor(B); // Again results in a different A (B is unchanged)
Right. That's how it works.
The problem with this is that I prefer both A and B BitSet objects
remain the same while resulting in a new BitSet object say C using an
interface similar to -> public BitSet and( BitSet A, BitSet B) -
BitSet.
something like:
public static BitSet andBitSets(BitSet A, BitSet B) {
BitSet retval = (BitSet)A.clone();
retval.and(B);
return retval;
}
With the current implementation of BitSet I would need to do
some sort of clone implementation (which seems like overkill)
BitSet implements Clonable. You don't need to do anything but call it.
Can anyone suggest what they would do in this situation where the
implementation operates either operand?
Use clone() as intended. This works just fine.
--
Mark Rafn dagon@xxxxxxxxx <http://www.dagon.net/>
.
- References:
- BitSet Class Implementation
- From: Erick Crouse
- BitSet Class Implementation
- Prev by Date: Bogus behavior of window listeners
- Next by Date: Re: Giving an application a window icon in a sensible way
- Previous by thread: Re: BitSet Class Implementation
- Next by thread: Couple java.net questions
- Index(es):
Relevant Pages
|