Home » Modeling » Epsilon » Different behavior in remove and removeAll?
Different behavior in remove and removeAll? [message #480871] |
Tue, 18 August 2009 18: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 #480884 is a reply to message #480871] |
Tue, 18 August 2009 18:34 |
Eclipse User |
|
|
|
Originally posted by: nyoescape.gmail.com
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 #574398 is a reply to message #480871] |
Tue, 18 August 2009 18:34 |
|
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
|
|
| | | |
Goto Forum:
Current Time: Fri Mar 29 07:18:44 GMT 2024
Powered by FUDForum. Page generated in 0.04801 seconds
|