Esempio n. 1
0
  CardCollection removeCards(
      CardCollection oldCards, Iterable<Card> cardsToRemove, TrackableProperty key) {
    if (cardsToRemove == null || oldCards == null) {
      return oldCards;
    }

    TrackableCollection<CardView> views = get(key);
    boolean needFlagAsChanged = false;
    for (Card c : cardsToRemove) {
      if (oldCards.remove(c)) {
        if (views == null) {
          set(key, null);
        } else if (views.remove(c.getView())) {
          if (views.isEmpty()) {
            views = null;
            set(key, null); // avoid keeping around an empty collection
            needFlagAsChanged = false; // doesn't need to be flagged a second time
          } else {
            needFlagAsChanged = true;
          }
        }
        if (oldCards.isEmpty()) {
          oldCards = null; // avoid keeping around an empty collection
          break;
        }
      }
    }
    if (needFlagAsChanged) {
      flagAsChanged(key);
    }
    return oldCards;
  }
Esempio n. 2
0
  CardCollection removeCard(CardCollection oldCards, Card cardToRemove, TrackableProperty key) {
    if (cardToRemove == null || oldCards == null) {
      return oldCards;
    }

    if (oldCards.remove(cardToRemove)) {
      TrackableCollection<CardView> views = get(key);
      if (views == null) {
        set(key, null);
      } else if (views.remove(cardToRemove.getView())) {
        if (views.isEmpty()) {
          set(key, null); // avoid keeping around an empty collection
        } else {
          flagAsChanged(key);
        }
      }
      if (oldCards.isEmpty()) {
        oldCards = null; // avoid keeping around an empty collection
      }
    }
    return oldCards;
  }