com.blackledge.david.game.solitaire
Class CardStack

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector
              extended by com.blackledge.david.game.solitaire.CardStack
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, List, RandomAccess
Direct Known Subclasses:
DeckStack, FreeCellGoalStack, FreeCellPlayStack, FreeCellSingleStack, SolitaireGoalStack, SolitairePlayStack

public class CardStack
extends Vector

A collection of Card objects

Version:
$Revision: 1.1 $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
CardStack()
           
CardStack(Collection list)
           
 
Method Summary
 boolean add(Object o)
          calls super.add(Object) if the object is a card, calls super.Vector.addAll(Collection) if the object is a CardStack.
 Card bottomCard()
           
 boolean canPickUp(int i)
          Determine if we are allowed to call pickUp(int) without getting a null back.
 boolean canStack(Card card)
          Override for stacks with rules.
 boolean canStack(CardStack stack)
           
 CardStack getReverse()
          Get a new CardStack instance that contains the same cards as this stack, but in reverse order.
 CardStack pickUp(int i)
          Grab part of the stack off of the current instance, removing them from this instance.
 Card topCard()
           
 
Methods inherited from class java.util.Vector
add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

CardStack

public CardStack()

CardStack

public CardStack(Collection list)
Method Detail

add

public boolean add(Object o)
calls super.add(Object) if the object is a card, calls super.Vector.addAll(Collection) if the object is a CardStack.

Specified by:
add in interface Collection
Specified by:
add in interface List
Overrides:
add in class Vector
Returns:
whatever te super implementation returns.
Throws:
IllegalArgumentException - if the object is not one of the above types.

canStack

public boolean canStack(Card card)
Override for stacks with rules.

Parameters:
card - the card that wants to be stacked on top of this instance.
Returns:
true if not overridden.

canStack

public boolean canStack(CardStack stack)
Parameters:
stack - the stack that wants to be stacked on top of this instance.
Returns:
canStack(Card) for the stack argument's bottomCard

canPickUp

public boolean canPickUp(int i)
Determine if we are allowed to call pickUp(int) without getting a null back.

Returns:
true always

pickUp

public CardStack pickUp(int i)
Grab part of the stack off of the current instance, removing them from this instance.

Parameters:
i - how deep to reach when picking up from this instance. 0 == top card
Returns:
Stack of face-up cards from 0-i, or null if can't pick up or no cards.

bottomCard

public Card bottomCard()
Returns:
the card on the bottom of the stack. - don't call on an empty stack.

topCard

public Card topCard()
Returns:
the card on the top of the stack. - don't call on an empty stack.

getReverse

public CardStack getReverse()
Get a new CardStack instance that contains the same cards as this stack, but in reverse order.

Returns:
a new CardStack instance the same size as this one.