Meant to attach my original pseudo-code, mostly for a laugh at my expense.

    if (root.indexOf(newModel) < 0) {
        if (originalModel != null) {
            int originalIdx = root.indexOf(originalModel);
            if (originalIdx >= 0) {
                Object thanksJava = (newModel != null) ? root.set(originalIdx, 
newModel) : root.remove(originalIdx);
            }
        } else if (newModel != null) {
            stack.push(newModel);
        }
    }

Then I decided to write it so I could actually understand it if I ever saw it 
again.

    // New model already on stack; no refresh needed.
    if (root.indexOf(newModel) >= 0) {
        return;
    }

    // Original model was null; just push new model on stack 
    // (nothing to replace) if new model not null.
    if ((originalModel == null) && (newModel != null)) {
        stack.push(newModel);
        return;
    }

    // Can't find original model on stack? Something may be wrong. 
    // TODO devMode exception.
    int originalIdx = root.indexOf(originalModel);
    if (originalIdx < 0) {
        return;
    }

    // Replace if new model not null, otherwise remove original
    // model--null models not put on stack.
    if (newModel != null) {
        root.set(originalIdx, newModel);
    } else {
        root.remove(orginalIdx);
    }

Then I realized I might have a future as a botanist or something, because at 
this point in my day I can't tell if either is correct :/

Dave

--- On Fri, 7/18/08, Dave Newton <[EMAIL PROTECTED]> wrote:
> --- On Thu, 7/17/08, Ted Husted <[EMAIL PROTECTED]>
> wrote:
> > As mentioned, to refresh the model, we remove the
> existing
> > model and push the latest version. For a
> "refresh" operation,
> > we might expect the new instance to replace the old
> instance 
> > in the same stack position.
> > 
> > In RefreshModelBeforeResult, we already have a
> reference to
> > the old model ("Item"). Could we just
> replace one object
> > with another?
> > 
> >             for (Object item : root) {
> >                 if (item == newModel) {
> >                     needsRefresh = false;
> >                 }
> > +             else {
> > +               item = newModel
> > +             }
> 
> Would that replace every non-newModel item? Maybe something
> closer to this, using your code as a start, then ruining it
> with returns (it's late, I'm groggy :)
> 
>     boolean replaced = false;
>     for (Object item : root) {
>         if (item == newModel) {
>             return;
>         } else if (item == originalModel) {
>             if (newModel != null) {
>                 item = newModel;
>             } else {
>                 root.remove(item);
>             }
>             return;
>         }
>     }
> 
>     if (newModel != null) {
>         stack.push(newModel);
>     }
> 
> The other issue I mentioned is that if newModel is null the
> current code doesn't push it--there's always a
> chance of the stack *depth* being modified, even if the
> stack index of the model isn't. This seems unavoidable
> and may not be an important issue.
> 
> Hmm, if for some reason there were two instances of the
> model (maybe even original *or* new models?) on the stack
> there could be some confusion.
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to