Пример #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;
  }
Пример #2
0
 void setPlayerMayLook(Player p, boolean mayLook, boolean temp) {
   TrackableProperty prop =
       temp ? TrackableProperty.PlayerMayLookTemp : TrackableProperty.PlayerMayLook;
   TrackableCollection<PlayerView> col = get(prop);
   if (mayLook) {
     if (col == null) {
       col = new TrackableCollection<PlayerView>(p.getView());
       set(prop, col);
     } else if (col.add(p.getView())) {
       flagAsChanged(prop);
     }
   } else if (col != null) {
     if (col.remove(p.getView())) {
       if (col.isEmpty()) {
         set(prop, null);
       } else {
         flagAsChanged(prop);
       }
     }
   }
 }
Пример #3
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;
  }