You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2019/10/28 18:42:29 UTC

[lang] immutable BitSet

Hi All,

Any thoughts for or against adding an ImmutableBitSet as a subclass
of BitSet?

It would throw an exception on attempt to mutate.

I can then be used to define an EMPTY_BITSET constant.

I could also be used in some of our methods that return a new empty bit
set, if appropriate of course.

Gary

Re: [lang] immutable BitSet

Posted by Gilles Sadowski <gi...@gmail.com>.
Hello.

2019-10-29 0:16 UTC+01:00, Claude Warren <cl...@xenei.com>:
> Having "ImmutableBitSet" inherit from "BitSet" breaks the latter's
> contract.
>>
>>
> no more

Yes, more, AFAICT...

> so than the ImmutableSet breaks the Set contract.

... because "Set" is an interface whose contract explicitly mentions
some operations as "optional".  Not so for the "BitSet" class.

> Yes it does but
> the pattern is well established.

There will be practical problems (e.g. if the upstream class adds a mutating
method, not yet overridden by this extension).

Immutability cannot be added after the fact.

Regards,
Gilles

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


Re: [lang] immutable BitSet

Posted by Claude Warren <cl...@xenei.com>.
Having "ImmutableBitSet" inherit from "BitSet" breaks the latter's contract.
>
>
no more so than the ImmutableSet breaks the Set contract.  Yes it does but
the pattern is well established.


-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: [lang] immutable BitSet

Posted by Gilles Sadowski <gi...@gmail.com>.
Hi.

2019-10-28 20:38 UTC+01:00, Xeno Amess <xe...@gmail.com>:
> Then all ImmutableBitSet instance are instance of a mutable BitSet class
> when we use instance of.
> I just worry that could be kind of misleading sometimes.
>

I agree with that remark.
Having "ImmutableBitSet" inherit from "BitSet" breaks the latter's contract.

Regards,
Gilles

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


Re: [lang] immutable BitSet

Posted by Xeno Amess <xe...@gmail.com>.
Then all ImmutableBitSet instance are instance of a mutable BitSet class
when we use instance of.
I just worry that could be kind of misleading sometimes.


Gary Gregory <ga...@gmail.com> 于 2019年10月29日周二 上午3:29写道:

> On Mon, Oct 28, 2019 at 3:16 PM Xeno Amess <xe...@gmail.com> wrote:
>
> > then it is better to make a AbstractBitSet abstract class?and two sub
> > classes MutableBitSet and ImmutableBitSet...
> >
>
> Why would you need that? The JRE already has a BitSet class. The idea is to
> reuse it, hence the new Lang immutable type extending the existing JRE
> mutable one. I do not think we need to reinvent the wheel here.
>
> Gary
>
>
> > ?? Outlook for Android<https://aka.ms/ghei36>
> >
> > ________________________________
> > From: Gary Gregory <ga...@gmail.com>
> > Sent: Tuesday, October 29, 2019 2:42:29 AM
> > To: Commons Developers List <de...@commons.apache.org>
> > Subject: [lang] immutable BitSet
> >
> > Hi All,
> >
> > Any thoughts for or against adding an ImmutableBitSet as a subclass
> > of BitSet?
> >
> > It would throw an exception on attempt to mutate.
> >
> > I can then be used to define an EMPTY_BITSET constant.
> >
> > I could also be used in some of our methods that return a new empty bit
> > set, if appropriate of course.
> >
> > Gary
> >
>

Re: [lang] immutable BitSet

Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Oct 28, 2019 at 3:16 PM Xeno Amess <xe...@gmail.com> wrote:

> then it is better to make a AbstractBitSet abstract class?and two sub
> classes MutableBitSet and ImmutableBitSet...
>

Why would you need that? The JRE already has a BitSet class. The idea is to
reuse it, hence the new Lang immutable type extending the existing JRE
mutable one. I do not think we need to reinvent the wheel here.

Gary


> ?? Outlook for Android<https://aka.ms/ghei36>
>
> ________________________________
> From: Gary Gregory <ga...@gmail.com>
> Sent: Tuesday, October 29, 2019 2:42:29 AM
> To: Commons Developers List <de...@commons.apache.org>
> Subject: [lang] immutable BitSet
>
> Hi All,
>
> Any thoughts for or against adding an ImmutableBitSet as a subclass
> of BitSet?
>
> It would throw an exception on attempt to mutate.
>
> I can then be used to define an EMPTY_BITSET constant.
>
> I could also be used in some of our methods that return a new empty bit
> set, if appropriate of course.
>
> Gary
>

Re: [lang] immutable BitSet

Posted by Xeno Amess <xe...@gmail.com>.
then it is better to make a AbstractBitSet abstract class?and two sub classes MutableBitSet and ImmutableBitSet...

?? Outlook for Android<https://aka.ms/ghei36>

________________________________
From: Gary Gregory <ga...@gmail.com>
Sent: Tuesday, October 29, 2019 2:42:29 AM
To: Commons Developers List <de...@commons.apache.org>
Subject: [lang] immutable BitSet

Hi All,

Any thoughts for or against adding an ImmutableBitSet as a subclass
of BitSet?

It would throw an exception on attempt to mutate.

I can then be used to define an EMPTY_BITSET constant.

I could also be used in some of our methods that return a new empty bit
set, if appropriate of course.

Gary