title: Android SortedList remove method is skipping items
body: <p>Im having troubles with Android SortedList in RecyclerView, mainly with the remove method:<br>
          public void replaceAll(List userFertList, List defaultFertList){
          restartIndexes(userFertList, defaultFertList);
          mComparator.swapLists(Utils.fertiliserListToNameList(userFertList));</p>
  
  <pre><code>    List&lt;Fertiliser&gt; combinedList = Utils.combineFertLists(userFertList, defaultFertList);
  
      mSortedList.beginBatchedUpdates();
      for (int i = mSortedList.size() -1; i &gt; -1 ; i--) {
          final Fertiliser fertiliser = mSortedList.get(i);
          if(!combinedList.contains(fertiliser)){
              if(!mSortedList.remove(fertiliser)){
                  throw new RuntimeException();
              };
          }
      }
  
      mSortedList.addAll(combinedList);
      mSortedList.endBatchedUpdates();
  }
  </code></pre>
  
  <p>The above code is executed when filtering the list. All of the objects that are not present in the new list are removed. However the call to remove objects sometimes fail. I know the object is present, because it's taken from the SortedList itself.</p>
  
  <p>My research hinted me there's something wrong with my Comparator compare method:</p>
  
  <pre><code>        @Override
      public int compare(Fertiliser fertiliser, Fertiliser t1) {
          if(fertiliser == t1){
              return 0;
          }
  
          if(mUserFertNames.contains(fertiliser.getName()) != mUserFertNames.contains(t1.getName())){
              return mUserFertNames.contains(fertiliser.getName()) ? -1 : 1;
          } else {
              return fertiliser.getName().compareToIgnoreCase(t1.getName());
          }
      }
  </code></pre>
  
  <p>Im sorting by two criteria (one that checks if the object is present in a list and by name). </p>
  
  <p>So my thinking is, because SortedList uses the Comparator to locate the element, my Comparator gives false results, and the list cannot find the item:
  The called method from the SortedList:</p>
  
  <pre><code>    private int findIndexOf(T item, T[] mData, int left, int right, int reason) {
      while (left &lt; right) {
          final int middle = (left + right) / 2;
          T myItem = mData[middle];
          final int cmp = mCallback.compare(myItem, item);
          if (cmp &lt; 0) {
              left = middle + 1;
          } else if (cmp == 0) {
              if (mCallback.areItemsTheSame(myItem, item)) {
                  return middle;
              } else {
                  int exact = linearEqualitySearch(item, middle, left, right);
                  if (reason == INSERTION) {
                      return exact == INVALID_POSITION ? middle : exact;
                  } else {
                      return exact;
                  }
              }
          } else {
              right = middle;
          }
      }
      return reason == INSERTION ? left : INVALID_POSITION;
  }
  </code></pre>
  
  <p>However i coudn't find a solution. Can you help me?</p>
  
  <p>P.S. When i examined the error, both objects were not in the list (so they were compared by names only).</p>