private void internalAddOrReplace(MediaModel old, MediaModel media) {
    // If the media is resizable, at this point consider it to be zero length.
    // Just before we send the slideshow, we take the remaining space in the
    // slideshow and equally allocate it to all the resizeable media items and resize them.
    int addSize = media.getMediaResizable() ? 0 : media.getMediaSize();
    int removeSize;
    if (old == null) {
      if (null != mParent) {
        mParent.checkMessageSize(addSize);
      }
      mMedia.add(media);
      increaseSlideSize(addSize);
      increaseMessageSize(addSize);
    } else {
      removeSize = old.getMediaResizable() ? 0 : old.getMediaSize();
      if (addSize > removeSize) {
        if (null != mParent) {
          mParent.checkMessageSize(addSize - removeSize);
        }
        increaseSlideSize(addSize - removeSize);
        increaseMessageSize(addSize - removeSize);
      } else {
        decreaseSlideSize(removeSize - addSize);
        decreaseMessageSize(removeSize - addSize);
      }
      mMedia.set(mMedia.indexOf(old), media);
      old.unregisterAllModelChangedObservers();
    }

    for (IModelChangedObserver observer : mModelChangedObservers) {
      media.registerModelChangedObserver(observer);
    }
  }
  public SlideModel set(int location, SlideModel object) {
    SlideModel slide = mSlides.get(location);
    if (null != object) {
      int removeSize = 0;
      int addSize = object.getSlideSize();
      if (null != slide) {
        removeSize = slide.getSlideSize();
      }
      if (addSize > removeSize) {
        checkMessageSize(addSize - removeSize);
        increaseMessageSize(addSize - removeSize);
      } else {
        decreaseMessageSize(removeSize - addSize);
      }
    }

    slide = mSlides.set(location, object);
    if (slide != null) {
      slide.unregisterAllModelChangedObservers();
    }

    if (object != null) {
      object.registerModelChangedObserver(this);
      for (IModelChangedObserver observer : mModelChangedObservers) {
        object.registerModelChangedObserver(observer);
      }
    }

    notifyModelChanged(true);
    return slide;
  }
  public void add(int location, SlideModel object) {
    if (object != null) {
      int increaseSize = object.getSlideSize();
      checkMessageSize(increaseSize);

      mSlides.add(location, object);
      increaseMessageSize(increaseSize);
      object.registerModelChangedObserver(this);
      for (IModelChangedObserver observer : mModelChangedObservers) {
        object.registerModelChangedObserver(observer);
      }
      notifyModelChanged(true);
    }
  }
  //
  // Implement List<E> interface.
  //
  public boolean add(SlideModel object) {
    int increaseSize = object.getSlideSize();
    checkMessageSize(increaseSize);

    if ((object != null) && mSlides.add(object)) {
      increaseMessageSize(increaseSize);
      object.registerModelChangedObserver(this);
      for (IModelChangedObserver observer : mModelChangedObservers) {
        object.registerModelChangedObserver(observer);
      }
      notifyModelChanged(true);
      return true;
    }
    return false;
  }