Ejemplo n.º 1
0
  CardCollection addCards(
      CardCollection oldCards, Iterable<Card> cardsToAdd, TrackableProperty key) {
    if (cardsToAdd == null) {
      return oldCards;
    }

    TrackableCollection<CardView> views = get(key);
    if (oldCards == null) {
      oldCards = new CardCollection();
    }
    boolean needFlagAsChanged = false;
    for (Card c : cardsToAdd) {
      if (c != null && oldCards.add(c)) {
        if (views == null) {
          views = new TrackableCollection<CardView>();
          views.add(c.getView());
          set(key, views);
        } else if (views.add(c.getView())) {
          needFlagAsChanged = true;
        }
      }
    }
    if (needFlagAsChanged) {
      flagAsChanged(key);
    }
    return oldCards;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
 public static TrackableCollection<CardView> getCollection(Iterable<Card> cards) {
   if (cards == null) {
     return null;
   }
   TrackableCollection<CardView> collection = new TrackableCollection<CardView>();
   for (Card c : cards) {
     if (c.getCardForUi() == c) { // only add cards that match their card for UI
       collection.add(c.getView());
     }
   }
   return collection;
 }
Ejemplo n.º 4
0
  CardCollection addCard(CardCollection oldCards, Card cardToAdd, TrackableProperty key) {
    if (cardToAdd == null) {
      return oldCards;
    }

    if (oldCards == null) {
      oldCards = new CardCollection();
    }
    if (oldCards.add(cardToAdd)) {
      TrackableCollection<CardView> views = get(key);
      if (views == null) {
        views = new TrackableCollection<CardView>();
        views.add(cardToAdd.getView());
        ;
        set(key, views);
      } else if (views.add(cardToAdd.getView())) {
        flagAsChanged(key);
      }
    }
    return oldCards;
  }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
0
 public static CardView get(Card c) {
   return c == null ? null : c.getView();
 }