RenderingHints oldHints,
ParameterBlock newParamBlock,
RenderingHints newHints,
CollectionImage oldRendering,
CollectionOp op) {
CollectionImage updatedCollection = null;
if(oldParamBlock.getObjectParameter(0).equals(newParamBlock.getObjectParameter(0)) &&
(oldHints == null ? newHints == null : oldHints.equals(newHints))) {
// Retrieve the old and new sources and the parameters.
Collection oldSource = (Collection)oldParamBlock.getSource(0);
Collection newSource = (Collection)newParamBlock.getSource(0);
double[] constants = (double[])oldParamBlock.getObjectParameter(0);
// Construct a Collection of common sources.
Collection commonSources = new ArrayList();
Iterator it = oldSource.iterator();
while(it.hasNext()) {
Object oldElement = it.next();
if(newSource.contains(oldElement)) {
commonSources.add(oldElement);
}
}
if(commonSources.size() != 0) {
// Construct a Collection of the RenderedOp nodes that
// will be retained in the new CollectionImage.
ArrayList commonNodes = new ArrayList(commonSources.size());
it = oldRendering.iterator();
while(it.hasNext()) {
RenderedOp node = (RenderedOp)it.next();
PlanarImage source = (PlanarImage)node.getSourceImage(0);
if(commonSources.contains(source)) {
commonNodes.add(node);
}
}
// Create a new CollectionImage.
updatedCollection =
new AddConstToCollectionOpImage(newSource, newHints,
constants);
// Remove from the new CollectionImage all nodes that
// are common with the old CollectionImage.
ArrayList newNodes = new ArrayList(oldRendering.size() -
commonSources.size());
it = updatedCollection.iterator();
while(it.hasNext()) {
RenderedOp node = (RenderedOp)it.next();
PlanarImage source = (PlanarImage)node.getSourceImage(0);
if(commonSources.contains(source)) {
it.remove();
}
}
// Add all the common nodes to the new CollectionImage.
it = commonNodes.iterator();
while(it.hasNext()) {
updatedCollection.add(it.next());
}
}
}
return updatedCollection;