001    ///////////////////////////////////////////////////////////////////////////////
002    // Copyright (c) 2006, Frank S. Nestel, All Rights Reserved.
003    //
004    // This library is free software; you can redistribute it and/or
005    // modify it under the terms of the GNU Lesser General Public
006    // License as published by the Free Software Foundation; either
007    // version 2.1 of the License, or (at your option) any later version.
008    //
009    // This library is distributed in the hope that it will be useful,
010    // but WITHOUT ANY WARRANTY; without even the implied warranty of
011    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012    // GNU General Public License for more details.
013    //
014    // You should have received a copy of the GNU Lesser General Public
015    // License along with this program; if not, write to the Free Software
016    // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017    ///////////////////////////////////////////////////////////////////////////////
018    
019    package de.spieleck.app.turn.pairing;
020    
021    import java.util.LinkedHashSet;
022    import java.util.Collections;
023    import java.util.Iterator;
024    
025    import de.spieleck.app.turn.Game;
026    import de.spieleck.app.turn.Player;
027    import de.spieleck.app.turn.PlayerGameScore;
028    
029    /**
030     * Simple implementation of Game for return purposes.
031     *
032     * <p><a href="$URL: https://svn.sourceforge.net/svnroot/jtourney/src/de/spieleck/app/turn/pairing/GameImpl.java $">$URL: https://svn.sourceforge.net/svnroot/jtourney/src/de/spieleck/app/turn/pairing/GameImpl.java $</a></p>
033     *
034     * @author Frank S. Nestel
035     * @author $Author: nestefan $
036     * @version $Revision: 2 $ $Date: 2006-03-20 14:33:27 +0100 (Mo, 20 Mrz 2006) $ $Author: nestefan $
037     */
038    public class GameImpl
039        implements Game
040    {
041        private int id;
042    
043        private LinkedHashSet<Player> players;
044    
045        public GameImpl(int id)
046        {
047            this.id = id;
048            players = new LinkedHashSet<Player>();
049        }
050    
051        public GameImpl(int id, Player[] players, int firstPlayer, int count)
052        {
053            this(id);
054            for(int i = 0; i < count; i++)
055                add(players[firstPlayer+i]);
056        }
057    
058        public void add(Player p)
059        {
060            players.add(p);
061        }
062    
063        public boolean contains(Player p)
064        {
065            return players.contains(p);
066        }
067    
068        public int size()
069        {
070            return players.size();
071        }
072    
073        public int getId()
074        {
075            return id;
076        }
077    
078        public Iterator<Player> players()
079        {
080            return Collections.unmodifiableSet(players).iterator();
081        }
082    
083        public String toString()
084        {
085            return "Game"+getId()+":"+size();
086        }
087    
088    }