01 /*
02 Copyright (c) 2005 Garrett Smith
03 The MIT License
04 
05 Permission is hereby granted, free of charge, to any person obtaining a copy 
06 of this software and associated documentation files (the "Software"), to deal
07 in the Software without restriction, including without limitation the rights
08 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
09 copies of the Software, and to permit persons to whom the Software is 
10 furnished to do so, subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in all 
13 copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
21 THE SOFTWARE.
22 */
23 
24 // $Id: CardList.java.html,v 1.1 2005/06/14 06:50:55 gsmith Exp $
25 
26 package garrettsmith.playingcards;
27 
28 import java.util.*;
29 
30 /**
31  * Provides a List with some protection to ensure only {@link Card} objects are
32  * put into the list.
33  
34  @author Garrett Smith, gsmith at northwestern dot edu
35  @version Blackjack v1.0
36  @since Blackjack v1.0
37  */
38 public final class CardList extends ArrayList {
39 
40   /**
41    * Creates an empty card list with an initial capaciy of 10.
42    */
43   public CardList() {
44     super10 );
45   }
46   
47   /**
48    * Creates an empty card list with an initial capaciy of <code>capacity</code>.
49    */
50   public CardListfinal int capacity ) {
51     supercapacity );
52   }
53 
54   /**
55    * Creates a card list which contains the contents of <code>cards</code>.
56    */
57   public CardListCardList cards ) {
58     supercards );
59   }
60 
61   /**
62    * Adds a card to the list.
63    
64    @throws IllegalArgumentException if <code>o</code> isn't a {@link Card}.
65    */
66   public boolean addfinal Object o ) {
67     if instanceof Card ) ) {
68       throw new IllegalArgumentException"must be a card" );
69     }
70     return super.add);
71   }
72   
73   /**
74    * Returns a {@link Card} from the specified index.
75    */
76   public Card getCardfinal int index ) {
77     return (Cardsuper.getindex );
78   }
79 
80   /**
81    * Removes a {@link Card} at the specified index.
82    */
83   public Card removeCard(int i) {
84     return (Cardsuper.remove);
85   }
86 }