toString method

  1. @override
String toString()
override

Print contents of Deck. Note that for performance, cards are popped from the end of the list, which makes it the notional "top" of the deck. For testing and simulation purposes, deck contents are shown backwards: i.e., from the end of the list to the front.

Implementation

@override
String toString() {
  int l = _cards.length;
  int max = l;
  int tail = 0;

  if (l > 32) {
    max = 29;
    tail = l - 29;
  }
  StringBuffer sb = StringBuffer();
  sb.write("${master.name} [");
  for (int i = l - 1; i >= l - max; i -= 1) {
    sb.write(_cards[i].toString());
  }
  if (tail > 0) {
    sb.write("...+$tail");
  }
  sb.write("]");
  return sb.toString();
}