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/.
18 package cz.xelfi.quoridor.statistics;
20 import cz.xelfi.quoridor.webidor.Game;
21 import cz.xelfi.quoridor.webidor.GameId;
22 import cz.xelfi.quoridor.webidor.GameStatus;
23 import cz.xelfi.quoridor.webidor.User;
24 import cz.xelfi.quoridor.Move;
25 import java.util.HashMap;
27 import java.util.List;
28 import java.util.ArrayList;
29 import javax.xml.bind.annotation.XmlAttribute;
35 public class OpeningTreeNode {
39 List<GameId> finishedGames;
40 Map<Move, OpeningTreeNode> children;
42 public OpeningTreeNode(){
45 public OpeningTreeNode(String hashCode){
46 this.hashCode = hashCode;
47 gameIds = new ArrayList<GameId>();
48 finishedGames = new ArrayList<GameId>();
49 children = new HashMap<Move,OpeningTreeNode>();
52 public OpeningTreeNode addGame(Game game){
53 gameIds.add(game.getId());
57 public OpeningTreeNode addFinishedGame(Game game){
58 finishedGames.add(game.getId());
62 public OpeningTreeNode addGameId(GameId gameId){
67 public OpeningTreeNode addChild(Move move, OpeningTreeNode child){
68 children.put(move, child);
72 public OpeningNodeView getView(User user){
73 return getView(user.getId());
76 public OpeningNodeView getView(String userId){
77 OpeningNodeView view = new OpeningNodeView(hashCode);
78 for(Map.Entry<Move, OpeningTreeNode> e: children.entrySet()){
79 for(GameId gId: e.getValue().gameIds){
80 if(User.canSee(gId, userId)){
81 view.processGame(e.getKey(), e.getValue().hashCode, gId);
85 for(GameId gId: finishedGames){
86 if(User.canSee(gId, userId)){
87 view.addFinishedGame(gId);
93 public List<GameId> filterGames(String userId, GameStatus status){
94 List<GameId> result = new ArrayList<GameId>();
95 for(GameId gId: gameIds){
96 if(User.canSee(gId, userId))
97 if(gId.getStatus().equals(status))
103 public List<GameId> getGameIds(){
109 public String getHashCode(){
110 return this.hashCode;
115 public boolean equals(Object obj) {
119 if (getClass() != obj.getClass()) {
122 OpeningTreeNode other = (OpeningTreeNode)obj;
123 return hashCode.equals(other.hashCode);
127 public int hashCode() {
128 return hashCode.hashCode();