001    /*
002     * Created on 27.03.2005 Filename: CardHolder.java
003     */
004    package jagafa.object;
005    
006    import jagafa.naming.ESwissColorNames;
007    import jagafa.naming.ESwissValueNames;
008    
009    import java.util.Iterator;
010    import java.util.LinkedList;
011    import java.util.List;
012    
013    /**
014     * Object to store a list of Card Objects
015     * Attention: Does not implement java.util.List
016     */
017    public class CardList{
018        private List<Card> cards_;
019    
020        /**
021         * Constructor: Init the list
022         */
023        public CardList() {
024            this.cards_ = new LinkedList<Card>();
025        }
026    
027        /**
028         * Add a card to the CardList
029         * @param c The card to add
030         */
031        public void add(Card c) {
032            this.cards_.add(c);
033        }
034    
035        /**
036         * Remove a card from the CardList
037         * @param c The card to remove
038         */
039        public void remove(Card c) {
040            this.cards_.remove(c);
041        }
042    
043        /**
044         * Remove a card from the CardList
045         * @param i The cards position
046         */
047        public void remove(int i) {
048            this.cards_.remove(i);
049        }
050    
051        /**
052         * Get a card out of the CardList at a position specified
053         * @return The card at the ith position in the CardList
054         * @param i The position
055         */
056        public Card get(int i) {
057            if (i >= this.size() || i <0) {
058                return null;
059            }
060            return this.cards_.get(i);
061    
062        }
063    
064        /**
065         * Converts the CardList to a java.util.iterator object
066         * @return An iterator of Card objects 
067         */
068        public Iterator<Card> iterator() {
069            return this.cards_.iterator();
070        }
071    
072        /**
073         * Get the number of cards in the CardList
074         * @return The number of Cards in the CardList
075         */
076        public int size() {
077            return this.cards_.size();
078        }
079    
080        /**
081         * Checks wether the CardList is empty or not
082         * @return True, if there are no Cards in the CardList
083         */
084        public boolean isEmpty() {
085            return this.cards_.isEmpty();
086        }
087    
088        /**
089         * Checks wether the CardList contains the Card given
090         * @return True, if the list contains the Card given
091         * @param c The card
092         */
093        public boolean contains(Card c) {
094            Iterator<Card> cardIter = this.iterator();
095            while (cardIter.hasNext()) {
096                Card next = cardIter.next();
097                if (next.equals(c)) {
098                    return true;
099                }
100            }
101            return false;
102    
103        }
104    
105        /**
106         * Clear the CardList
107         */
108        public void clear() {
109            this.cards_.clear();
110        }
111    
112        /**
113         * Convert the CardList to a java.util.list object
114         * @return A List (java.util.List) of the Cards in CardList
115         */
116        public List<Card> list() {
117            return this.cards_;
118        }
119    
120        /**
121         * Adds all Card from the CardList given to the CardList
122         * @param list The CardList to add
123         */
124        public void addAll(CardList list) {
125            this.cards_.addAll(list.list());
126        }
127        
128        public String toString() {
129            Iterator<Card> listIter = this.iterator();
130            String result = "";
131            while (listIter.hasNext()) {
132                Card c = listIter.next();
133                result += ESwissColorNames.getName(c.getColor()) + " " + ESwissValueNames.getName(c.getValue()) + "\n";
134    
135            }
136    
137            return result;
138    
139        }
140    
141            /**
142             * Dummy method: Used in GoneCardHeap only
143             */
144            public CardList getGoneOfColor(int i) {
145            
146                    return null;
147            }
148            
149            
150    }