Re: JMIUNDO SPI 0.2
Brian Smith <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.mdr.devel |
|---|---|
| Organization | CollabNet Hosting |
| Message-ID | <[email protected]> |
Brian Smith wrote:
>
> // ... TestClass tc = ...;
> Collection c = tc.getUntrackable().clone();
> // ... change c as you wish
> tc.setUntrackable(c);
Okay, I wasn't thinking: clone() will probably return another immutable
collection :(. So, let me try again. Let's say that c.untrackable
contains { { 'Hello', 'Holger' }, { 'I', 'love', 'undo' } } and you want
to change the 'Hello' to 'Goodbye'. Then you would have to do something
like (untested):
// a is a mutable list of immutable collections
ArrayList a = new ArrayList(tc.getUntrackable());
ArrayList a0 = new ArrayList((Collection) a.get(0));
a0.set(0, "Goodbye"); // replace 'Hello' with 'Goodbye'
// replace { 'Hello', 'Holger' } with { 'Goodbye', 'Holger' }
a.set(0, a0);
tc.setUntrackable(a); // This will make an immutable deep copy of a
Notice that there are 2+3 copies of collections being made during this
operation: we made two copies ourselves and tc.setUntrackable(a) made up
to three copies (likely, at least two).
- Brian