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

import java.util.function.Supplier;

/**
 * Demonstrates how to use the Supplier interface to obtain
 * card in the context of a card source that can supply an infinity
 * of card.
 * 
 * See Section 9.4
 */
public class InfiniteCardSource implements CardSource {
	
	/**
	 * Code that illustrates how to use this class
	 */
	@SuppressWarnings("unused")
	public static void main(String[] args) {
		InfiniteCardSource randomCards = new InfiniteCardSource(Card::random);
		InfiniteCardSource acesOfHeart = new InfiniteCardSource(() -> Card.get(Rank.ACE, Suit.HEARTS));
	}
	
	private final Supplier<Card> aCardSupplier;

	public InfiniteCardSource(Supplier<Card> pCardSupplier) {
		aCardSupplier = pCardSupplier;
	}

	@Override
	public Card draw() {
		return aCardSupplier.get();
	}

	@Override
	public boolean isEmpty() {
		return false;
	}
}