All pastes #912479 Raw Edit

Hand.java

public java v1 · immutable
·published 2008-02-21 12:20 UTC
rendered paste body
package oving5.card;import java.util.*;public class Hand implements Iterable<Card> {	private Card[] cards;		/*	 * Constructor	 * 	 * @param	cards	An instance (Card) representing a hand of cards.	 */	public Hand(Card[] cards) {		this.cards = cards.clone();	}		/*	 * @return	Length of the current hand	 */	public int getCardCount() {		return cards.length;	}		/*	 * @return	A specific card in the hand	 */	public Card getCard(int i) {		return (i >= 0 && i < getCardCount() ? cards[i] : null);	}		/*	 * Sorts the hand.	 */		public void sort() {		Arrays.sort(cards);	}		/*	 * @return	the highest card in the hand	 */	public Card getHighestCard() {		Card highest = this.cards[0];		CardComparator c = new CardComparator();				for (int i = 0; i < this.cards.length; i++) {						if (c.compare(cards[i], highest) > 0) {				highest = cards[i];			} 		}		return highest;	}		@Override	public Iterator<Card> iterator() {		List<Card> cardList = Arrays.asList(cards);		return cardList.iterator();	}		}