/**
 * Copyright (C) 2022 by Martin Robillard. See https://codesample.info/about.html
 */
package e2.chapter8;

/**
 * Sample observer of ObservableCardStack. Counts the number of
 * cards pushed on a stack.
 */
public class Counter implements CardStackObserver {
	private int aCount = 0;

	@Override
	public void pushed(Card pCard) {
		aCount++;
		System.out.println("PUSH Counter=" + aCount);
	}

	@Override
	public void popped(Card pCard) {
		aCount--;
		System.out.println("POP Counter=" + aCount);
		if (aCount == 0) {
			System.out.println("Last card popped!");
		}
	}

	@Override
	public void cleared() {
		aCount = 0;
		System.out.println("CLEAR Counter=" + aCount);
	}
}