code: static boolean safeRemove(Collection<?> collection, @Nullable Object object) {
      checkNotNull(collection);
      try {
        return collection.remove(object);
      } catch (ClassCastException | NullPointerException e) {
        return false;
      }
    }
docs: Delegates to {@link Collection#remove}. Returns {@code false} if the {@code remove} method
  throws a {@code ClassCastException} or {@code NullPointerException}.