Hi,
I am newbie to Java who had been given this task of debugging a bug. I would really appreaicte if you can help me in this. I have to find out why exportAssets.length is zero in the final method call down below(last method). Since it had a value before the method was called. Can someone tell me y? I have also put in my comments to tell you the return values I am getting after each call.Thanks
public void updateExportAssets(String uoiId, String mediaTypeName, ExportAsset[] newExportAssets) {
ExportAssetDao dao = new ExportAssetDao();
ExportAsset[] oldExportAssets = dao.getSelectedExportAssets(uoiId, mediaTypeName);
Set oldSet = new HashSet();
oldSet.addAll(Arrays.asList(oldExportAssets));
Set newSet = new HashSet();
newSet.addAll(Arrays.asList(newExportAssets));
Collection addedItems = getChangedItems(oldSet, newSet);
log.error("addedItems:" + addedItems);
-- This returns addedItems:[]
Collection deletedItems = getChangedItems(newSet, oldSet);
log.error("deletedItems:" + deletedItems);
-- This returns deletedItems:[]
log.error("OLD EXPORT ASSETS LENGTH:" + oldExportAssets.length);
-- This returns OLD EXPORT ASSETS LENGTH:8
log.error("NEW EXPORT ASSETS LENGTH:" + newExportAssets.length);
-- This returns NEW EXPORT ASSETS LENGTH:8
dao.removeExportAssetLinks( (ExportAsset[]) deletedItems.toArray(new ExportAsset[deletedItems.size()]));
dao.addExportAssetLinks( (ExportAsset[]) addedItems.toArray(new ExportAsset[addedItems.size()]));
}
/**
* Returns a collection with all items in newCol not in oldCol.
*/
protected Collection getChangedItems(Collection oldCol, Collection newCol) {
Iterator it = newCol.iterator();
Object o = null;
Collection retval = new ArrayList();
while (it.hasNext()) {
o = it.next();
if (!oldCol.contains(o)) {
retval.add(o);
}
}
return retval;
}
}
public void removeExportAssetLinks(ExportAsset[] exportAssets) {
for (int i=0; i<exportAssets.length; i++)
-- HERE the exportAssets.length becomes 0 (ZERO) so the subsequent call below does not work
{
removeExportAssetLink(exportAssets);
}
}
I am newbie to Java who had been given this task of debugging a bug. I would really appreaicte if you can help me in this. I have to find out why exportAssets.length is zero in the final method call down below(last method). Since it had a value before the method was called. Can someone tell me y? I have also put in my comments to tell you the return values I am getting after each call.Thanks
public void updateExportAssets(String uoiId, String mediaTypeName, ExportAsset[] newExportAssets) {
ExportAssetDao dao = new ExportAssetDao();
ExportAsset[] oldExportAssets = dao.getSelectedExportAssets(uoiId, mediaTypeName);
Set oldSet = new HashSet();
oldSet.addAll(Arrays.asList(oldExportAssets));
Set newSet = new HashSet();
newSet.addAll(Arrays.asList(newExportAssets));
Collection addedItems = getChangedItems(oldSet, newSet);
log.error("addedItems:" + addedItems);
-- This returns addedItems:[]
Collection deletedItems = getChangedItems(newSet, oldSet);
log.error("deletedItems:" + deletedItems);
-- This returns deletedItems:[]
log.error("OLD EXPORT ASSETS LENGTH:" + oldExportAssets.length);
-- This returns OLD EXPORT ASSETS LENGTH:8
log.error("NEW EXPORT ASSETS LENGTH:" + newExportAssets.length);
-- This returns NEW EXPORT ASSETS LENGTH:8
dao.removeExportAssetLinks( (ExportAsset[]) deletedItems.toArray(new ExportAsset[deletedItems.size()]));
dao.addExportAssetLinks( (ExportAsset[]) addedItems.toArray(new ExportAsset[addedItems.size()]));
}
/**
* Returns a collection with all items in newCol not in oldCol.
*/
protected Collection getChangedItems(Collection oldCol, Collection newCol) {
Iterator it = newCol.iterator();
Object o = null;
Collection retval = new ArrayList();
while (it.hasNext()) {
o = it.next();
if (!oldCol.contains(o)) {
retval.add(o);
}
}
return retval;
}
}
public void removeExportAssetLinks(ExportAsset[] exportAssets) {
for (int i=0; i<exportAssets.length; i++)
-- HERE the exportAssets.length becomes 0 (ZERO) so the subsequent call below does not work
{
removeExportAssetLink(exportAssets);
}
}