Home » Modeling » Epsilon » Different behavior in remove and removeAll?
Different behavior in remove and removeAll? [message #480871] |
Tue, 18 August 2009 14:05  |
Eclipse User |
|
|
|
Originally posted by: nyoescape.gmail.com
Hi list,
I've noticed that remove and removeAll don't seem to work quite the
same, as in this script:
var seq := Sequence { 0 };
seq.println('before, with number: ');
seq.remove(seq.first());
seq.println('after remove, with number: ');
seq.removeAll(Collection { seq.first() });
seq.println('after removeAll, with number: ');
var seq := Sequence { Sequence { 0 } };
seq.println('before, with nested sequence: ');
seq.remove(seq.first());
seq.println('after remove, with nested sequence: ');
seq.removeAll(Collection { seq.first() });
seq.println('after removeAll, with nested sequence: ');
If I run it, I get:
before, with number: Sequence {0}
after remove, with number: Sequence {0}
after removeAll, with number: Sequence {}
before, with nested sequence: Sequence {Sequence {0}}
after remove, with nested sequence: Sequence {Sequence {0}}
after removeAll, with nested sequence: Sequence {}
If I'm not mistaken, I believe that the expected behaviour would be for
both sequences to be empty right after the remove, so removeAll wouldn't
really have to remove anything.
By the way: I thought about using a Native('java.util.LinkedList') to
work around this issue (it also has more convenient methods, such as
removeFirst and getFirst), but no matter what I do, Epsilon seems to
convert it back to an EolCollection. Is there any way I can avoid that
implicit conversion?
Cheers,
Antonio
|
|
| | | |
Re: Different behavior in remove and removeAll? [message #481005 is a reply to message #480913] |
Wed, 19 August 2009 06:36  |
Eclipse User |
|
|
|
Hi Antonio,
Antonio García Domínguez wrote:
> Hi Dimitris,
>
> OK, I've reported it. Here is the link:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=286992
Thanks!
>
> Well, as for the conversion: would it work if I wrapped whatever
> collection class I wanted to use within another class which did not
> implement the Collection interface? It's an ugly hack and I don't need
> it anymore, as I've rewritten the code to avoid using remove and
> removeAll, but I'm curious.
>
That should work indeed - if one is that desperate :)
> Cheers,
> Antonio
Cheers,
Dimitris
|
|
|
Re: Different behavior in remove and removeAll? [message #574398 is a reply to message #480871] |
Tue, 18 August 2009 14:34  |
Eclipse User |
|
|
|
Hi again,
Now I'm really confused. There appear to be other times when remove gets
it right and removeAll doesn't. This EOL script loops forever when
use_remove is false, and finishes properly when use_remove is true. I
believe this script should work the same either way, if I'm not mistaken.
var use_remove := true;
var seq := new Sequence;
seq.add(Sequence {0});
seq.add(Sequence {1});
while (seq.notEmpty()) {
seq.println('elements: ');
var elem := seq.first();
if (use_remove) {
seq.remove(elem);
} else {
seq.removeAll(Collection { elem });
}
}
Cheers,
Antonio
|
|
|
Re: Different behavior in remove and removeAll? [message #574422 is a reply to message #480884] |
Tue, 18 August 2009 15:46  |
Eclipse User |
|
|
|
Hi Antonio,
I've reproduced this; it is definitely a bug. Could you please file a
bug report? Regarding the conversion from LinkedList to EolCollection,
I'm afraid there is currently no way to avoid it.
Cheers,
Dimitris
Antonio García Domínguez wrote:
> Hi again,
>
> Now I'm really confused. There appear to be other times when remove gets
> it right and removeAll doesn't. This EOL script loops forever when
> use_remove is false, and finishes properly when use_remove is true. I
> believe this script should work the same either way, if I'm not mistaken.
>
> var use_remove := true;
>
> var seq := new Sequence;
> seq.add(Sequence {0});
> seq.add(Sequence {1});
>
> while (seq.notEmpty()) {
> seq.println('elements: ');
> var elem := seq.first();
> if (use_remove) {
> seq.remove(elem);
> } else {
> seq.removeAll(Collection { elem });
> }
> }
>
> Cheers,
> Antonio
|
|
| |
Re: Different behavior in remove and removeAll? [message #574498 is a reply to message #480913] |
Wed, 19 August 2009 06:36  |
Eclipse User |
|
|
|
Hi Antonio,
Antonio García Domínguez wrote:
> Hi Dimitris,
>
> OK, I've reported it. Here is the link:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=286992
Thanks!
>
> Well, as for the conversion: would it work if I wrapped whatever
> collection class I wanted to use within another class which did not
> implement the Collection interface? It's an ugly hack and I don't need
> it anymore, as I've rewritten the code to avoid using remove and
> removeAll, but I'm curious.
>
That should work indeed - if one is that desperate :)
> Cheers,
> Antonio
Cheers,
Dimitris
|
|
|
Goto Forum:
Current Time: Wed Jul 23 03:23:58 EDT 2025
Powered by FUDForum. Page generated in 0.48918 seconds
|