/**
  * Removes a disposable object, which was previously added.
  *
  * @param disposable
  */
 @Override
 public void removeDisposable(Disposable disposable) {
   if (disposables != null) {
     disposables.remove(disposable);
     if (disposables.isEmpty()) {
       disposables = null;
     }
   }
 }
 /**
  * Adds a disposable object, which will be disposed when the specified view is disposed.
  *
  * @param disposable
  */
 @Override
 public void addDisposable(Disposable disposable) {
   if (disposables == null) {
     disposables = new LinkedList<Disposable>();
   }
   disposables.add(disposable);
 }
  /**
   * Gets rid of all the resources of the view. No other methods should be invoked on the view
   * afterwards.
   */
  @SuppressWarnings("unchecked")
  @Override
  public void dispose() {
    if (executor != null) {
      executor.shutdown();
      executor = null;
    }

    if (disposables != null) {
      for (Disposable d : (LinkedList<Disposable>) disposables.clone()) {
        d.dispose();
      }
      disposables = null;
    }

    removeAll();
  }