Re: Safer version of IncrementalFaultList.DataRowListHelper

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Dec 22 2004 - 10:33:46 EST

  • Next message: Derek Rendall: "Re: Safer version of IncrementalFaultList.DataRowListHelper"

    Hi Derek,

    > Basically I can end up with full data row maps (not just idmaps)
    > in some of the entries in my version of the IncrementalFaultList.

    Is this because of some of your customizations? Could you explain?

    Anyway, the code looks ok. Please submit it in a patch format via JIRA, so
    that we don't forget. I'll review and commit it after the holidays. If you
    can come up with some junit tests for this addition, please post them too.

    Thanks

    Andrus

    > Hi
    >
    > I have some code that needs a safer version of the methods in this
    > class. Basically I can end up with full data row maps (not just idmaps)
    > in some of the entries in my version of the IncrementalFaultList. This
    > causes some havoc when it comes time to replace the items in the list on
    > the second time through - as the expanded map is a superset of the idmap
    > (thus fails the equality test, even though the id key values are the
    > same). I have made some changes to fix up things for my case (i.e. made
    > the handling a bit more generic), but was wondering whether it
    > could/should be included in the main code base? I would rather not have
    > to maintain this if I can avoid it (and I cant alter this class for a
    > subclass of IncrementalFaultList because it has package visibility). Any
    > comments are welcomed.
    >
    > Here is the original Data Row List Helper class:
    >
    > class DataObjectListHelper extends IncrementalListHelper {
    > boolean incorrectObjectType(Object object) {
    > if (!(object instanceof DataObject)) {
    >
    > return true;
    > }
    >
    > DataObject dataObj = (DataObject) object;
    > if (dataObj.getDataContext() != dataContext) {
    > return true;
    > }
    >
    > if (!dataObj
    > .getObjectId()
    > .getObjClass()
    > .getName()
    > .equals(rootEntity.getClassName())) {
    > return true;
    > }
    >
    > return false;
    > }
    >
    > boolean objectsAreEqual(Object object, Object objectInTheList) {
    >
    > if (objectInTheList instanceof DataObject) {
    > // due to object uniquing this should be sufficient
    > return object == objectInTheList;
    > }
    > else {
    > return ((DataObject)
    > object).getObjectId().getIdSnapshot().equals(objectInTheList);
    > }
    > }
    >
    > boolean replacesObject(Object object, Object objectInTheList) {
    > if (objectInTheList instanceof DataObject) {
    > return false;
    > }
    >
    > DataObject dataObject = (DataObject) object;
    > return
    > dataObject.getObjectId().getIdSnapshot().equals(objectInTheList);
    > }
    > }
    >
    >
    >
    > and here is my version:
    >
    >
    > class DataObjectListHelper extends IncrementalListHelper {
    > boolean incorrectObjectType(Object object) {
    > if (!(object instanceof DataObject)) {
    >
    > return true;
    > }
    >
    > DataObject dataObj = (DataObject) object;
    > if (dataObj.getDataContext() != dataContext) {
    > return true;
    > }
    >
    > if (!dataObj
    > .getObjectId()
    > .getObjClass()
    > .getName()
    > .equals(rootEntity.getClassName())) {
    > return true;
    > }
    >
    > return false;
    > }
    >
    > private boolean checkDataRowIsForObject(DataObject dataObject,
    > Object objectInTheList) {
    > Map idSnapshotMap =
    > dataObject.getObjectId().getIdSnapshot(); if
    > (objectInTheList instanceof DataRow) {
    > DataRow dr = (DataRow)objectInTheList;
    > if (dr.size() > idSnapshotMap.size()) {
    > // might be full data row rather than just id
    > Iterator i = idSnapshotMap.entrySet().iterator();
    > while (i.hasNext()) {
    > Entry e = (Entry) i.next();
    > Object key = e.getKey();
    > Object value = e.getValue();
    > if (value == null) {
    > if (!(dr.get(key) == null &&
    > dr.containsKey(key)))
    > return false;
    > }
    > else {
    > if (!value.equals(dr.get(key)))
    > return false;
    > }
    > }
    > return true;
    > }
    > return idSnapshotMap.equals(dr);
    > }
    > return idSnapshotMap.equals(objectInTheList);
    > }
    >
    > boolean objectsAreEqual(Object object, Object objectInTheList) {
    >
    > if (objectInTheList instanceof DataObject) {
    > // due to object uniquing this should be sufficient
    > return object == objectInTheList;
    > }
    > return checkDataRowIsForObject((DataObject) object,
    > objectInTheList);
    > }
    >
    > boolean replacesObject(Object object, Object objectInTheList) {
    > if (objectInTheList instanceof DataObject) {
    > return false;
    > }
    > return checkDataRowIsForObject((DataObject) object,
    > objectInTheList);
    > }
    > }
    >
    > Thanks
    >
    > Derek



    This archive was generated by hypermail 2.0.0 : Wed Dec 22 2004 - 10:33:48 EST