2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Martin Rexa
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
19 package cz.xelfi.quoridor.statistics;
21 import cz.xelfi.quoridor.webidor.Game;
22 import cz.xelfi.quoridor.webidor.GameId;
23 import cz.xelfi.quoridor.webidor.GameStatus;
24 import cz.xelfi.quoridor.webidor.User;
25 import cz.xelfi.quoridor.Move;
26 import java.util.HashMap;
28 import java.util.List;
29 import java.util.ArrayList;
30 import javax.xml.bind.annotation.XmlAttribute;
36 public class OpeningTreeNode {
40 List<GameId> finishedGames;
41 Map<Move, OpeningTreeNode> children;
43 public OpeningTreeNode(){
46 public OpeningTreeNode(String hashCode){
47 this.hashCode = hashCode;
48 gameIds = new ArrayList<GameId>();
49 finishedGames = new ArrayList<GameId>();
50 children = new HashMap<Move,OpeningTreeNode>();
53 public OpeningTreeNode addGame(Game game){
54 gameIds.add(game.getId());
58 public OpeningTreeNode addFinishedGame(Game game){
59 finishedGames.add(game.getId());
63 public OpeningTreeNode addGameId(GameId gameId){
68 public OpeningTreeNode addChild(Move move, OpeningTreeNode child){
69 children.put(move, child);
73 public OpeningNodeView getView(User user){
74 return getView(user.getId());
77 public OpeningNodeView getView(String userId){
78 OpeningNodeView view = new OpeningNodeView(hashCode);
79 for(Map.Entry<Move, OpeningTreeNode> e: children.entrySet()){
80 for(GameId gId: e.getValue().gameIds){
81 if(User.canSee(gId, userId)){
82 view.processGame(e.getKey(), e.getValue().hashCode, gId);
86 for(GameId gId: finishedGames){
87 if(User.canSee(gId, userId)){
88 view.addFinishedGame(gId);
94 public List<GameId> filterGames(String userId, GameStatus status){
95 List<GameId> result = new ArrayList<GameId>();
96 for(GameId gId: gameIds){
97 if(User.canSee(gId, userId))
98 if(gId.getStatus().equals(status))
104 public List<GameId> getGameIds(){
110 public String getHashCode(){
111 return this.hashCode;
116 public boolean equals(Object obj) {
120 if (getClass() != obj.getClass()) {
123 OpeningTreeNode other = (OpeningTreeNode)obj;
124 return hashCode.equals(other.hashCode);
128 public int hashCode() {
129 return hashCode.hashCode();