Closed GoogleCodeExporter closed 9 years ago
AtomicObservableEventList has been created: overrides addAll and clear methods
(just
do something before and after effectively adding or removing):
e.j.:
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public boolean addAll(int index, Collection values) {
Assert.notNull(values, "values");
final int startIndex = index;
final int endIndex = startIndex + values.size() - 1;
// [1] Force begin events (this will increase "event level" counts and delay
commits after [3])
this.beforeOperation(startIndex, endIndex, ListEvent.INSERT);
try {
// [2] Call super (no event will be published)
return super.addAll(index, values);
} catch (RuntimeException e) {
throw e; // If an exception ocurred then rethrow it but restoring initial
state [3]
} finally {
// [3] Force commits (this will decrease initially increased "event
level" counts [1] and force commits)
this.afterOperation(startIndex, endIndex, ListEvent.INSERT);
}
}
Original comment by julioarg...@gmail.com
on 3 May 2010 at 7:30
Also exists a problem when dealing with deep copy, see explanation below:
/**
* Prepare the backing collection for installation into the
<code>ListListModel</code>. Create a new collection that
* contains a deep copy of the given collection.
* <p>
* Replaces original implementation due to performance reasons:
* <ul>
* <li>On one hand suppose the following case, where a <em>parent entity</em>
(<code>Parent</code>) has a
* bidirectional relation with a <em>child entity</em> ( <code>Child</code>):
*
* <pre>
* parent <---> child_1
* |
* ^
* +--> child_2
* ^
* +--> child_3
* |
* .
* .
* .
* ^
* +--> child_N
* </pre>
*
* <li>On the other hand find attached the old implementation:
*
* <pre>
* ArrayList list = new ArrayList(col);
* for (int i = 0; i < list.size(); i++) {
* list.set(i, deepCopy(list.get(i)));
* }
* return list;
* </pre>
*
* </ul>
*
* While trying to show the case above, old implementation would create
<code>(N+1)*N</code> objects, due to deep
* copy iteration and probably would cause an <code>OutOfMemory</code> error.
However employing a single deep copy
* the number of new objects is <code>N+1</code>.
*
* <pre>
* return (Collection<?>) SerializationUtils.clone(new
ArrayList<T>((Collection<T>) col));
* </pre>
*
* @param col
* the collection of objects to process.
* @return the processed collection.
*/
@SuppressWarnings("unchecked")
@Override
protected Collection<?> prepareBackingCollection(Collection col) {
return (Collection<?>) SerializationUtils.clone(new
ArrayList<T>((Collection<T>) col));
}
Original comment by julioarg...@gmail.com
on 3 May 2010 at 7:31
This are source files:
http://code.google.com/p/bluebell/source/browse/trunk/bluebell-
richclient/src/main/java/org/bluebell/binding/value/support/DirtyTrackingDCBCVM.
java
http://code.google.com/p/bluebell/source/browse/trunk/bluebell-
richclient/src/main/java/org/bluebell/binding/value/support/DirtyTrackingDCBCVM.
java
Original comment by julioarg...@gmail.com
on 3 May 2010 at 7:33
Original issue reported on code.google.com by
julioarg...@gmail.com
on 3 May 2010 at 7:27